dcapwell commented on code in PR #4556: URL: https://github.com/apache/cassandra/pull/4556#discussion_r2748588723
########## test/distributed/org/apache/cassandra/distributed/test/thresholds/WriteSizeWarningTest.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.distributed.test.thresholds; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.List; + +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.config.DataStorageSpec; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Keyspace; +import org.apache.cassandra.dht.Murmur3Partitioner; +import org.apache.cassandra.utils.ByteBufferUtil; + +import static org.apache.cassandra.config.DataStorageSpec.DataStorageUnit.MEBIBYTES; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Distributed tests for write size threshold warnings. + * Tests that writes to large partitions (tracked in TopPartitionTracker) trigger warnings. + */ +public class WriteSizeWarningTest extends AbstractWriteThresholdWarning +{ + private static final long WARN_THRESHOLD_BYTES = 5 * 1024 * 1024; // 5MB + private static final Logger log = LoggerFactory.getLogger(WriteSizeWarningTest.class); + + @BeforeClass + public static void setupClass() throws IOException + { + AbstractWriteThresholdWarning.setupClass(); + + // Setup write size threshold after cluster init + CLUSTER.stream().forEach(i -> i.runOnInstance(() -> { + DatabaseDescriptor.setWriteSizeWarnThreshold(new DataStorageSpec.LongBytesBound(5, MEBIBYTES)); + // Set minimum tracked partition size to ensure partitions are tracked + // This should be lower than the test value (10MB) to allow tracking + DatabaseDescriptor.setMinTrackedPartitionSizeInBytes(new DataStorageSpec.LongBytesBound(1, MEBIBYTES)); + DatabaseDescriptor.setWriteThresholdsEnabled(true); + })); + } + + @Override + protected long getWarnThreshold() + { + return WARN_THRESHOLD_BYTES; + } + + @Override + protected void populateTopPartitions(int pk, long sizeBytes) + { + CLUSTER.stream().forEach(node -> node.runOnInstance(() -> { + // Get the DecoratedKey for the partition + var key = Murmur3Partitioner.instance.decorateKey(ByteBufferUtil.bytes(pk)); + + // Get the ColumnFamilyStore + ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore("tbl"); + + // If topPartitions is null, create it using reflection + if (cfs.topPartitions == null) + { + try + { + Field field = ColumnFamilyStore.class.getDeclaredField("topPartitions"); + field.setAccessible(true); Review Comment: i think this will have issues on jdk 17+... let me find how we do this now -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

