CASSANDRA-21659: Make schema diffing independent of the number of tables in the cluster - #5121
CASSANDRA-21659: Make schema diffing independent of the number of tables in the cluster#5121pmcfadin wants to merge 1 commit into
Conversation
Keyspaces.diff and Tables.diff built created and dropped with filter(), costing one BTreeMap removal per table in the cluster on every diff. Collect the differences directly, and skip comparing tables carried over by reference. patch by Patrick McFadin; reviewed by TBD for CASSANDRA-21659 Assisted-by: Claude Opus 5 <noreply@anthropic.com>
1c01336 to
8a2a3e5
Compare
|
JMH numbers, as requested. Benchmark added at Baseline is
Average time — ns/op
Allocation is flat: 1.00x across an 8x larger schema, where the baseline is 13.2x. Time improves 26x at 3200 tables, though as noted in the description the diff still scans both collections, so it remains O(N) — the allocation is what stops scaling, not the walk. JMH agrees with the |
|
Correction to an earlier claim in the description. The description previously stated that the allocation "OOMs a node at ~3200 tables in one keyspace regardless of heap size", citing runs at 8, 12 and 24 GiB. That claim was wrong and I have removed it. The heap size in those runs was never actually varied.
The arithmetic closes exactly: retained heap is ~295,796 B per table (measured), and 3,500 × 295,796 B = 0.96 GiB. The node ran out of a 1 GiB heap, which says nothing about behaviour at a realistic heap size. What survives, and what does not:
With a correctly-sized heap, 10,000 tables completes: 28 minutes, ~2.75 GiB retained, on a gently rising curve with no cliff. So the failure this patch was motivated by is real but less dramatic than described — it is a scaling cost, not an unavoidable wall. Apologies for the noise. The measurement error was mine; better to correct it here than have a reviewer find it. |
|
Superseded by a single combined patch for CASSANDRA-21664, which carries this commit unchanged as one of its first three commits. Closing in favour of that PR. |
CASSANDRA-21659
Every schema change allocates in proportion to the whole schema rather than to what changed. This addresses the diffing component.
What
Keyspaces.diffandTables.diffbuildcreated/droppedwithfilter(), which removes every non-matching entry from a copy one at a time. On aCREATE TABLEno keyspace is created or dropped, soKeyspaces.filterfalls intowithoutKsTablesViewsand removes every table in the cluster individually — twice per diff.Tables.diffthen callsTableMetadata.comparefor every surviving table, andcomparehas no identity fast path.Several diffs run per DDL:
AlterSchemaStatement:194and:200,AlterSchema:160,DistributedSchema:213,:260and:325.Change
created/droppeddirectly instead of filtering whole collections.TableMetadataare reference-identical across a schema change (Tables.Builder.addstores the instance verbatim), andx.compare(x)is empty by construction — so identity is exact here, not an approximation.No signature, serialized-format or API changes.
Result
Allocation for adding one table:
Before is superlinear because the BTreeMap teardown is O(N log N). After is independent of schema size.
Scope — please read before benchmarking
This removes the allocation term, not the scan. Time stays O(N) per diff and bulk creation remains quadratic in wall-clock; at small N wall-clock will barely move. What it removes is allocation that scales with the size of the schema. Two further per-DDL allocation sites are being addressed separately.
Tests
New
KeyspacesDiffScalingTest: 2 scaling assertions, 3 correctness guards. It asserts an allocation ratio between a 400-table and a 3200-table fixture rather than an absolute byte count, so it needs no re-tuning per JDK or machine. Allocation rather than elapsed time because it is counted exactly rather than sampled, is independent of GC timing and machine load, and is the quantity that produces the failure.Verified red before the change and green after, and re-verified that the final test still fails with the fix stashed.
Regression:
org.apache.cassandra.schema27 suites / 130 tests,org.apache.cassandra.tcm13 suites / 55 tests, 0 failures.ant checkstyleandant checkstyle-testclean.