You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ma...@apache.org on 2024/12/11 13:45:07 UTC
(cassandra) branch cassandra-5.0 updated: Add flag to avoid invalidating key cache on sstable deletions
This is an automated email from the ASF dual-hosted git repository.
marcuse pushed a commit to branch cassandra-5.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-5.0 by this push:
new f9ab5cf797 Add flag to avoid invalidating key cache on sstable deletions
f9ab5cf797 is described below
commit f9ab5cf797013211c51c4e7d2dbd401300eb44e6
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Fri Nov 8 13:39:51 2024 +0100
Add flag to avoid invalidating key cache on sstable deletions
Patch by marcuse; reviewed by Caleb Rackliffe for CASSANDRA-20068
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/config/Config.java | 1 +
.../org/apache/cassandra/config/DatabaseDescriptor.java | 10 ++++++++++
.../apache/cassandra/io/sstable/format/big/BigFormat.java | 15 +++++++++------
src/java/org/apache/cassandra/service/StorageService.java | 10 ++++++++++
.../org/apache/cassandra/service/StorageServiceMBean.java | 2 ++
.../cassandra/io/sstable/keycache/KeyCacheTest.java | 6 +++---
7 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 6fbc22f8fb..b038387817 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0.3
+ * Add flag to avoid invalidating key cache on sstable deletions (CASSANDRA-20068)
* Interpret inet, bigint, varint, and decimal as non-reversed types for query construction and post-filtering (CASSANDRA-20100)
* Fix delayed gossip shutdown messages clobbering startup states that leave restarted nodes appearing down (CASSANDRA-20033)
* Streamline the serialized format for index status gossip messages (CASSANDRA-20058)
diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java
index 103d8a7cf7..8f6283ac1d 100644
--- a/src/java/org/apache/cassandra/config/Config.java
+++ b/src/java/org/apache/cassandra/config/Config.java
@@ -455,6 +455,7 @@ public class Config
public volatile DataStorageSpec.IntMebibytesBound sstable_preemptive_open_interval = new DataStorageSpec.IntMebibytesBound("50MiB");
public volatile boolean key_cache_migrate_during_compaction = true;
+ public volatile boolean key_cache_invalidate_after_sstable_deletion = false;
public volatile int key_cache_keys_to_save = Integer.MAX_VALUE;
@Replaces(oldName = "key_cache_size_in_mb", converter = Converters.MEBIBYTES_DATA_STORAGE_LONG, deprecated = true)
public DataStorageSpec.LongMebibytesBound key_cache_size = null;
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index bf44b53e2b..8fe910aad7 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -3760,6 +3760,16 @@ public class DatabaseDescriptor
conf.key_cache_migrate_during_compaction = migrateCacheEntry;
}
+ public static boolean shouldInvalidateKeycacheOnSSTableDeletion()
+ {
+ return conf.key_cache_invalidate_after_sstable_deletion;
+ }
+
+ public static void setInvalidateKeycacheOnSSTableDeletion(boolean invalidateCacheEntry)
+ {
+ conf.key_cache_invalidate_after_sstable_deletion = invalidateCacheEntry;
+ }
+
/** This method can return negative number for disabled */
public static int getSSTablePreemptiveOpenIntervalInMiB()
{
diff --git a/src/java/org/apache/cassandra/io/sstable/format/big/BigFormat.java b/src/java/org/apache/cassandra/io/sstable/format/big/BigFormat.java
index 4abfc88b5a..d188638669 100644
--- a/src/java/org/apache/cassandra/io/sstable/format/big/BigFormat.java
+++ b/src/java/org/apache/cassandra/io/sstable/format/big/BigFormat.java
@@ -247,13 +247,16 @@ public class BigFormat extends AbstractSSTableFormat<BigTableReader, BigTableWri
{
try
{
- // remove key cache entries for the sstable being deleted
- Iterator<KeyCacheKey> it = CacheService.instance.keyCache.keyIterator();
- while (it.hasNext())
+ if (DatabaseDescriptor.shouldInvalidateKeycacheOnSSTableDeletion())
{
- KeyCacheKey key = it.next();
- if (key.desc.equals(desc))
- it.remove();
+ // remove key cache entries for the sstable being deleted
+ Iterator<KeyCacheKey> it = CacheService.instance.keyCache.keyIterator();
+ while (it.hasNext())
+ {
+ KeyCacheKey key = it.next();
+ if (key.desc.equals(desc))
+ it.remove();
+ }
}
delete(desc, Lists.newArrayList(Sets.intersection(allComponents(), desc.discoverComponents())));
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 7a86e89fd5..ec771ab9bf 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -6646,6 +6646,16 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
DatabaseDescriptor.setMigrateKeycacheOnCompaction(invalidateKeyCacheOnCompaction);
}
+ public boolean getInvalidateKeycacheOnSSTableDeletion()
+ {
+ return DatabaseDescriptor.shouldInvalidateKeycacheOnSSTableDeletion();
+ }
+
+ public void setInvalidateKeycacheOnSSTableDeletion(boolean invalidate)
+ {
+ DatabaseDescriptor.setInvalidateKeycacheOnSSTableDeletion(invalidate);
+ }
+
public int getTombstoneWarnThreshold()
{
return DatabaseDescriptor.getTombstoneWarnThreshold();
diff --git a/src/java/org/apache/cassandra/service/StorageServiceMBean.java b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
index 8152096831..bd0f80aba6 100644
--- a/src/java/org/apache/cassandra/service/StorageServiceMBean.java
+++ b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
@@ -833,6 +833,8 @@ public interface StorageServiceMBean extends NotificationEmitter
public boolean getMigrateKeycacheOnCompaction();
public void setMigrateKeycacheOnCompaction(boolean invalidateKeyCacheOnCompaction);
+ public boolean getInvalidateKeycacheOnSSTableDeletion();
+ public void setInvalidateKeycacheOnSSTableDeletion(boolean invalidate);
public int getConcurrentViewBuilders();
public void setConcurrentViewBuilders(int value);
diff --git a/test/unit/org/apache/cassandra/io/sstable/keycache/KeyCacheTest.java b/test/unit/org/apache/cassandra/io/sstable/keycache/KeyCacheTest.java
index 15c37ea60a..abe83b59d5 100644
--- a/test/unit/org/apache/cassandra/io/sstable/keycache/KeyCacheTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/keycache/KeyCacheTest.java
@@ -350,14 +350,14 @@ public class KeyCacheTest
LifecycleTransaction.waitForDeletions();
- // after releasing the reference this should drop to 2
- assertKeyCacheSize(2, KEYSPACE1, cf);
+ // after releasing the reference this should drop to 2, unless we don't invalidate keycache on sstable deletion
+ assertKeyCacheSize(DatabaseDescriptor.shouldInvalidateKeycacheOnSSTableDeletion() ? 2 : 4, KEYSPACE1, cf);
// re-read same keys to verify that key cache didn't grow further
Util.getAll(Util.cmd(cfs, "key1").build());
Util.getAll(Util.cmd(cfs, "key2").build());
- assertKeyCacheSize( 2, KEYSPACE1, cf);
+ assertKeyCacheSize( DatabaseDescriptor.shouldInvalidateKeycacheOnSSTableDeletion() ? 2 : 4, KEYSPACE1, cf);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org