ibessonov commented on code in PR #6983:
URL: https://github.com/apache/ignite-3/pull/6983#discussion_r2533684144
##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/gc/AbstractGcUpdateHandlerTest.java:
##########
@@ -250,10 +255,95 @@ void testVacuumThenInsert() {
}
}
+ /**
+ * Tests that {@link GcUpdateHandler#vacuumBatch} exits early when {@code
shouldRelease()} returns {@code true}.
+ *
+ * <p>This test verifies that the vacuum process can be interrupted
mid-execution by the {@code shouldRelease()}
+ * mechanism, which is used to allow other operations (like rebalancing)
to acquire necessary locks.
+ */
+ @Test
+ void testShouldReleaseExitsEarly() {
+ // Given: A partition storage with controllable shouldRelease()
behavior
+ AtomicBoolean shouldRelease = new AtomicBoolean(false);
+ AtomicBoolean shouldReleaseCalled = new AtomicBoolean(false);
+
+ BooleanSupplier shouldReleaseSupplier = () -> {
+ shouldReleaseCalled.set(true);
+ return shouldRelease.get();
+ };
+
+ TestPartitionDataStorage partitionStorage =
createTestMvPartitionStorage(shouldReleaseSupplier);
+ IndexUpdateHandler indexUpdateHandler = createIndexUpdateHandler();
+ GcUpdateHandler gcUpdateHandler =
createGcUpdateHandler(partitionStorage, indexUpdateHandler);
+
+ HybridTimestamp lowWatermark = HybridTimestamp.MAX_VALUE;
+
+ // Given: Multiple rows with garbage to collect (10 rows with 2
versions each)
+ for (int i = 0; i < 10; i++) {
+ RowId rowId = new RowId(PARTITION_ID);
+ BinaryRow row = binaryRow(new TestKey(i, "key" + i), new
TestValue(i, "value" + i));
+
+ addWriteCommitted(partitionStorage, rowId, row, clock.now());
+ addWriteCommitted(partitionStorage, rowId, row, clock.now());
+ }
+
+ // When: Vacuum runs with shouldRelease() returning false
+ shouldRelease.set(false);
+ boolean hasGarbageLeft = gcUpdateHandler.vacuumBatch(lowWatermark,
100, true);
+
+ // Then: All garbage is processed and shouldRelease() was checked
+ assertFalse(hasGarbageLeft, "Expected no garbage left after full
vacuum");
+ assertTrue(shouldReleaseCalled.get(), "Expected shouldRelease() to be
called during vacuum");
+
+ // Given: More rows with garbage to collect (another 10 rows with 2
versions each)
+ for (int i = 10; i < 20; i++) {
+ RowId rowId = new RowId(PARTITION_ID);
+ BinaryRow row = binaryRow(new TestKey(i, "key" + i), new
TestValue(i, "value" + i));
+
+ addWriteCommitted(partitionStorage, rowId, row, clock.now());
+ addWriteCommitted(partitionStorage, rowId, row, clock.now());
+ }
+
+ // When: Vacuum runs with shouldRelease() returning true (simulating
lock contention)
+ shouldRelease.set(true);
+ shouldReleaseCalled.set(false);
+ hasGarbageLeft = gcUpdateHandler.vacuumBatch(lowWatermark, 10, true);
Review Comment:
We may have two tests instead of reinitializing the state for the second
scenario. What do you think?
--
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]