Skip to content

CASSANDRA-21156: Prevent cyclic static initialization during table count threshold conversion - #5156

Open
cheeeee wants to merge 1 commit into
apache:trunkfrom
cheeeee:CASSANDRA-21156-trunk
Open

CASSANDRA-21156: Prevent cyclic static initialization during table count threshold conversion#5156
cheeeee wants to merge 1 commit into
apache:trunkfrom
cheeeee:CASSANDRA-21156-trunk

Conversation

@cheeeee

@cheeeee cheeeee commented Sep 11, 2026

Copy link
Copy Markdown

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.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant