You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/12/21 11:35:12 UTC

[GitHub] [ignite-3] ibessonov opened a new pull request, #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

ibessonov opened a new pull request, #1464:
URL: https://github.com/apache/ignite-3/pull/1464

   https://issues.apache.org/jira/browse/IGNITE-18019


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056208244


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -162,4 +217,24 @@ private void cleanup() {
             row = pollForVacuum(HybridTimestamp.MAX_VALUE);
         } while (row != null);
     }
+
+    private enum AddAndCommit {
+        ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                HybridTimestamp ts = test.clock.now();
+
+                test.addWriteCommitted(ROW_ID, binaryRow, ts);
+
+                return ts;
+            }
+        },
+        NON_ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                return test.addAndCommit(binaryRow);
+            }
+        };
+        abstract HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow);

Review Comment:
   I wonder why I have a green PMD check...



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055228440


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)

Review Comment:
   I forgot to remove it apparently, thank you!



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056082288


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   Continuing the example. We now have 2 identical entries in the GC queue. When the watermark is high enough, GC grabs first of them, nullifies the pointer to the version it shadows, but this changes nothing from the point of view of the user, because this entry is not included in the chain. So GC vacuumed something, but in reality it did not. This might cause confusing failures in tests.
   
   Why don't we just add synchronization to make sure it behaves as predictable as possible? This is a test storage, after all. If we must have a trade-off between performance and simplicity/predictability, we should choose the latter.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056118383


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/BaseMvPartitionStorageTest.java:
##########
@@ -47,9 +47,9 @@ public abstract class BaseMvPartitionStorageTest extends BaseMvStoragesTest {
 
     protected static final TestKey KEY = new TestKey(10, "foo");
 
-    protected static final TestValue VALUE = new TestValue(20, "bar");
+    protected static final BinaryRow BINARY_ROW = binaryRow(KEY, new TestValue(20, "bar"));
 
-    protected static final BinaryRow BINARY_ROW = binaryRow(KEY, VALUE);
+    protected static final BinaryRow BINARY_ROW2 = binaryRow(KEY, new TestValue(20, "bar"));

Review Comment:
   Copy-paste, sorry



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055287006


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   That is true, comparator should remove this '2 entries' problem. But there is still '2 writes to the queue' problem.
   
   Imagine that:
   
   1. `map.compute()` makes first attempt, adds an entry to the queue
   2. GC thread calls `pollForVacuum()` and removes this entry
   3. `map.compute()` makes a second attempt and adds a second entry (equal to the first one) for the second time
   4. GC thread polls again, so it sees the same (actually, a different, but equal) entry for the second time
   
   Is this possible? Is this valid?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055226803


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {

Review Comment:
   I thought about it, it's not a big deal in this test.
   Tests that need cleanup to work properly, do it at the end of every iteration. 



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056203297


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -162,4 +217,24 @@ private void cleanup() {
             row = pollForVacuum(HybridTimestamp.MAX_VALUE);
         } while (row != null);
     }
+
+    private enum AddAndCommit {
+        ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                HybridTimestamp ts = test.clock.now();
+
+                test.addWriteCommitted(ROW_ID, binaryRow, ts);
+
+                return ts;
+            }
+        },
+        NON_ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                return test.addAndCommit(binaryRow);
+            }
+        };
+        abstract HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow);

Review Comment:
   Blank line above?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055227792


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);

Review Comment:
   Ok, I'll do it in places where we compare values



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055368571


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   GC cannot remove this entry, we only remove "old" entries, and even they must have a "parent" in the chain. Situation that you're describing is only possible in tests, and I don't see a necessity to cover it



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov merged pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov merged PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055222992


##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,43 @@ public static <T> T await(CompletionStage<T> stage, long timeout, TimeUnit unit)
     public static <T> T await(CompletionStage<T> stage) {
         return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
     }
+
+    /**
+     * Runs all actions, each in a separate thread, having a {@link CyclicBarrier} before calling {@link RunnableX#run()}.
+     *
+     * @throws InterruptedException If failed to {@link Thread#join()} a thread.
+     */
+    public static void startRace(RunnableX... actions) throws InterruptedException {

Review Comment:
   Good



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055268099


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),

Review Comment:
   My concern is about a different row (different value), but with same rowId. This would update the existing write intent, but it will change its value. In the current test the value after change is same, so it's impossible to say whether the update was applied or not.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
