Skip to content

Commit

Permalink
Merge branch 'cassandra-4.1' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterinadimitrova2 committed Jul 28, 2022
2 parents ea03af4 + 222f66e commit 0e3bdea
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -38,6 +38,9 @@ Merged from 4.1:
* Revert removal of withBufferSizeInMB(int size) in CQLSSTableWriter.Builder class and deprecate it in favor of withBufferSizeInMiB(int size) (CASSANDRA-17675)
* Remove expired snapshots of dropped tables after restart (CASSANDRA-17619)
Merged from 4.0:
* Fix Setting Virtual Table - update after startup config properties gc_log_threshold_in_ms, gc_warn_threshold_in_ms,
conf.index_summary_capacity_in_mb, prepared_statements_cache_size_mb, key_cache_size_in_mb, counter_cache_size_in_mb
(CASSANDRA-17737)
* Clean up ScheduledExecutors, CommitLog, and MessagingService shutdown for in-JVM dtests (CASSANDRA-17731)
* Remove extra write to system table for prepared statements (CASSANDRA-17764)
Merge from 3.11:
Expand Down
4 changes: 2 additions & 2 deletions src/java/org/apache/cassandra/config/Config.java
Expand Up @@ -508,9 +508,9 @@ public MemtableOptions()
public volatile DurationSpec.IntMinutesBound index_summary_resize_interval = new DurationSpec.IntMinutesBound("60m");

@Replaces(oldName = "gc_log_threshold_in_ms", converter = Converters.MILLIS_DURATION_INT, deprecated = true)
public DurationSpec.IntMillisecondsBound gc_log_threshold = new DurationSpec.IntMillisecondsBound("200ms");
public volatile DurationSpec.IntMillisecondsBound gc_log_threshold = new DurationSpec.IntMillisecondsBound("200ms");
@Replaces(oldName = "gc_warn_threshold_in_ms", converter = Converters.MILLIS_DURATION_INT, deprecated = true)
public DurationSpec.IntMillisecondsBound gc_warn_threshold = new DurationSpec.IntMillisecondsBound("1s");
public volatile DurationSpec.IntMillisecondsBound gc_warn_threshold = new DurationSpec.IntMillisecondsBound("1s");

// TTL for different types of trace events.
@Replaces(oldName = "tracetype_query_ttl", converter = Converters.SECONDS_DURATION, deprecated=true)
Expand Down
19 changes: 19 additions & 0 deletions src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Expand Up @@ -729,6 +729,9 @@ else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().m

if (preparedStatementsCacheSizeInMiB == 0)
throw new NumberFormatException(); // to escape duplicating error message

// we need this assignment for the Settings virtual table - CASSANDRA-17734
conf.prepared_statements_cache_size = new DataStorageSpec.LongMebibytesBound(preparedStatementsCacheSizeInMiB);
}
catch (NumberFormatException e)
{
Expand All @@ -745,6 +748,9 @@ else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().m

if (keyCacheSizeInMiB < 0)
throw new NumberFormatException(); // to escape duplicating error message

// we need this assignment for the Settings Virtual Table - CASSANDRA-17734
conf.key_cache_size = new DataStorageSpec.LongMebibytesBound(keyCacheSizeInMiB);
}
catch (NumberFormatException e)
{
Expand Down Expand Up @@ -784,6 +790,9 @@ else if (conf.repair_session_space.toMebibytes() > (int) (Runtime.getRuntime().m
+ conf.paxos_cache_size + "', supported values are <integer> >= 0.", false);
}

// we need this assignment for the Settings virtual table - CASSANDRA-17735
conf.counter_cache_size = new DataStorageSpec.LongMebibytesBound(counterCacheSizeInMiB);

// if set to empty/"auto" then use 5% of Heap size
indexSummaryCapacityInMiB = (conf.index_summary_capacity == null)
? Math.max(1, (int) (Runtime.getRuntime().totalMemory() * 0.05 / 1024 / 1024))
Expand Down Expand Up @@ -3463,6 +3472,11 @@ public static long getGCLogThreshold()
return conf.gc_log_threshold.toMilliseconds();
}

public static void setGCLogThreshold(int gcLogThreshold)
{
conf.gc_log_threshold = new DurationSpec.IntMillisecondsBound(gcLogThreshold);
}

public static EncryptionContext getEncryptionContext()
{
return encryptionContext;
Expand All @@ -3473,6 +3487,11 @@ public static long getGCWarnThreshold()
return conf.gc_warn_threshold.toMilliseconds();
}

public static void setGCWarnThreshold(int threshold)
{
conf.gc_warn_threshold = new DurationSpec.IntMillisecondsBound(threshold);
}

