Cyrill commented on code in PR #6711:
URL: https://github.com/apache/ignite-3/pull/6711#discussion_r2416287348


##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/StorageCleanupTest.java:
##########
@@ -970,4 +974,117 @@ void testCleanupBeforeUpdateError() {
         verify(indexUpdateHandler, never()).tryRemoveFromIndexes(any(), any(), 
any(), any());
     }
 
+    @Test
+    void testSimpleDeleteOperation() {
+        UUID txUuid = UUID.randomUUID();
+        TablePartitionId partitionId = new TablePartitionId(333, PARTITION_ID);
+
+        BinaryRow row1 = binaryRow(new TestKey(1, "foo1"), new TestValue(2, 
"bar"));
+        UUID rowId = UUID.randomUUID();
+        HybridTimestamp commitTs = CLOCK.now();
+
+        storageUpdateHandler.handleUpdate(txUuid, rowId, partitionId, row1, 
true, null, null, null, null);
+        storageUpdateHandler.switchWriteIntents(txUuid, true, commitTs, null);
+
+        ReadResult committedResult = storage.read(new RowId(PARTITION_ID, 
rowId), HybridTimestamp.MAX_VALUE);
+        assertFalse(committedResult.isWriteIntent());
+        assertEquals(row1, committedResult.binaryRow());
+
+        UUID deleteTx = UUID.randomUUID();
+
+        storageUpdateHandler.handleUpdate(deleteTx, rowId, partitionId, null, 
true, null, null, null, null);
+
+        ReadResult deleteResult = storage.read(new RowId(PARTITION_ID, rowId), 
HybridTimestamp.MAX_VALUE);
+        assertTrue(deleteResult.isWriteIntent());
+        assertNull(deleteResult.binaryRow());
+    }
+
+    @Test
+    void testDeleteCommitCleanup() {
+        UUID txUuid = UUID.randomUUID();
+        TablePartitionId partitionId = new TablePartitionId(333, PARTITION_ID);
+
+        BinaryRow row1 = binaryRow(new TestKey(1, "foo1"), new TestValue(2, 
"bar"));
+        UUID rowId = UUID.randomUUID();
+        HybridTimestamp commitTs = CLOCK.now();
+
+        storageUpdateHandler.handleUpdate(txUuid, rowId, partitionId, row1, 
true, null, null, null, null);
+        storageUpdateHandler.switchWriteIntents(txUuid, true, commitTs, null);
+
+        UUID deleteTx = UUID.randomUUID();
+
+        storageUpdateHandler.handleUpdate(deleteTx, rowId, partitionId, null, 
true, null, null, null, null);
+
+        storageUpdateHandler.switchWriteIntents(deleteTx, true, CLOCK.now(), 
null);
+
+        ReadResult finalResult = storage.read(new RowId(PARTITION_ID, rowId), 
HybridTimestamp.MAX_VALUE);
+        assertFalse(finalResult.isWriteIntent());
+        assertNull(finalResult.binaryRow());
+    }
+
+    @Test
+    void testDeleteAbortCleanup() {
+        UUID txUuid = UUID.randomUUID();
+        TablePartitionId partitionId = new TablePartitionId(333, PARTITION_ID);
+
+        BinaryRow row1 = binaryRow(new TestKey(1, "foo1"), new TestValue(2, 
"bar"));
+        UUID rowId = UUID.randomUUID();
+        HybridTimestamp commitTs = CLOCK.now();
+
+        storageUpdateHandler.handleUpdate(txUuid, rowId, partitionId, row1, 
true, null, null, null, null);
+        storageUpdateHandler.switchWriteIntents(txUuid, true, commitTs, null);
+
+        UUID deleteTx = UUID.randomUUID();
+
+        storageUpdateHandler.handleUpdate(deleteTx, rowId, partitionId, null, 
true, null, null, null, null);
+
+        storageUpdateHandler.switchWriteIntents(deleteTx, false, null, null);
+
+        ReadResult finalResult = storage.read(new RowId(PARTITION_ID, rowId), 
HybridTimestamp.MAX_VALUE);
+        assertFalse(finalResult.isWriteIntent());
+        assertEquals(row1, finalResult.binaryRow());
+    }
+
+    @Test
+    void testCleanupWithNullLastCommitTsThrowsException() {
+        UUID tx1 = UUID.randomUUID();
+        UUID tx2 = UUID.randomUUID();
+        UUID tx3 = UUID.randomUUID();
+        TablePartitionId partitionId = new TablePartitionId(333, PARTITION_ID);
+
+        BinaryRow row1 = binaryRow(new TestKey(1, "foo1"), new TestValue(2, 
"bar"));
+        UUID rowId = UUID.randomUUID();
+
+        storageUpdateHandler.handleUpdate(tx1, rowId, partitionId, row1, true, 
null, null, null, null);
+        assertTrue(storage.read(new RowId(PARTITION_ID, rowId), 
HybridTimestamp.MAX_VALUE).isWriteIntent());
+
+        // add write from tx2 without lastCommitTs
+        BinaryRow row2 = binaryRow(new TestKey(3, "foo3"), new TestValue(4, 
"baz"));
+
+        // When handleUpdate tries to add write and encounters write intent 
with null lastCommitTs
+        TxIdMismatchException exception = 
assertThrows(TxIdMismatchException.class, () ->
+                storageUpdateHandler.handleUpdate(tx2, rowId, partitionId, 
row2, true, null, null, null, null));
+        assertTrue(exception.getMessage().contains(tx1.toString()));
+        assertTrue(exception.getMessage().contains(tx2.toString()));
+
+        // Verify that no cleanup operations were attempted
+        verify(storage, never()).commitWrite(any(), any(), any());
+        verify(storage, never()).abortWrite(any(), any());
+        verify(indexUpdateHandler, never()).tryRemoveFromIndexes(any(), any(), 
any(), any());
+
+        // Verify the original write intent is still there
+        ReadResult result = storage.read(new RowId(PARTITION_ID, rowId), 
HybridTimestamp.MAX_VALUE);
+        assertTrue(result.isWriteIntent());
+        assertEquals(row1, result.binaryRow());
+
+        // also check the same logic applies for the committed case

Review Comment:
   Please remember that according to the code style comments start with a 
capital letter and end with a full stop.



-- 
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]

Reply via email to