tkalkirill commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056235385


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -162,4 +217,24 @@ private void cleanup() {
             row = pollForVacuum(HybridTimestamp.MAX_VALUE);
         } while (row != null);
     }
+
+    private enum AddAndCommit {
+        ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                HybridTimestamp ts = test.clock.now();
+
+                test.addWriteCommitted(ROW_ID, binaryRow, ts);
+
+                return ts;
+            }
+        },
+        NON_ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                return test.addAndCommit(binaryRow);
+            }
+        };
+        abstract HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow);

Review Comment:
   Are you using Gradle?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055233039


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);
+
+        // Data is still visible for older timestamps.
+        assertNull(storage.pollForVacuum(firstCommitTs));
+
+        assertNull(storage.pollForVacuum(tsBetweenCommits));
+
+        // Once a low watermark value becomes equal to second commit timestamp, previous value
+        // becomes completely inaccessible and should be purged.
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Read from the old timestamp should return null.
+        assertNull(read(ROW_ID, firstCommitTs));
+
+        // Read from the newer timestamp should return last value.
+        assertRowMatches(read(ROW_ID, secondCommitTs), BINARY_ROW);
+    }
+
+    @Test
+    void testPollFromUnderTombstone() {
+        addAndCommit(BINARY_ROW);
+        HybridTimestamp secondCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, secondCommitTs));
+
+        // Check that tombstone is also deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testDoubleTombstone() {
+        addAndCommit(BINARY_ROW);
+        addAndCommit(null);
+        HybridTimestamp lastCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(lastCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, lastCommitTs));
+
+        // Check that all tombstones are deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testManyOldVersions() {
+        addAndCommit(BINARY_ROW);
+
+        BinaryRow binaryRow2 = binaryRow(KEY, new TestValue(50, "50"));
+
+        addAndCommit(binaryRow2);
+
+        HybridTimestamp lowWatermark = addAndCommit(null);
+
+        // Poll the oldest row.
+        BinaryRowWithRowId row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Poll the next oldest row.
+        row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), binaryRow2);
+
+        // Nothing else to poll.
+        assertNull(pollForVacuum(lowWatermark));
+    }
+}

Review Comment:
   Scenarios that are closer to the real usages will be tested later, when we implement the component that actually calls this new method.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055268664


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testRegularGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);

Review Comment:
   Oh, it's 'assume', not 'assert'. My bad.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055222174


##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/BinaryRowWithRowId.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.ignite.internal.storage;
+
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper that holds both {@link BinaryRow} and {@link RowId}.
+ */
+public class BinaryRowWithRowId {

Review Comment:
   Ok, why not



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
tkalkirill commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056235385


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -162,4 +217,24 @@ private void cleanup() {
             row = pollForVacuum(HybridTimestamp.MAX_VALUE);
         } while (row != null);
     }
+
+    private enum AddAndCommit {
+        ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                HybridTimestamp ts = test.clock.now();
+
+                test.addWriteCommitted(ROW_ID, binaryRow, ts);
+
+                return ts;
+            }
+        },
+        NON_ATOMIC {
+            @Override
+            HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow) {
+                return test.addAndCommit(binaryRow);
+            }
+        };
+        abstract HybridTimestamp perform(AbstractMvPartitionStorageConcurrencyTest test, @Nullable BinaryRow binaryRow);

Review Comment:
   Are you using Gradle?
   Maven checks everything well.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055289721


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);
+
+        // Data is still visible for older timestamps.
+        assertNull(storage.pollForVacuum(firstCommitTs));
+
+        assertNull(storage.pollForVacuum(tsBetweenCommits));
+
+        // Once a low watermark value becomes equal to second commit timestamp, previous value
+        // becomes completely inaccessible and should be purged.
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Read from the old timestamp should return null.
+        assertNull(read(ROW_ID, firstCommitTs));
+
+        // Read from the newer timestamp should return last value.
+        assertRowMatches(read(ROW_ID, secondCommitTs), BINARY_ROW);
+    }
+
+    @Test
+    void testPollFromUnderTombstone() {
+        addAndCommit(BINARY_ROW);
+        HybridTimestamp secondCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, secondCommitTs));
+
+        // Check that tombstone is also deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testDoubleTombstone() {
+        addAndCommit(BINARY_ROW);
+        addAndCommit(null);
+        HybridTimestamp lastCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(lastCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, lastCommitTs));
+
+        // Check that all tombstones are deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testManyOldVersions() {
+        addAndCommit(BINARY_ROW);
+
+        BinaryRow binaryRow2 = binaryRow(KEY, new TestValue(50, "50"));
+
+        addAndCommit(binaryRow2);
+
+        HybridTimestamp lowWatermark = addAndCommit(null);
+
+        // Poll the oldest row.
+        BinaryRowWithRowId row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Poll the next oldest row.
+        row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), binaryRow2);
+
+        // Nothing else to poll.
+        assertNull(pollForVacuum(lowWatermark));
+    }
+}

