tkalkirill commented on code in PR #1716: URL: https://github.com/apache/ignite-3/pull/1716#discussion_r1118125232
########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/PartitionGcOnWriteTest.java: ########## @@ -0,0 +1,185 @@ +/* + * 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.table.distributed; + +import static java.util.Collections.singletonMap; +import static java.util.stream.Collectors.toList; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import org.apache.ignite.distributed.TestPartitionDataStorage; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.schema.BinaryRow; +import org.apache.ignite.internal.storage.BaseMvStoragesTest; +import org.apache.ignite.internal.storage.ReadResult; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.storage.impl.TestMvPartitionStorage; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.internal.util.Cursor; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +/** Tests for cooperative GC (GC that is executed on write). */ +public class PartitionGcOnWriteTest extends BaseMvStoragesTest { Review Comment: It would be necessary to add concurrent tests. ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java: ########## @@ -150,6 +202,25 @@ public void handleUpdateAll( }); } + private void executeBatchGc(@Nullable HybridTimestamp newLwm) { + if (newLwm != null) { + HybridTimestamp curLwm = lastRecordedLwm.updateAndGet(prevLwm -> { + if (prevLwm == null) { + return newLwm; + } + + return newLwm.compareTo(prevLwm) > 0 ? newLwm : prevLwm; + }); + + if (curLwm == newLwm) { Review Comment: Since method `java.util.concurrent.atomic.AtomicReference#updateAndGet` is not single CAS, I think that we will always perform `vacuumBatch`. Maybe if the new LWM is greater (make a single CAS) or equal to the recorded one, then perform the `vacuumBatch`, otherwise skip. ########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/PartitionGcOnWriteTest.java: ########## @@ -0,0 +1,185 @@ +/* + * 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.table.distributed; + +import static java.util.Collections.singletonMap; +import static java.util.stream.Collectors.toList; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import org.apache.ignite.distributed.TestPartitionDataStorage; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.schema.BinaryRow; +import org.apache.ignite.internal.storage.BaseMvStoragesTest; +import org.apache.ignite.internal.storage.ReadResult; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.storage.impl.TestMvPartitionStorage; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.internal.util.Cursor; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +/** Tests for cooperative GC (GC that is executed on write). */ +public class PartitionGcOnWriteTest extends BaseMvStoragesTest { + private static final int WRITES_COUNT = 10; + private static final UUID TX_ID = UUID.randomUUID(); + private static final int PARTITION_ID = 1; + private static final TablePartitionId TABLE_PARTITION_ID = new TablePartitionId(UUID.randomUUID(), PARTITION_ID); + + private TestMvPartitionStorage storage; + private StorageUpdateHandler storageUpdateHandler; + + @BeforeEach + void setUp() { + storage = new TestMvPartitionStorage(1); + + storageUpdateHandler = new StorageUpdateHandler(1, new TestPartitionDataStorage(storage), Collections::emptyMap); + } + + @ParameterizedTest + @EnumSource(AddWriteWithGc.class) + void testNullLwm(AddWriteWithGc writer) { + RowId rowId = fillWithDataForGc(); + + writeWithGc(writer, null); + + assertEquals(WRITES_COUNT, getRowVersions(rowId).size()); + } + + @ParameterizedTest + @EnumSource(AddWriteWithGc.class) + void testOlderLwm(AddWriteWithGc writer) { + HybridTimestamp older = clock.now(); + + HybridTimestamp newer = clock.now(); + + writeWithGc(writer, newer); + + RowId rowId = fillWithDataForGc(); + + writeWithGc(writer, older); + + assertEquals(WRITES_COUNT, getRowVersions(rowId).size()); + } + + @ParameterizedTest + @EnumSource(AddWriteWithGc.class) + void testNewerLwm(AddWriteWithGc writer) { + RowId rowId = fillWithDataForGc(); + + writeWithGc(writer, clock.now()); + + assertEquals(WRITES_COUNT - StorageUpdateHandler.GC_BATCH_SIZE, getRowVersions(rowId).size()); + } + + private List<ReadResult> getRowVersions(RowId rowId) { Review Comment: Maybe add a static method to `BaseMvStoragesTestMaybe`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
