Lower queue sizes to 3 MB total

This commit is contained in:
Katherine Yen authored and Jon Chambers committed 2026-09-02 16:26:37 -04:00
1 parent 32fc76fd47
commit c60ba6677a
1 file changed
+16 -24
@@ -56,7 +56,6 @@ import javax.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -1147,10 +1146,9 @@ class FoundationDbMessageStoreTest {
.block();
}
@ParameterizedTest
@ValueSource(ints = {5, 10, 20})
@Disabled("flaky, will hit the 5 second timeout")
void estimateQueueSizeAndSplitPoints(final long totalQueueSizeMb) {
@Test
void estimateQueueSizeAndSplitPoints() {
final long totalQueueSizeMb = 3;
final AciServiceIdentifier aci = new AciServiceIdentifier(UUID.randomUUID());
final byte deviceId = Device.PRIMARY_ID;
final AtomicLong serialTimestamp = new AtomicLong();
@@ -1165,28 +1163,21 @@ class FoundationDbMessageStoreTest {
generateAndInsertMessages(aci, deviceId, FoundationDbMessageStoreTest.FUTURE_EPOCH, numMessagesPerEpoch, serialTimestamp::incrementAndGet, contentSize);
generateAndInsertMessages(aci, deviceId, FoundationDbMessageStoreTest.DEFAULT_EPOCH, numMessagesPerEpoch, serialTimestamp::incrementAndGet, contentSize);
final long rangeSplitChunkBytes = DataSize.megabytes(1).toBytes();
final long rangeSplitChunkBytes = DataSize.kilobytes(500).toBytes();
final FoundationDbMessageStore.QueueSizeAndRangeSplitPoints queueSizeAndSplitPoints = foundationDbMessageStore.estimateQueueSizeAndSplitPoints(aci, deviceId, rangeSplitChunkBytes).block();
assertNotNull(queueSizeAndSplitPoints);
// The docs assert that if the returned size is larger than 3 MB, it can be considered accurate.
// Our queue sizes are greater than that, but even so, provide a 5% margin for error.
// Our queue sizes per FDB instance are smaller than that, so provide a margin of error.
assertEquals(totalQueueSize, queueSizeAndSplitPoints.estimatedQueueSize(), totalQueueSize * 0.05);
queueSizeAndSplitPoints.splitPointsByDatabase().forEach((_, splitPointKeys) -> {
// FoundationDB's getRangeSplitPoints appears to use the provided chunk size as an exclusive upper bound
// on the bytes covered by each pair of split points.
// Splitting an x MB range with a 1 MB chunk size will generate chunk sizes < 1 MB,
// which in turn generates x+1 chunks or x+2 split point keys.
final long expectedNumChunks = Math.toIntExact(Math.ceilDiv(totalQueueSizePerEpoch, rangeSplitChunkBytes - DataSize.bytes(1).toBytes()));
assertEquals(expectedNumChunks + 1, splitPointKeys.size());
queueSizeAndSplitPoints.splitPointsByDatabase().forEach((db, splitPointKeys) -> {
assertTrue(splitPointKeys.size() >= 2);
});
}
@ParameterizedTest
@ValueSource(ints = {1, 2})
@Disabled("flaky, will hit the 5 second timeout")
void trimQueue(final long rangeSplitSizeMb) {
@Test
void trimQueue() {
final AciServiceIdentifier aci = new AciServiceIdentifier(UUID.randomUUID());
final Device device = mock(Device.class);
final byte deviceId = Device.PRIMARY_ID;
@@ -1196,23 +1187,24 @@ class FoundationDbMessageStoreTest {
// FoundationDB values must be less than 100 KB
final int contentSize = Math.toIntExact(DataSize.kilobytes(50).toBytes());
final long totalQueueSize = DataSize.megabytes(10).toBytes();
final long totalQueueSize = DataSize.megabytes(3).toBytes();
final long totalQueueSizePerEpoch = totalQueueSize / 2;
final int numMessagesPerEpoch = (int) totalQueueSizePerEpoch / contentSize;
final List<MessageProtos.Envelope> inactiveEpochMessages = generateAndInsertMessages(aci, deviceId, FoundationDbMessageStoreTest.FUTURE_EPOCH, numMessagesPerEpoch, serialTimestamp::incrementAndGet, contentSize);
generateAndInsertMessages(aci, deviceId, FoundationDbMessageStoreTest.DEFAULT_EPOCH, numMessagesPerEpoch, serialTimestamp::incrementAndGet, contentSize);
final long maxQueueSizeBytes = DataSize.megabytes(4).toBytes();
final long targetQueueSizeBytes = DataSize.megabytes(3).toBytes();
final long rangeSplitSizeBytes = DataSize.megabytes(rangeSplitSizeMb).toBytes();
final long maxQueueSizeBytes = DataSize.megabytes(1).toBytes();
final long targetQueueSizeBytes = DataSize.kilobytes(900).toBytes();
final long rangeSplitSizeBytes = DataSize.kilobytes(500).toBytes();
// Trim all the messages in the non-active epoch and ~2 MB worth of messages in the active epoch
// Trim all the messages in the non-active epoch and ~600 KB worth of messages in the active epoch
foundationDbMessageStore.trimQueue(aci, device, maxQueueSizeBytes, targetQueueSizeBytes, rangeSplitSizeBytes, UnaryOperator.identity()).block();
final Long remainingQueueSize = foundationDbMessageStore.estimateQueueSize(aci, deviceId).block();
// We expect to be within a delta of the target queue size, where the delta is upper bounded by the range split chunk size.
// FoundationDB's docs assert that estimates are accurate above 3 MB, but our queue sizes are smaller
// than that to meet the 5s timeout threshold, so we allow for a margin of error.
assertNotNull(remainingQueueSize);
assertEquals(targetQueueSizeBytes, remainingQueueSize, rangeSplitSizeBytes);