cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [11/14] git commit: EC2 snitch incorrectly reports regions patch by Vijay; reviewed by Brandon Williams for CASSANDRA-4026
Date Wed, 14 Mar 2012 04:25:55 GMT
EC2 snitch incorrectly reports regions
patch by Vijay; reviewed by Brandon Williams for CASSANDRA-4026


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/34060fc7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/34060fc7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/34060fc7

Branch: refs/heads/cassandra-1.1
Commit: 34060fc77a77846b60b146fc32af9dd58a21b545
Parents: d096471
Author: Vijay Parthasarathy <vijay2win@gmail.com>
Authored: Mon Mar 12 12:00:06 2012 -0700
Committer: Vijay Parthasarathy <vijay2win@gmail.com>
Committed: Mon Mar 12 12:00:06 2012 -0700

----------------------------------------------------------------------
 .../org/apache/cassandra/locator/Ec2Snitch.java    |    9 +++++++--
 .../apache/cassandra/locator/EC2SnitchTest.java    |   14 +++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/34060fc7/src/java/org/apache/cassandra/locator/Ec2Snitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index 3648143..139c305 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -51,10 +51,15 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
 
     public Ec2Snitch() throws IOException, ConfigurationException
     {
+        String az = awsApiCall(ZONE_NAME_QUERY_URL);
         // Split "us-east-1a" or "asia-1a" into "us-east"/"1a" and "asia"/"1a".
-        String[] splits = awsApiCall(ZONE_NAME_QUERY_URL).split("-");
+        String[] splits = az.split("-");
         ec2zone = splits[splits.length - 1];
-        ec2region = splits.length < 3 ? splits[0] : splits[0] + "-" + splits[1];
+
+        // hack for CASSANDRA-4026
+        ec2region = az.substring(0, az.length() - 1);
+        if (ec2region.endsWith("1"))
+            ec2region = az.substring(0, az.length() - 3);
         logger.info("EC2Snitch using region: " + ec2region + ", zone: " + ec2zone + ".");
     }
     

http://git-wip-us.apache.org/repos/asf/cassandra/blob/34060fc7/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
index fad5e9e..9df9543 100644
--- a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
+++ b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
@@ -36,6 +36,7 @@ import org.junit.Test;
 
 public class EC2SnitchTest
 {
+    private static String az;
 
     private class TestEC2Snitch extends Ec2Snitch
     {
@@ -47,13 +48,14 @@ public class EC2SnitchTest
         @Override
         String awsApiCall(String url) throws IOException, ConfigurationException
         {
-            return "us-east-1d";
+            return az;
         }
     }
 
     @Test
     public void testRac() throws IOException, ConfigurationException
     {
+        az = "us-east-1d";
         Ec2Snitch snitch = new TestEC2Snitch();
         InetAddress local = InetAddress.getByName("127.0.0.1");
         InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
@@ -69,4 +71,14 @@ public class EC2SnitchTest
         assertEquals("us-east", snitch.getDatacenter(local));
         assertEquals("1d", snitch.getRack(local));
     }
+    
+    @Test
+    public void testNewRegions() throws IOException, ConfigurationException
+    {
+        az = "us-east-2d";
+        Ec2Snitch snitch = new TestEC2Snitch();
+        InetAddress local = InetAddress.getByName("127.0.0.1");
+        assertEquals("us-east-2", snitch.getDatacenter(local));
+        assertEquals("2d", snitch.getRack(local));
+    }
 }


Mime
View raw message