Review Comment:
   Sure, I'm ok with `AbstractMvPartitionStorageConcurrencyTest`



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055227152


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testRegularGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+            addAndCommit(BINARY_ROW);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> read(ROW_ID, firstCommitTs),
+                    () -> scanFirstEntry(firstCommitTs)
+            );
+
+            assertNull(pollForVacuum(HybridTimestamp.MAX_VALUE));
+
+            cleanup();
+        }
+    }
+
+    @Test
+    void testTombstoneGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+            addAndCommit(null);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> read(ROW_ID, firstCommitTs),
+                    () -> scanFirstEntry(firstCommitTs)
+            );
+
+            assertNull(pollForVacuum(HybridTimestamp.MAX_VALUE));
+        }
+    }
+
+    @Test
+    void testTombstoneGcAndAddWrite() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            addAndCommit(BINARY_ROW);
+
+            addAndCommit(null);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID)

Review Comment:
   Not necessarily, we don't compare them anyway, because that's too wasteful



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056086777


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/BaseMvPartitionStorageTest.java:
##########
@@ -47,9 +47,9 @@ public abstract class BaseMvPartitionStorageTest extends BaseMvStoragesTest {
 
     protected static final TestKey KEY = new TestKey(10, "foo");
 
-    protected static final TestValue VALUE = new TestValue(20, "bar");
+    protected static final BinaryRow BINARY_ROW = binaryRow(KEY, new TestValue(20, "bar"));
 
-    protected static final BinaryRow BINARY_ROW = binaryRow(KEY, VALUE);
+    protected static final BinaryRow BINARY_ROW2 = binaryRow(KEY, new TestValue(20, "bar"));

Review Comment:
   It looks like the values of `BINARY_ROW` and `BINARY_ROW2` are identical. They should probably be different.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056198696


##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,57 @@ public static <T> T await(CompletionStage<T> stage, long timeout, TimeUnit unit)
     public static <T> T await(CompletionStage<T> stage) {
         return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
     }
+
+    /**
+     * {@link #runRace(long, RunnableX...)} with default timeout of 10 seconds.
+     */
+    public static void runRace(RunnableX... actions) {
+        runRace(TimeUnit.SECONDS.toMillis(10), actions);
+    }
+
+    /**
+     * Runs all actions, each in a separate thread, having a {@link CyclicBarrier} before calling {@link RunnableX#run()}.
+     * Waits for threads completion or fails with the assertion if timeout exceeded.
+     */
+    public static void runRace(long timeoutMillis, RunnableX... actions) {
+        int length = actions.length;
+
+        CyclicBarrier barrier = new CyclicBarrier(length);
+
+        Set<Throwable> throwables = ConcurrentHashMap.newKeySet();
+
+        Thread[] threads = IntStream.range(0, length).mapToObj(i -> new Thread(() -> {
+            try {
+                barrier.await();
+
+                actions[i].run();
+            } catch (Throwable e) {
+                throwables.add(e);
+            }
+        })).toArray(Thread[]::new);
+
+        Stream.of(threads).forEach(Thread::start);
+
+        try {
+            for (Thread thread : threads) {
+                thread.join(timeoutMillis);
+            }
+        } catch (InterruptedException e) {
+            for (Thread thread : threads) {
+                thread.interrupt();
+            }
+
+            fail("Race operations took too long.");
+        }
+
+        if (!throwables.isEmpty()) {
+            AssertionError assertionError = new AssertionError("One or several threads have failed.");

Review Comment:
   Ok



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055239122


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   You know what, gcQueue is defined with a custom comparator, right? I guess equality is not an issue and hashCode is never called, so writing to the queue several times should be fine.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055224102


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),

Review Comment:
   That would be a different scenario, right? Here I specifically want to update existing write intent.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
tkalkirill commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056168633


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate due to recreating the storage every time. */
+    private static final int REPEATS = 100;

Review Comment:
   Maybe use **org.junit.jupiter.api.RepeatedTest**?



##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/BinaryRowAndRowId.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.ignite.internal.storage;
+
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper that holds both {@link BinaryRow} and {@link RowId}. {@link BinaryRow} is null for tombstones.
+ */
+public class BinaryRowAndRowId {
+    /** Binary row. */
+    private final @Nullable BinaryRow binaryRow;
+
+    /** Row id. */
+    private final RowId rowId;
+
+    /**
+     * Constructor.
+     *
+     * @param binaryRow Binary row.
+     * @param rowId Row id.
+     */
+    public BinaryRowAndRowId(@Nullable BinaryRow binaryRow, RowId rowId) {
+        this.binaryRow = binaryRow;
+        this.rowId = rowId;
+    }
+
+    public BinaryRow binaryRow() {

Review Comment:
   ```suggestion
       public @Nullable BinaryRow binaryRow() {
   ```



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,57 @@ public static <T> T await(CompletionStage<T> stage, long timeout, TimeUnit unit)
     public static <T> T await(CompletionStage<T> stage) {
         return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
     }
+
+    /**
+     * {@link #runRace(long, RunnableX...)} with default timeout of 10 seconds.
+     */
+    public static void runRace(RunnableX... actions) {
+        runRace(TimeUnit.SECONDS.toMillis(10), actions);
+    }
+
+    /**
+     * Runs all actions, each in a separate thread, having a {@link CyclicBarrier} before calling {@link RunnableX#run()}.
+     * Waits for threads completion or fails with the assertion if timeout exceeded.
+     */
+    public static void runRace(long timeoutMillis, RunnableX... actions) {
+        int length = actions.length;
+
+        CyclicBarrier barrier = new CyclicBarrier(length);
+
+        Set<Throwable> throwables = ConcurrentHashMap.newKeySet();
+
+        Thread[] threads = IntStream.range(0, length).mapToObj(i -> new Thread(() -> {
+            try {
+                barrier.await();
+
+                actions[i].run();
+            } catch (Throwable e) {
+                throwables.add(e);
+            }
+        })).toArray(Thread[]::new);
+
+        Stream.of(threads).forEach(Thread::start);
+
+        try {
+            for (Thread thread : threads) {
+                thread.join(timeoutMillis);
+            }
+        } catch (InterruptedException e) {
+            for (Thread thread : threads) {
+                thread.interrupt();
+            }
+
+            fail("Race operations took too long.");
+        }
+
+        if (!throwables.isEmpty()) {
+            AssertionError assertionError = new AssertionError("One or several threads have failed.");

Review Comment:
   Nothing is said in the documentation.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055229704


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   My bad, I'll fix it. Queue should be concurrent as well, I forgot to do it



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055224102


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),

Review Comment:
   That would be a different scenario, right? Here I specifically want to update existing write intent.
   Operations with other row ids don't bother me, because there are no reasons to worry about them



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056199594


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate due to recreating the storage every time. */
+    private static final int REPEATS = 100;

Review Comment:
   I explicitly said that it has smaller fail rate, which is bad for such tests.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055368992


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),

Review Comment:
   Ah, ok, I see



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055232273


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);
+
+        // Data is still visible for older timestamps.
+        assertNull(storage.pollForVacuum(firstCommitTs));
+
+        assertNull(storage.pollForVacuum(tsBetweenCommits));
+
+        // Once a low watermark value becomes equal to second commit timestamp, previous value
+        // becomes completely inaccessible and should be purged.
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Read from the old timestamp should return null.
+        assertNull(read(ROW_ID, firstCommitTs));
+
+        // Read from the newer timestamp should return last value.
+        assertRowMatches(read(ROW_ID, secondCommitTs), BINARY_ROW);
+    }
+
+    @Test
+    void testPollFromUnderTombstone() {
+        addAndCommit(BINARY_ROW);
+        HybridTimestamp secondCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, secondCommitTs));
+
+        // Check that tombstone is also deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testDoubleTombstone() {
+        addAndCommit(BINARY_ROW);
+        addAndCommit(null);
+        HybridTimestamp lastCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(lastCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, lastCommitTs));
+
+        // Check that all tombstones are deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testManyOldVersions() {
+        addAndCommit(BINARY_ROW);
+
+        BinaryRow binaryRow2 = binaryRow(KEY, new TestValue(50, "50"));
+
+        addAndCommit(binaryRow2);
+
+        HybridTimestamp lowWatermark = addAndCommit(null);
+
+        // Poll the oldest row.
+        BinaryRowWithRowId row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Poll the next oldest row.
+        row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), binaryRow2);
+
+        // Nothing else to poll.
+        assertNull(pollForVacuum(lowWatermark));
+    }
+}

