CASSANDRA-21156: Prevent cyclic static initialization during table count threshold conversion - #5156
Open
cheeeee wants to merge 1 commit into
Open
CASSANDRA-21156: Prevent cyclic static initialization during table count threshold conversion#5156cheeeee wants to merge 1 commit into
cheeeee wants to merge 1 commit into
Conversation
…version Configuring the legacy 'table_count_warn_threshold' parameter in cassandra.yaml triggered Converters.TABLE_COUNT_THRESHOLD_TO_GUARDRAIL during DatabaseDescriptor.loadConfig(). To calculate user-table thresholds, this converter invoked SchemaConstants.getLocalAndReplicatedSystemTableNames(), which accessed non-compile-time-constant fields (SystemKeyspace.TABLE_NAMES and AccordKeyspace.TABLE_NAMES). Under JLS §12.4.1, accessing these fields executed the static initializers (<clinit>) of SystemKeyspace and AccordKeyspace before DatabaseDescriptor completed booting, attempting to query uninitialized components (DatabaseDescriptor.getPartitioner() and DatabaseDescriptor.getAccord()) and throwing ExceptionInInitializerError / NullPointerException. Furthermore, premature initialization of AccordKeyspace froze TableMetadata Journal without its RouteJournalIndex (since isDaemonInitialized() was false), causing a fatal invariant failure in AccordJournal upon startup. This patch: 1. SchemaConstants: declares system table names as constant sets using compile-time inlined String constants (SystemKeyspace.BATCHES, AccordKeyspace.JOURNAL, etc.). Under JLS §12.4.1, compile-time string constants are inlined into bytecode and do not trigger <clinit> of storage classes during pre-boot YAML parsing. 2. SystemKeyspace, AccordKeyspace, TraceKeyspace, AuthKeyspace, and SystemDistributedKeyspace: delegate their TABLE_NAMES fields directly to SchemaConstants.*, preserving a single source of truth and 100% backward compatibility. 3. Converters: handles non-positive values cleanly (retaining -1 for disabled guardrails), and clamps legacy thresholds less than or equal to the system table count to 0 with an explicit warning logged via LazyLogger. 4. Testing: adds TableCountThresholdToGuardrailConverterTest running in a virgin, uninitialized JVM, and SystemTableNamesConsistencyTest verifying schema parity against class definitions. Fixes: CASSANDRA-21156
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status: changes requested — not ready to merge
The daemon-only guard disables the configured Accord journal index in tool initialization. The published consistency tests do not cover this lifecycle.
Verification correction
Earlier descriptions overstated correctness and/or test coverage. Those claims are withdrawn. AI-assisted source review has been performed; this is not maintainer approval. Previously mixed build artifacts are not accepted as verification evidence. Corrective changes and clean, targeted verification are in progress; the published head has not yet been replaced.
Published head under review:
3fb8629623e567ee4b2682a0eb241386e2177958.