public static boolean isCDCEnabled()
{
return conf.cdc_enabled;
Expand Down
36 changes: 20 additions & 16 deletions src/java/org/apache/cassandra/service/GCInspector.java
Expand Up @@ -53,8 +53,6 @@ public class GCInspector implements NotificationListener, GCInspectorMXBean
{
public static final String MBEAN_NAME = "org.apache.cassandra.service:type=GCInspector";
private static final Logger logger = LoggerFactory.getLogger(GCInspector.class);
private volatile long gcLogThreshholdInMs = DatabaseDescriptor.getGCLogThreshold();
private volatile long gcWarnThreasholdInMs = DatabaseDescriptor.getGCWarnThreshold();

/*
* The field from java.nio.Bits that tracks the total number of allocated
Expand Down Expand Up @@ -292,9 +290,9 @@ public void handleNotification(final Notification notification, final Object han
break;
}

if (gcWarnThreasholdInMs != 0 && duration > gcWarnThreasholdInMs)
if (getGcWarnThresholdInMs() != 0 && duration > getGcWarnThresholdInMs())
logger.warn(sb.toString());
else if (duration > gcLogThreshholdInMs)
else if (duration > getGcLogThresholdInMs())
logger.info(sb.toString());
else if (logger.isTraceEnabled())
logger.trace(sb.toString());
Expand Down Expand Up @@ -345,37 +343,43 @@ private static long getAllocatedDirectMemory()

public void setGcWarnThresholdInMs(long threshold)
{
long gcLogThresholdInMs = getGcLogThresholdInMs();
if (threshold < 0)
throw new IllegalArgumentException("Threshold must be greater than or equal to 0");
if (threshold != 0 && threshold <= gcLogThreshholdInMs)
throw new IllegalArgumentException("Threshold must be greater than gcLogTreasholdInMs which is currently "
+ gcLogThreshholdInMs);
gcWarnThreasholdInMs = threshold;
if (threshold != 0 && threshold <= gcLogThresholdInMs)
throw new IllegalArgumentException("Threshold must be greater than gcLogThresholdInMs which is currently "
+ gcLogThresholdInMs);
if (threshold > Integer.MAX_VALUE)
throw new IllegalArgumentException("Threshold must be less than Integer.MAX_VALUE");
DatabaseDescriptor.setGCWarnThreshold((int)threshold);
}

public long getGcWarnThresholdInMs()
{
return gcWarnThreasholdInMs;
return DatabaseDescriptor.getGCWarnThreshold();
}

public void setGcLogThresholdInMs(long threshold)
{
if (threshold <= 0)
throw new IllegalArgumentException("Threashold must be greater than 0");
if (gcWarnThreasholdInMs != 0 && threshold > gcWarnThreasholdInMs)
throw new IllegalArgumentException("Threashold must be less than gcWarnTreasholdInMs which is currently "
+ gcWarnThreasholdInMs);
gcLogThreshholdInMs = threshold;
throw new IllegalArgumentException("Threshold must be greater than 0");

long gcWarnThresholdInMs = getGcWarnThresholdInMs();
if (gcWarnThresholdInMs != 0 && threshold > gcWarnThresholdInMs)
throw new IllegalArgumentException("Threshold must be less than gcWarnThresholdInMs which is currently "
+ gcWarnThresholdInMs);

DatabaseDescriptor.setGCLogThreshold((int) threshold);
}

public long getGcLogThresholdInMs()
{
return gcLogThreshholdInMs;
return DatabaseDescriptor.getGCLogThreshold();
}

public long getStatusThresholdInMs()
{
return gcWarnThreasholdInMs != 0 ? gcWarnThreasholdInMs : gcLogThreshholdInMs;
return getGcWarnThresholdInMs() != 0 ? getGcWarnThresholdInMs() : getGcLogThresholdInMs();
}

}
17 changes: 16 additions & 1 deletion test/unit/org/apache/cassandra/service/GCInspectorTest.java
Expand Up @@ -64,11 +64,16 @@ public void ensureZeroIsOk()
{
gcInspector.setGcWarnThresholdInMs(0);
Assert.assertEquals(gcInspector.getStatusThresholdInMs(), gcInspector.getGcLogThresholdInMs());
Assert.assertEquals(0, DatabaseDescriptor.getGCWarnThreshold());
Assert.assertEquals(200, DatabaseDescriptor.getGCLogThreshold());
}

@Test(expected=IllegalArgumentException.class)
public void ensureLogLessThanWarn()
{
Assert.assertEquals(200, gcInspector.getGcLogThresholdInMs());
gcInspector.setGcWarnThresholdInMs(1000);
Assert.assertEquals(1000, gcInspector.getGcWarnThresholdInMs());
gcInspector.setGcLogThresholdInMs(gcInspector.getGcWarnThresholdInMs() + 1);
}

Expand All @@ -77,6 +82,16 @@ public void testDefaults()
{
gcInspector.setGcLogThresholdInMs(200);
gcInspector.setGcWarnThresholdInMs(1000);
Assert.assertEquals(200, DatabaseDescriptor.getGCLogThreshold());
Assert.assertEquals(200, gcInspector.getGcLogThresholdInMs());
Assert.assertEquals(1000, DatabaseDescriptor.getGCWarnThreshold());
Assert.assertEquals(1000, gcInspector.getGcWarnThresholdInMs());
}

@Test(expected=IllegalArgumentException.class)
public void testMaxValue()
{
gcInspector.setGcLogThresholdInMs(200);
gcInspector.setGcWarnThresholdInMs(Integer.MAX_VALUE+1L);
}

}

0 comments on commit 0e3bdea

Please sign in to comment.