Review Comment:
   I should add more scenarios to AbstractMvPartitionStorageConcurrencyTest, is this what you mean? Yeah, I guess so, let's be paranoid, I like that



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055229704


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   My bad, I'll fix it



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1054362896


##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/BinaryRowWithRowId.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.ignite.internal.storage;
+
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper that holds both {@link BinaryRow} and {@link RowId}.

Review Comment:
   Should it be noted that it *might* hold a binary row, but it also might be missing?



##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/MvPartitionStorage.java:
##########
@@ -209,6 +209,17 @@ public interface MvPartitionStorage extends ManuallyCloseable {
      */
     @Nullable RowId closestRowId(RowId lowerBound) throws StorageException;
 
+    /**
+     * Polls an oldest row in the partition, removing it at the same time.

Review Comment:
   ```suggestion
        * Polls the oldest row in the partition, removing it at the same time.
   ```



##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/BinaryRowWithRowId.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.ignite.internal.storage;
+
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper that holds both {@link BinaryRow} and {@link RowId}.
+ */
+public class BinaryRowWithRowId {

Review Comment:
   `BinaryRowWithRowId` makes me think that it is a binary row itself, but here it isn't (as it does not extend it, it has it as a part of it). `BinaryRowAndRowId` does not seem to cause this feeling.
   
   Extremely optional.



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),

Review Comment:
   Let's make this write another row, not the same row that was written before, so we can distinguish the 'it was updated' case from 'it was not updated' case



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */

Review Comment:
   Probably because with `@RepeatedTest` a brand new storage instance is created?



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testRegularGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+            addAndCommit(BINARY_ROW);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> read(ROW_ID, firstCommitTs),
+                    () -> scanFirstEntry(firstCommitTs)
+            );
+
+            assertNull(pollForVacuum(HybridTimestamp.MAX_VALUE));
+
+            cleanup();
+        }
+    }
+
+    @Test
+    void testTombstoneGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+            addAndCommit(null);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> read(ROW_ID, firstCommitTs),
+                    () -> scanFirstEntry(firstCommitTs)
+            );
+
+            assertNull(pollForVacuum(HybridTimestamp.MAX_VALUE));
+        }
+    }
+
+    @Test
+    void testTombstoneGcAndAddWrite() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);
+
+        for (int i = 0; i < REPEATS; i++) {
+            addAndCommit(BINARY_ROW);
+
+            addAndCommit(null);
+
+            startRace(
+                    () -> pollForVacuum(HybridTimestamp.MAX_VALUE),
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID)

Review Comment:
   Should this row be different from the first one?



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);
+
+        // Data is still visible for older timestamps.
+        assertNull(storage.pollForVacuum(firstCommitTs));
+
+        assertNull(storage.pollForVacuum(tsBetweenCommits));
+
+        // Once a low watermark value becomes equal to second commit timestamp, previous value
+        // becomes completely inaccessible and should be purged.
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Read from the old timestamp should return null.
+        assertNull(read(ROW_ID, firstCommitTs));
+
+        // Read from the newer timestamp should return last value.
+        assertRowMatches(read(ROW_ID, secondCommitTs), BINARY_ROW);
+    }
+
+    @Test
+    void testPollFromUnderTombstone() {
+        addAndCommit(BINARY_ROW);
+        HybridTimestamp secondCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, secondCommitTs));
+
+        // Check that tombstone is also deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testDoubleTombstone() {
+        addAndCommit(BINARY_ROW);
+        addAndCommit(null);
+        HybridTimestamp lastCommitTs = addAndCommit(null);
+
+        BinaryRowWithRowId row = storage.pollForVacuum(lastCommitTs);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        assertNull(read(ROW_ID, lastCommitTs));
+
+        // Check that all tombstones are deleted from the partition. It must be empty at this point.
+        assertNull(storage.closestRowId(ROW_ID));
+    }
+
+    @Test
+    void testManyOldVersions() {
+        addAndCommit(BINARY_ROW);
+
+        BinaryRow binaryRow2 = binaryRow(KEY, new TestValue(50, "50"));
+
+        addAndCommit(binaryRow2);
+
+        HybridTimestamp lowWatermark = addAndCommit(null);
+
+        // Poll the oldest row.
+        BinaryRowWithRowId row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), BINARY_ROW);
+
+        // Poll the next oldest row.
+        row = pollForVacuum(lowWatermark);
+
+        assertNotNull(row);
+        assertRowMatches(row.binaryRow(), binaryRow2);
+
+        // Nothing else to poll.
+        assertNull(pollForVacuum(lowWatermark));
+    }
+}

