Reduce disk space usage by CommitLogSegmentManagerCDCTest

patch by Dmitry Konstantinov; reviewed by Michael Semb Wever for CASSANDRA-21534
This commit is contained in:
Dmitry Konstantinov 2026-07-23 03:15:55 +01:00 committed by Stefan Miklosovic
parent 4066139d3f
commit 0040482e26
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
1 changed files with 32 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import com.google.common.util.concurrent.Uninterruptibles;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@ -42,9 +43,11 @@ import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.RowUpdateBuilder;
import org.apache.cassandra.db.commitlog.CommitLogSegment.CDCState;
import org.apache.cassandra.db.lifecycle.LifecycleTransaction;
import org.apache.cassandra.exceptions.CDCWriteException;
import org.apache.cassandra.io.util.File;
import org.apache.cassandra.io.util.FileReader;
import org.apache.cassandra.schema.Schema;
import org.apache.cassandra.schema.TableMetadata;
public class CommitLogSegmentManagerCDCTest extends CQLTester
@ -57,7 +60,11 @@ public class CommitLogSegmentManagerCDCTest extends CQLTester
{
ServerTestUtils.daemonInitialization();
DatabaseDescriptor.setCDCEnabled(true);
DatabaseDescriptor.setCDCTotalSpaceInMiB(1024);
// The bulk writes are sized to commitLogSegmentSize/3, so the suite's disk footprint scales
// with the segment size; shrink it to the 1 MiB floor. Cap the default CDC space too: bulkWrite
// writes ~2x the CDC limit, so this bounds how much the non-blocking cases flush to disk.
DatabaseDescriptor.setCommitLogSegmentSize(1);
DatabaseDescriptor.setCDCTotalSpaceInMiB(100);
CQLTester.setUpClass();
}
@ -71,6 +78,24 @@ public class CommitLogSegmentManagerCDCTest extends CQLTester
((CommitLogSegmentManagerCDC)CommitLog.instance.segmentManager).updateCDCTotalSize();
}
@After
public void afterTest() throws Throwable
{
// Reclaim the SSTables this test wrote so data/ doesn't grow across methods; CQLTester#afterTest
// only clears schema-tracking state. Do NOT stop/delete the commit log here: super.afterTest()
// resets the CMS, whose schema re-application runs asynchronously on the TCM log follower, and
// deleting segments underneath it makes CDC hard-linking fail ("hard link to file that does not
// exist"). beforeTest() restarts the commit log for the next test instead.
Keyspace ks = Schema.instance.getKeyspaceInstance(keyspace());
if (ks != null)
{
for (ColumnFamilyStore cfs : ks.getColumnFamilyStores())
cfs.truncateBlockingWithoutSnapshot();
LifecycleTransaction.waitForDeletions();
}
super.afterTest();
}
@Test
public void testCDCWriteFailure() throws Throwable
{
@ -456,10 +481,14 @@ public class CommitLogSegmentManagerCDCTest extends CQLTester
{
TableMetadata ccfm = Keyspace.open(keyspace()).getColumnFamilyStore(tableName).metadata();
boolean blockWrites = DatabaseDescriptor.getCDCBlockWrites();
// Spin to make sure we hit CDC capacity
// Write enough to overflow the configured CDC limit so we reliably hit capacity. Derive the
// count from the CDC size and mutation size. Blocking mode stops
// early on the first CDCWriteException; non-blocking mode writes the whole run, recycling
// older segments (2x the fill count keeps it exercising recycling without over-writing).
int writes = 2 * (int) (DatabaseDescriptor.getCDCTotalSpace() / mutationSize);
try
{
for (int i = 0; i < 1000; i++)
for (int i = 0; i < writes; i++)
{
new RowUpdateBuilder(ccfm, 0, i)
.add("data", randomizeBuffer(mutationSize))