cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [4/5] cassandra git commit: Avoid invalidating disk boundaries unnecessarily
Date Tue, 26 Dec 2017 12:53:12 GMT
Avoid invalidating disk boundaries unnecessarily

Patch by Paulo Motta; Reviewed by Marcus Eriksson for CASSANDRA-14083


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

Branch: refs/heads/cassandra-3.11
Commit: 9337ca316a24a2a08f3c19cec2170ca1db80976b
Parents: e208a6a
Author: Paulo Motta <pauloricardomg@gmail.com>
Authored: Fri Dec 1 03:37:47 2017 +1100
Committer: Paulo Motta <paulo@apache.org>
Committed: Tue Dec 26 23:19:11 2017 +1100

----------------------------------------------------------------------
 CHANGES.txt                                              |  1 +
 .../org/apache/cassandra/db/DiskBoundaryManager.java     |  2 ++
 src/java/org/apache/cassandra/db/Keyspace.java           | 10 ++++++++--
 .../org/apache/cassandra/db/DiskBoundaryManagerTest.java | 11 +++++++----
 4 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/9337ca31/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8a6b61a..7ac528c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.11.2
+ * Avoid invalidating disk boundaries unnecessarily (CASSANDRA-14083)
  * Avoid exposing compaction strategy index externally (CASSANDRA-14082)
  * Prevent continuous schema exchange between 3.0 and 3.11 nodes (CASSANDRA-14109)
  * Fix imbalanced disks when replacing node with same address with JBOD (CASSANDRA-14084)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9337ca31/src/java/org/apache/cassandra/db/DiskBoundaryManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/DiskBoundaryManager.java b/src/java/org/apache/cassandra/db/DiskBoundaryManager.java
index ad6a67e..03cbf7b 100644
--- a/src/java/org/apache/cassandra/db/DiskBoundaryManager.java
+++ b/src/java/org/apache/cassandra/db/DiskBoundaryManager.java
@@ -31,6 +31,7 @@ import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Splitter;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.TokenMetadata;
+import org.apache.cassandra.service.PendingRangeCalculatorService;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 
@@ -78,6 +79,7 @@ public class DiskBoundaryManager
             if (StorageService.instance.isBootstrapMode()
                 && !StorageService.isReplacingSameAddress()) // When replacing same
address, the node marks itself as UN locally
             {
+                PendingRangeCalculatorService.instance.blockUntilFinished();
                 localRanges = tmd.getPendingRanges(cfs.keyspace.getName(), FBUtilities.getBroadcastAddress());
             }
             else

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9337ca31/src/java/org/apache/cassandra/db/Keyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Keyspace.java b/src/java/org/apache/cassandra/db/Keyspace.java
index 01fd451..5e39823 100644
--- a/src/java/org/apache/cassandra/db/Keyspace.java
+++ b/src/java/org/apache/cassandra/db/Keyspace.java
@@ -46,6 +46,7 @@ import org.apache.cassandra.io.sstable.format.SSTableReader;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.metrics.KeyspaceMetrics;
 import org.apache.cassandra.schema.KeyspaceMetadata;
+import org.apache.cassandra.schema.ReplicationParams;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.tracing.Tracing;
 import org.apache.cassandra.utils.*;
@@ -82,6 +83,7 @@ public class Keyspace
     private final ConcurrentMap<UUID, ColumnFamilyStore> columnFamilyStores = new ConcurrentHashMap<>();
     private volatile AbstractReplicationStrategy replicationStrategy;
     public final ViewManager viewManager;
+    private volatile ReplicationParams replicationParams;
 
     public static final Function<String,Keyspace> keyspaceTransformer = new Function<String,
Keyspace>()
     {
@@ -344,8 +346,12 @@ public class Keyspace
                                                                                     StorageService.instance.getTokenMetadata(),
                                                                                     DatabaseDescriptor.getEndpointSnitch(),
                                                                                     ksm.params.replication.options);
-        logger.debug("New replication strategy instance - invalidating disk boundary cache");
-        columnFamilyStores.values().forEach(ColumnFamilyStore::invalidateDiskBoundaries);
+        if (!ksm.params.replication.equals(replicationParams))
+        {
+            logger.debug("New replication settings for keyspace {} - invalidating disk boundary
caches", ksm.name);
+            columnFamilyStores.values().forEach(ColumnFamilyStore::invalidateDiskBoundaries);
+        }
+        replicationParams = ksm.params.replication;
     }
 
     // best invoked on the compaction mananger.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/9337ca31/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java b/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java
index de79959..5231e17 100644
--- a/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java
+++ b/test/unit/org/apache/cassandra/db/DiskBoundaryManagerTest.java
@@ -35,6 +35,8 @@ import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -51,11 +53,11 @@ public class DiskBoundaryManagerTest extends CQLTester
         TokenMetadata metadata = StorageService.instance.getTokenMetadata();
         metadata.updateNormalTokens(BootStrapper.getRandomTokens(metadata, 10), FBUtilities.getBroadcastAddress());
         createTable("create table %s (id int primary key, x text)");
-        dbm = getCurrentColumnFamilyStore().diskBoundaryManager;
         dirs = new Directories(getCurrentColumnFamilyStore().metadata, Lists.newArrayList(new
Directories.DataDirectory(new File("/tmp/1")),
                                                                                         
 new Directories.DataDirectory(new File("/tmp/2")),
                                                                                         
 new Directories.DataDirectory(new File("/tmp/3"))));
         mock = new MockCFS(getCurrentColumnFamilyStore(), dirs);
+        dbm = mock.diskBoundaryManager;
     }
 
     @Test
@@ -92,13 +94,14 @@ public class DiskBoundaryManagerTest extends CQLTester
     @Test
     public void alterKeyspaceTest() throws Throwable
     {
+        //do not use mock to since it will not be invalidated after alter keyspace
+        DiskBoundaryManager dbm = getCurrentColumnFamilyStore().diskBoundaryManager;
         DiskBoundaries dbv1 = dbm.getDiskBoundaries(mock);
         execute("alter keyspace "+keyspace()+" with replication = { 'class' : 'SimpleStrategy',
'replication_factor' : 3 }");
         DiskBoundaries dbv2 = dbm.getDiskBoundaries(mock);
-        // == on purpose - we just want to make sure that there is a new instance cached
-        assertFalse(dbv1 == dbv2);
+        assertNotSame(dbv1, dbv2);
         DiskBoundaries dbv3 = dbm.getDiskBoundaries(mock);
-        assertTrue(dbv2 == dbv3);
+        assertSame(dbv2, dbv3);
 
     }
 


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


Mime
View raw message