Review Comment:
   Let's add a test (or a few) that models the real threading model that will be used in production code: one thread modifies the storage, another one acts as a GC. This might help catch visibility bugs (if, for some reason, `pollForVacuum()` never sees changes made by other methods).



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   Also, access to `gcQueue` is not synchronized explicitly. `ConcurrentMap` guarantees happens-before between actions with the map and actions around these actions (before or after them in the Program Order), but does it make any guarantees about what happens inside remapping functions? Documentation on `ConcurrentSkipListMap#compute()` specifically says that it does NOT guarantee atomicity for remapping functions.



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,43 @@ public static <T> T await(CompletionStage<T> stage, long timeout, TimeUnit unit)
     public static <T> T await(CompletionStage<T> stage) {
         return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
     }
+
+    /**
+     * Runs all actions, each in a separate thread, having a {@link CyclicBarrier} before calling {@link RunnableX#run()}.
+     *
+     * @throws InterruptedException If failed to {@link Thread#join()} a thread.

Review Comment:
   ```suggestion
        * @throws InterruptedException If interrupted when trying to {@link Thread#join()} a thread.
   ```



##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,43 @@ public static <T> T await(CompletionStage<T> stage, long timeout, TimeUnit unit)
     public static <T> T await(CompletionStage<T> stage) {
         return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
     }
+
+    /**
+     * Runs all actions, each in a separate thread, having a {@link CyclicBarrier} before calling {@link RunnableX#run()}.
+     *
+     * @throws InterruptedException If failed to {@link Thread#join()} a thread.
+     */
+    public static void startRace(RunnableX... actions) throws InterruptedException {

Review Comment:
   `start` makes me think that it just starts the threads, but does not wait for them to finish. But here, the method is fully synchronous as it joins the threads. How about `runRace()`?



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);

