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

samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit fde56f2531e94143df1386ff33f1ba57b1523876
Author: Marcus Eriksson <[email protected]>
AuthorDate: Fri Mar 17 10:00:31 2023 +0100

    [CEP-21] Fix nodetool ring and effective ownership
    
    patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
    for CASSANDRA-18410
---
 .../apache/cassandra/service/StorageService.java   | 37 +++++++++++-----------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/src/java/org/apache/cassandra/service/StorageService.java 
b/src/java/org/apache/cassandra/service/StorageService.java
index 5f16329d66..88fa90019b 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -239,6 +239,7 @@ import static java.util.stream.Collectors.toSet;
 import static 
org.apache.cassandra.config.CassandraRelevantProperties.DRAIN_EXECUTOR_TIMEOUT_MS;
 import static org.apache.cassandra.index.SecondaryIndexManager.getIndexName;
 import static 
org.apache.cassandra.index.SecondaryIndexManager.isIndexColumnFamily;
+import static 
org.apache.cassandra.schema.SchemaConstants.isLocalSystemKeyspace;
 import static 
org.apache.cassandra.service.ActiveRepairService.ParentRepairStatus;
 import static 
org.apache.cassandra.service.ActiveRepairService.repairCommandExecutor;
 import static 
org.apache.cassandra.tcm.compatibility.TokenRingUtils.getAllRanges;
@@ -2479,7 +2480,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
 
     public int forceKeyspaceCleanup(int jobs, String keyspaceName, String... 
tableNames) throws IOException, ExecutionException, InterruptedException
     {
-        if (SchemaConstants.isLocalSystemKeyspace(keyspaceName))
+        if (isLocalSystemKeyspace(keyspaceName))
             throw new RuntimeException("Cleanup of the system keyspace is 
neither necessary nor wise");
 
         if 
(ClusterMetadata.current().directory.peerState(getBroadcastAddressAndPort()) != 
JOINED)
@@ -3004,7 +3005,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         long total = 0;
         for (Keyspace keyspace : Keyspace.all())
         {
-            if (SchemaConstants.isLocalSystemKeyspace(keyspace.getName()))
+            if (isLocalSystemKeyspace(keyspace.getName()))
                 continue;
 
             for (ColumnFamilyStore cfStore : keyspace.getColumnFamilyStores())
@@ -4122,6 +4123,9 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         AbstractReplicationStrategy strategy;
         if (keyspace != null)
         {
+            if (isLocalSystemKeyspace(keyspace))
+                throw new IllegalArgumentException("Ownership values for 
keyspaces with LocalStrategy are meaningless");
+
             KeyspaceMetadata keyspaceInstance = 
metadata.schema.getKeyspaces().getNullable(keyspace);
             if (keyspaceInstance == null)
                 throw new IllegalArgumentException("The keyspace " + keyspace 
+ ", does not exist");
@@ -4133,35 +4137,30 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         }
         else
         {
-            Keyspaces keyspaces = metadata.schema.getKeyspaces();
+            Set<String> userKeyspaces = metadata.schema.getKeyspaces()
+                                                       
.without(SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES)
+                                                       .names();
 
-            if (keyspaces.size() > 0)
+            if (userKeyspaces.size() > 0)
             {
-                AbstractReplicationStrategy rs = null;
-                for (KeyspaceMetadata ks : keyspaces)
+                keyspace = userKeyspaces.iterator().next();
+                AbstractReplicationStrategy replicationStrategy = 
Schema.instance.getKeyspaceInstance(keyspace).getReplicationStrategy();
+                for (String keyspaceName : userKeyspaces)
                 {
-                    if (ks.params.replication.isMeta())
-                        continue;
-
-                    if (rs == null)
-                    {
-                        rs = ks.replicationStrategy;
-                        continue;
-                    }
-
-                    if (!ks.replicationStrategy.hasSameSettings(rs))
+                    if 
(!Schema.instance.getKeyspaceInstance(keyspaceName).getReplicationStrategy().hasSameSettings(replicationStrategy))
                         throw new IllegalStateException("Non-system keyspaces 
don't have the same replication settings, effective ownership information is 
meaningless");
                 }
             }
-            else
+
+            if (keyspace == null)
             {
                 keyspace = "system_traces";
             }
 
-            KeyspaceMetadata keyspaceInstance = 
keyspaces.getNullable(keyspace);
+            Keyspace keyspaceInstance = 
Schema.instance.getKeyspaceInstance(keyspace);
             if (keyspaceInstance == null)
                 throw new IllegalStateException("The node does not have " + 
keyspace + " yet, probably still bootstrapping. Effective ownership information 
is meaningless.");
-            strategy = keyspaceInstance.replicationStrategy;
+            strategy = keyspaceInstance.getReplicationStrategy();
         }
 
         if (strategy instanceof MetaStrategy)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to