Reduce allocations in DefaultQueryOptions when read thresholds are enabled

patch by Francisco Guerrero; reviewed by Dmitry Konstantinov, Stefan Miklosovic for CASSANDRA-21467
This commit is contained in:
Francisco Guerrero 2026-06-16 05:50:45 -05:00 committed by Stefan Miklosovic
parent f7f52421c7
commit 8fc52f5d2f
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
4 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,5 @@
6.0-alpha2
* Reduce allocations in DefaultQueryOptions (CASSANDRA-21467)
* Coordinator load-shedding returns OverloadedException without setting streamId, misrouting query responses (CASSANDRA-21508)
* Reduce number of scheduledTasks on metric id release in ThreadLocalMetrics (CASSANDRA-21475)
* Cache various Enum.values() used in deserialization to avoid per-read array allocation (CASSANDRA-21528)

View File

@ -85,6 +85,7 @@ import org.apache.cassandra.config.Config.DiskAccessMode;
import org.apache.cassandra.config.Config.PaxosOnLinearizabilityViolation;
import org.apache.cassandra.config.Config.PaxosStatePurging;
import org.apache.cassandra.config.DurationSpec.IntMillisecondsBound;
import org.apache.cassandra.cql3.QueryOptions;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.db.commitlog.AbstractCommitLogSegmentManager;
import org.apache.cassandra.db.commitlog.CommitLog;
@ -272,6 +273,8 @@ public class DatabaseDescriptor
public static volatile boolean allowUnlimitedConcurrentValidations = ALLOW_UNLIMITED_CONCURRENT_VALIDATIONS.getBoolean();
private static volatile QueryOptions.DefaultReadThresholds defaultReadThresholds;
/**
* RetryStrategy which provides exponential backoff with full jitter, for use by both CMS and non-CMS members
* when submitting a Commit request. The range and increments of the backoff times are defined by
@ -5555,6 +5558,14 @@ public class DatabaseDescriptor
return conf.invalid_legacy_protocol_magic_no_spam_enabled;
}
public static QueryOptions.DefaultReadThresholds getDefaultReadThresholds()
{
if (defaultReadThresholds == null)
defaultReadThresholds = new QueryOptions.DefaultReadThresholds(getCoordinatorReadSizeWarnThreshold(),
getCoordinatorReadSizeFailThreshold());
return defaultReadThresholds;
}
public static boolean getReadThresholdsEnabled()
{
return conf.read_thresholds_enabled;
@ -5579,6 +5590,7 @@ public class DatabaseDescriptor
{
logger.info("updating coordinator_read_size_warn_threshold to {}", value);
conf.coordinator_read_size_warn_threshold = value;
defaultReadThresholds = new QueryOptions.DefaultReadThresholds(value, getCoordinatorReadSizeFailThreshold());
}
@Nullable
@ -5591,6 +5603,7 @@ public class DatabaseDescriptor
{
logger.info("updating coordinator_read_size_fail_threshold to {}", value);
conf.coordinator_read_size_fail_threshold = value;
defaultReadThresholds = new QueryOptions.DefaultReadThresholds(getCoordinatorReadSizeWarnThreshold(), value);
}
@Nullable

View File

@ -322,7 +322,7 @@ public abstract class QueryOptions implements RealTimeFunctionContext
// if daemon initialization hasn't happened yet (very common in tests) then ignore
if (!DatabaseDescriptor.isDaemonInitialized() || !DatabaseDescriptor.getReadThresholdsEnabled())
return DisabledReadThresholds.INSTANCE;
return new DefaultReadThresholds(DatabaseDescriptor.getCoordinatorReadSizeWarnThreshold(), DatabaseDescriptor.getCoordinatorReadSizeFailThreshold());
return DatabaseDescriptor.getDefaultReadThresholds();
}
}
@ -349,7 +349,7 @@ public abstract class QueryOptions implements RealTimeFunctionContext
}
}
private static class DefaultReadThresholds implements ReadThresholds
public static class DefaultReadThresholds implements ReadThresholds
{
private final long warnThresholdBytes;
private final long abortThresholdBytes;

View File

@ -123,6 +123,8 @@ public class DatabaseDescriptorRefTest
"org.apache.cassandra.config.Config$CorruptedTombstoneStrategy",
"org.apache.cassandra.config.Config$BatchlogEndpointStrategy",
"org.apache.cassandra.config.Config$TombstonesMetricGranularity",
"org.apache.cassandra.cql3.QueryOptions$DefaultReadThresholds",
"org.apache.cassandra.cql3.QueryOptions$ReadThresholds",
"org.apache.cassandra.service.consensus.UnsupportedTransactionConsistencyLevel",
"org.apache.cassandra.repair.autorepair.AutoRepairConfig",
"org.apache.cassandra.repair.autorepair.AutoRepairConfig$Options",