Review Comment:
   Let's use a row with a different value to be able to differentiate the values



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testRegularGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);

Review Comment:
   Why do we need this assertion? On an engine where GC is not implemented the corresponding exception will demonstrate clearly why this test has failed.



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)

Review Comment:
   Why is it needed here?



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageGcTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Abstract test for MV partition storage GC.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractMvPartitionStorageGcTest extends BaseMvPartitionStorageTest {
+    @Test
+    void testEmptyStorage() {
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testSingleValueStorage() {
+        addAndCommit(BINARY_ROW);
+
+        assertNull(storage.pollForVacuum(clock.now()));
+    }
+
+    @Test
+    void testRegularPoll() {
+        HybridTimestamp firstCommitTs = addAndCommit(BINARY_ROW);
+
+        HybridTimestamp tsBetweenCommits = clock.now();
+
+        HybridTimestamp secondCommitTs = addAndCommit(BINARY_ROW);
+
+        // Data is still visible for older timestamps.
+        assertNull(storage.pollForVacuum(firstCommitTs));
+
+        assertNull(storage.pollForVacuum(tsBetweenCommits));
+
+        // Once a low watermark value becomes equal to second commit timestamp, previous value
+        // becomes completely inaccessible and should be purged.
+        BinaryRowWithRowId row = storage.pollForVacuum(secondCommitTs);

Review Comment:
   ```suggestion
           BinaryRowWithRowId gcedRow = storage.pollForVacuum(secondCommitTs);
   ```



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -426,6 +448,51 @@ public ReadResult next() {
         return map.ceilingKey(lowerBound);
     }
 
+    @Override
+    public @Nullable BinaryRowWithRowId pollForVacuum(HybridTimestamp lowWatermark) {
+        Iterator<IgniteBiTuple<VersionChain, RowId>> it = gcQueue.iterator();

Review Comment:
   No synchronization whatsoever. How about changing `gcQueue` to `ConcurrentSkipListSet`?



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {

Review Comment:
   Shouldn't the storage be cleaned between iterations? Otherwise, more and more versions of the row are added. Is this ok?
   
   The same question also probably concerns other tests.



##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   `ConcurrentSkipListMap#compute()` may invoke the remapping function more than once due to concurrency. Here, the remapping function has a side effect (addition to the queue). It seems that it can result in multiple insertion to the queue. `VersionChain` does not define `equals()/hashCode()`, so this will really result in a chain being stored twice in the GC queue.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055225784


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */
+    private static final int REPEATS = 100;
+
+    @Test
+    void testAbortAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> abortWrite(ROW_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertNull(read(ROW_ID, clock.now()));
+        }
+    }
+
+    @Test
+    void testCommitAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> commitWrite(ROW_ID, clock.now()),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testUpdateAndRead() throws Exception {
+        for (int i = 0; i < REPEATS; i++) {
+            addWrite(ROW_ID, BINARY_ROW, TX_ID);
+
+            startRace(
+                    () -> addWrite(ROW_ID, BINARY_ROW, TX_ID),
+                    () -> read(ROW_ID, clock.now()),
+                    () -> scanFirstEntry(clock.now())
+            );
+
+            assertRowMatches(read(ROW_ID, clock.now()), BINARY_ROW);
+        }
+    }
+
+    @Test
+    void testRegularGcAndRead() throws Exception {
+        //TODO https://issues.apache.org/jira/browse/IGNITE-18020
+        assumeTrue(engine instanceof TestStorageEngine);

Review Comment:
   I don't want it to fail on TC, and overriding it with disabling would mean that these tests must be protected, not package-private, like the rest of them, I didn't want them to be different.
   I can replace it with overrides if you would like it more



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055225963


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageConcurrencyTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.ignite.internal.storage;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.startRace;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.impl.TestStorageEngine;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test to check for race conditions in MV partition storage.
+ */
+public abstract class AbstractMvPartitionStorageConcurrencyTest extends BaseMvPartitionStorageTest {
+    /** To be used in a loop. {@link RepeatedTest} has a smaller failure rate for some reasons. */

Review Comment:
   Yeah, probably



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1055230821


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -426,6 +448,51 @@ public ReadResult next() {
         return map.ceilingKey(lowerBound);
     }
 
+    @Override
+    public @Nullable BinaryRowWithRowId pollForVacuum(HybridTimestamp lowWatermark) {
+        Iterator<IgniteBiTuple<VersionChain, RowId>> it = gcQueue.iterator();

Review Comment:
   Sure, thank you!



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1464: IGNITE-18019 GC methods in MvPartitionStorage & new tests & old tests reorganization.

Posted by GitBox <gi...@apache.org>.
ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056114999


##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java:
##########
@@ -204,7 +215,18 @@ public void commitWrite(RowId rowId, HybridTimestamp timestamp) {
                 return versionChain;
             }
 
-            return VersionChain.forCommitted(timestamp, versionChain);
+            VersionChain committedVersionChain = VersionChain.forCommitted(timestamp, versionChain);
+
+            if (committedVersionChain.next != null) {
+                // Avoid creating tombstones for tombstones.
+                if (committedVersionChain.row == null && committedVersionChain.next.row == null) {
+                    return committedVersionChain.next;
+                }
+
+                gcQueue.add(new IgniteBiTuple<>(committedVersionChain, rowId));

Review Comment:
   > We now have 2 identical entries in the GC queue.
   
   There can be no duplicates in the queue. Anyway, I think I found a different example where the map itself can break regardless of the queue.
   
   > Why don't we just add synchronization to make sure it behaves as predictable as possible?
   
   I think I will



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org