From 5c830dc492bf2551cdcdaff949946e339e61a9f1 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Mon, 16 Dec 2024 11:26:19 +0100 Subject: [PATCH] CNDB-12128 Expose to CNDB some methods around ExpirationTask (#1465) Expose some methods needed for https://github.com/riptano/cndb/issues/12128 --- .../compaction/UnifiedCompactionStrategy.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java index 5669a4ce48dd..213916b99e9a 100644 --- a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java @@ -335,7 +335,7 @@ public synchronized Collection getNextBackgroundTasks(in return getNextBackgroundTasks(getNextCompactionAggregates(), gcBefore); } - /// Check for fully expired sstables and return a collection of expiration tasks if found. Called by CNDB directly. + /// Check for fully expired sstables and return a collection of expiration tasks if found. public Collection getExpirationTasks(int gcBefore) { long ts = System.currentTimeMillis(); @@ -344,19 +344,20 @@ public Collection getExpirationTasks(int gcBefore) return null; lastExpiredCheck = ts; - // Get all expired sstables, regardless of expiration status. - // This is simpler and faster than per-arena collection, and will find nothing in most calls. - var expired = CompactionController.getFullyExpiredSSTables(realm, - getSuitableSSTables(), - realm::getOverlappingLiveSSTables, - gcBefore, - controller.getIgnoreOverlapsInExpirationCheck()); + var expired = getFullyExpiredSSTables(gcBefore); if (expired.isEmpty()) return null; if (logger.isDebugEnabled()) logger.debug("Expiration check found {} fully expired SSTables", expired.size()); + return createExpirationTasks(expired); + } + + /// Create expiration tasks for the given set of expired sstables. + /// Used by CNDB + public List createExpirationTasks(Set expired) + { // if we found sstables to expire, split them to arenas to correctly isolate their repair status. var tasks = new ArrayList(); try @@ -377,6 +378,18 @@ public Collection getExpirationTasks(int gcBefore) } } + /// Get all expired sstables, regardless of expiration status. + /// This is simpler and faster than per-arena collection, and will find nothing in most calls. + /// Used by CNDB + public Set getFullyExpiredSSTables(int gcBefore) + { + return CompactionController.getFullyExpiredSSTables(realm, + getSuitableSSTables(), + realm::getOverlappingLiveSSTables, + gcBefore, + controller.getIgnoreOverlapsInExpirationCheck()); + } + /// Used by CNDB where compaction aggregates come from etcd rather than the strategy /// @return collection of `AbstractCompactionTask`, which could be either a `CompactionTask` or a `UnifiedCompactionTask` public synchronized Collection getNextBackgroundTasks(Collection aggregates, int gcBefore)