You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by mc...@apache.org on 2020/06/29 16:26:10 UTC

[cassandra] branch trunk updated: Fix upgrade failures when using the EC2Snitch in legacy mode

This is an automated email from the ASF dual-hosted git repository.

mck pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 6fc8920  Fix upgrade failures when using the EC2Snitch in legacy mode
6fc8920 is described below

commit 6fc8920889e8537a1f56f45e6c966b3d18325fbb
Author: Alexander Dejanovski <al...@thelastpickle.com>
AuthorDate: Fri Jun 26 11:08:50 2020 +0200

    Fix upgrade failures when using the EC2Snitch in legacy mode
    
    Legacy naming conventions for AWS regions were allowing datacenter names such as us-west and us-west-2, which in the new standard mode become us-west-1 and us-west-2.
    As us-west-2 can match both the standard and legacy mode, checking the DC name cannot be reliably used to detect mixed modes being used as it would fail in case of an upgrade from pre-4.0 clusters in a region such as us-west-2.
    The rack check should be enough as rack names in the standard mode now includes the region name, which can be easily identified.
    
     patch by Alexander Dejanovski; reviewed by Mick Semb Wever, Joey Lynch for CASSANDRA-15878
---
 CHANGES.txt                                        |  1 +
 .../org/apache/cassandra/locator/Ec2Snitch.java    |  9 ++++---
 .../apache/cassandra/locator/EC2SnitchTest.java    | 29 +++++++++++++++++++++-
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 9feaa5e..0781ca2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0-alpha5
+ * Fix Ec2Snitch handling of legacy mode for dc names matching both formats, eg "us-west-2" (CASSANDRA-15878)
  * Add support for server side DESCRIBE statements (CASSANDRA-14825)
  * Fail startup if -Xmn is set when the G1 garbage collector is used (CASSANDRA-15839)
  * generateSplits method replaced the generateRandomTokens for ReplicationAwareTokenAllocator. (CASSANDRA-15877)
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index d0474e4..5e51408 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -178,10 +178,11 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
             // Further, we can't make any assumptions of what that suffix might be by looking at this node's
             // datacenterSuffix as conceivably their could be many different suffixes in play for a given region.
             //
-            // Thus, the best we can do is make sure the region name follows
-            // the basic region naming pattern: "us-east-1<custom-suffix>"
-            boolean dcUsesLegacyFormat = !dc.matches("[a-z]+-[a-z].+-[\\d].*");
-            if (dcUsesLegacyFormat != usingLegacyNaming)
+            // It is impossible to distinguish standard and legacy names for datacenters in some cases
+            // as the format didn't change for some regions (us-west-2 for example).
+            // We can still identify as legacy the dc names without a number as a suffix like us-east"
+            boolean dcUsesLegacyFormat = dc.matches("^[a-z]+-[a-z]+$");
+            if (dcUsesLegacyFormat && !usingLegacyNaming)
                 valid = false;
         }
 
diff --git a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
index 2646d1c..13d5149 100644
--- a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
+++ b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java
@@ -140,7 +140,7 @@ public class EC2SnitchTest
     {
         Set<String> datacenters = new HashSet<>();
         datacenters.add("us-east-1");
-        Assert.assertFalse(Ec2Snitch.validate(datacenters, Collections.emptySet(), true));
+        Assert.assertTrue(Ec2Snitch.validate(datacenters, Collections.emptySet(), true));
     }
 
     @Test
@@ -207,6 +207,33 @@ public class EC2SnitchTest
         Assert.assertTrue(Ec2Snitch.validate(datacenters, racks, false));
     }
 
+    /**
+     * Validate upgrades in legacy mode for regions that didn't change name between the standard and legacy modes.
+     */
+    @Test
+    public void validate_RequiresLegacy_DCValidStandardAndLegacy()
+    {
+        Set<String> datacenters = new HashSet<>();
+        datacenters.add("us-west-2");
+        Set<String> racks = new HashSet<>();
+        racks.add("2a");
+        racks.add("2b");
+        Assert.assertTrue(Ec2Snitch.validate(datacenters, racks, true));
+    }
+
+    /**
+     * Check that racks names are enough to detect a mismatch in naming conventions.
+     */
+    @Test
+    public void validate_RequiresLegacy_RackInvalidForLegacy()
+    {
+        Set<String> datacenters = new HashSet<>();
+        datacenters.add("us-west-2");
+        Set<String> racks = new HashSet<>();
+        racks.add("us-west-2a");
+        Assert.assertFalse(Ec2Snitch.validate(datacenters, racks, true));
+    }
+
     @AfterClass
     public static void tearDown()
     {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org