From 999d6d7c56b8ac320ac771d21555fa49e6ff12df Mon Sep 17 00:00:00 2001 From: Francisco Guerrero Date: Tue, 16 Jun 2026 05:50:45 -0500 Subject: [PATCH] Reduce allocations in DefaultQueryOptions when read thresholds are enabled patch by Francisco Guerrero; reviewed by TBD for CASSANDRA-21467 --- .../org/apache/cassandra/cql3/QueryOptions.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/cassandra/cql3/QueryOptions.java b/src/java/org/apache/cassandra/cql3/QueryOptions.java index afc5bacc38c1..e9313e50f29c 100644 --- a/src/java/org/apache/cassandra/cql3/QueryOptions.java +++ b/src/java/org/apache/cassandra/cql3/QueryOptions.java @@ -322,7 +322,7 @@ static ReadThresholds create() // 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 DefaultReadThresholds.INSTANCE; } } @@ -351,14 +351,7 @@ public long getCoordinatorReadSizeFailThresholdBytes() private static class DefaultReadThresholds implements ReadThresholds { - private final long warnThresholdBytes; - private final long abortThresholdBytes; - - public DefaultReadThresholds(DataStorageSpec.LongBytesBound warnThreshold, DataStorageSpec.LongBytesBound abortThreshold) - { - this.warnThresholdBytes = warnThreshold == null ? -1 : warnThreshold.toBytes(); - this.abortThresholdBytes = abortThreshold == null ? -1 : abortThreshold.toBytes(); - } + private static final DefaultReadThresholds INSTANCE = new DefaultReadThresholds(); @Override public boolean isEnabled() @@ -369,13 +362,15 @@ public boolean isEnabled() @Override public long getCoordinatorReadSizeWarnThresholdBytes() { - return warnThresholdBytes; + DataStorageSpec.LongBytesBound warnThreshold = DatabaseDescriptor.getCoordinatorReadSizeWarnThreshold(); + return warnThreshold == null ? -1 : warnThreshold.toBytes(); } @Override public long getCoordinatorReadSizeFailThresholdBytes() { - return abortThresholdBytes; + DataStorageSpec.LongBytesBound abortThreshold = DatabaseDescriptor.getCoordinatorReadSizeFailThreshold(); + return abortThreshold == null ? -1 : abortThreshold.toBytes(); } }