This is an automated email from the ASF dual-hosted git repository. samt pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 8d6d1774e4008263bb381ae9d6b14b8f10f12fca Author: Sam Tunnicliffe <s...@apache.org> AuthorDate: Tue Dec 5 12:54:05 2023 +0000 Avoid NPEs when initializing CFSs from local keyspaces before ClusterMetadata is available Patch by Sam Tunnicliffe; reviewed by Alex Petrov for CASSANDRA-19169 --- src/java/org/apache/cassandra/db/ColumnFamilyStore.java | 3 +-- .../cassandra/db/compaction/UnifiedCompactionStrategy.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 83957a6260..1dc2687c40 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -1495,9 +1495,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean, Memtable.Owner public VersionedLocalRanges localRangesWeighted() { - ClusterMetadata metadata = ClusterMetadata.current(); if (!SchemaConstants.isLocalSystemKeyspace(getKeyspaceName()) - && getPartitioner() == metadata.partitioner) + && getPartitioner() == ClusterMetadata.current().partitioner) { DiskBoundaryManager.VersionedRangesAtEndpoint versionedLocalRanges = DiskBoundaryManager.getVersionedLocalRanges(this); Set<Range<Token>> localRanges = versionedLocalRanges.rangesAtEndpoint.ranges(); diff --git a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java index 0cb1f46cc8..361f67d8cb 100644 --- a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java @@ -302,10 +302,15 @@ public class UnifiedCompactionStrategy extends AbstractCompactionStrategy synchronized (this) { // Recheck after entering critical section, another thread may have beaten us to it. - while (shardManager == null || shardManager.isOutOfDate(ClusterMetadata.current().epoch.getEpoch())) + while (shardManager == null || + // Short circuit for local keyspaces which may be initialised before ClusterMetadata + (cfs.localRangesWeighted().ringVersion != ColumnFamilyStore.RING_VERSION_IRRELEVANT + && shardManager.isOutOfDate(ClusterMetadata.current().epoch.getEpoch()))) + { shardManager = ShardManager.create(cfs); - // Note: this can just as well be done without the synchronization (races would be benign, just doing some - // redundant work). For the current usages of this blocking is fine and expected to perform no worse. + // Note: this can just as well be done without the synchronization (races would be benign, just doing some + // redundant work). For the current usages of this blocking is fine and expected to perform no worse. + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org