You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by vi...@apache.org on 2012/03/12 19:50:01 UTC

git commit: EC2 snitch incorrectly reports regions patch by Vijay; reviewed by Brandon Williams for CASSANDRA-4026

Updated Branches:
  refs/heads/trunk f16becfc2 -> a7b9d09b0


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/a7b9d09b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a7b9d09b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a7b9d09b

Branch: refs/heads/trunk
Commit: a7b9d09b05f263f2e9629b4c5432d6044b1f15e2
Parents: f16becf
Author: Vijay Parthasarathy <vi...@gmail.com>
Authored: Mon Mar 12 11:49:00 2012 -0700
Committer: Vijay Parthasarathy <vi...@gmail.com>
Committed: Mon Mar 12 11:49:00 2012 -0700

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


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a7b9d09b/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 c597a74..2d7fbd0 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -50,10 +50,16 @@ 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/a7b9d09b/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 a72069a..103db51 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));
+    }
 }