rpuch commented on code in PR #1578:
URL: https://github.com/apache/ignite-3/pull/1578#discussion_r1088638782
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvTableStorageTest.java:
##########
@@ -632,10 +627,76 @@ public void testRestartStoragesAfterFailDuringRebalance()
{
hashIndexStorage = tableStorage.getOrCreateHashIndex(PARTITION_ID,
hashIdx.id());
sortedIndexStorage = tableStorage.getOrCreateSortedIndex(PARTITION_ID,
sortedIdx.id());
- // Let's check the repositories: they should be empty.
- checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+ if (tableStorage.isVolatile()) {
+ // Let's check the repositories: they should be empty.
+ checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+
+ checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ } else {
+ checkForPresenceRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+
+ checkLastApplied(mvPartitionStorage, REBALANCE_IN_PROGRESS,
REBALANCE_IN_PROGRESS, REBALANCE_IN_PROGRESS);
+ }
+ }
+
+ @Test
+ void testClear() {
+ assertThrows(IllegalArgumentException.class, () ->
tableStorage.clearPartition(getPartitionIdOutOfRange()));
+
+ // Let's check that there will be an error for a non-existent
partition.
+ assertThrows(StorageException.class, () ->
tableStorage.clearPartition(PARTITION_ID));
+
+ MvPartitionStorage mvPartitionStorage =
tableStorage.getOrCreateMvPartition(PARTITION_ID);
+ HashIndexStorage hashIndexStorage =
tableStorage.getOrCreateHashIndex(PARTITION_ID, hashIdx.id());
+ SortedIndexStorage sortedIndexStorage =
tableStorage.getOrCreateSortedIndex(PARTITION_ID, sortedIdx.id());
+
+ // Let's check the cleanup for an empty partition.
+ assertThat(tableStorage.clearPartition(PARTITION_ID),
willCompleteSuccessfully());
+
+ checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ assertNull(mvPartitionStorage.committedGroupConfiguration());
+
+ // Let's fill the storages and clean them.
+ List<IgniteTuple3<RowId, TableRow, HybridTimestamp>> rows = List.of(
+ new IgniteTuple3<>(new RowId(PARTITION_ID), tableRow(new
TestKey(0, "0"), new TestValue(0, "0")), clock.now()),
+ new IgniteTuple3<>(new RowId(PARTITION_ID), tableRow(new
TestKey(1, "1"), new TestValue(1, "1")), clock.now())
+ );
+
+ RaftGroupConfiguration raftGroupConfig =
createRandomRaftGroupConfiguration();
+
+ fillStorages(mvPartitionStorage, hashIndexStorage, sortedIndexStorage,
rows);
+
+ mvPartitionStorage.runConsistently(() -> {
+ mvPartitionStorage.lastApplied(100, 500);
+
+ mvPartitionStorage.committedGroupConfiguration(raftGroupConfig);
+
+ return null;
+ });
+
+ // Let's clear the storages and check them out.
+ assertThat(tableStorage.clearPartition(PARTITION_ID),
willCompleteSuccessfully());
checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ assertNull(mvPartitionStorage.committedGroupConfiguration());
+
+ checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+ }
+
Review Comment:
Cleaning is a complex process: we first raise a 'latch' to prevent any
normal operations, then we destroy data, switch the store to the 'empty state
and then we release the 'latch'. It seems easy to forget to release something
during this process, so it would be great to make sure that the storage is
actually in a fully useable state (nothing is forgotten).
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvTableStorageTest.java:
##########
@@ -632,10 +627,76 @@ public void testRestartStoragesAfterFailDuringRebalance()
{
hashIndexStorage = tableStorage.getOrCreateHashIndex(PARTITION_ID,
hashIdx.id());
sortedIndexStorage = tableStorage.getOrCreateSortedIndex(PARTITION_ID,
sortedIdx.id());
- // Let's check the repositories: they should be empty.
- checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+ if (tableStorage.isVolatile()) {
+ // Let's check the repositories: they should be empty.
+ checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+
+ checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ } else {
+ checkForPresenceRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+
+ checkLastApplied(mvPartitionStorage, REBALANCE_IN_PROGRESS,
REBALANCE_IN_PROGRESS, REBALANCE_IN_PROGRESS);
+ }
+ }
+
+ @Test
+ void testClear() {
+ assertThrows(IllegalArgumentException.class, () ->
tableStorage.clearPartition(getPartitionIdOutOfRange()));
+
+ // Let's check that there will be an error for a non-existent
partition.
+ assertThrows(StorageException.class, () ->
tableStorage.clearPartition(PARTITION_ID));
+
+ MvPartitionStorage mvPartitionStorage =
tableStorage.getOrCreateMvPartition(PARTITION_ID);
+ HashIndexStorage hashIndexStorage =
tableStorage.getOrCreateHashIndex(PARTITION_ID, hashIdx.id());
+ SortedIndexStorage sortedIndexStorage =
tableStorage.getOrCreateSortedIndex(PARTITION_ID, sortedIdx.id());
+
+ // Let's check the cleanup for an empty partition.
+ assertThat(tableStorage.clearPartition(PARTITION_ID),
willCompleteSuccessfully());
+
+ checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ assertNull(mvPartitionStorage.committedGroupConfiguration());
+
+ // Let's fill the storages and clean them.
+ List<IgniteTuple3<RowId, TableRow, HybridTimestamp>> rows = List.of(
+ new IgniteTuple3<>(new RowId(PARTITION_ID), tableRow(new
TestKey(0, "0"), new TestValue(0, "0")), clock.now()),
+ new IgniteTuple3<>(new RowId(PARTITION_ID), tableRow(new
TestKey(1, "1"), new TestValue(1, "1")), clock.now())
+ );
+
+ RaftGroupConfiguration raftGroupConfig =
createRandomRaftGroupConfiguration();
+
+ fillStorages(mvPartitionStorage, hashIndexStorage, sortedIndexStorage,
rows);
+
+ mvPartitionStorage.runConsistently(() -> {
+ mvPartitionStorage.lastApplied(100, 500);
+
+ mvPartitionStorage.committedGroupConfiguration(raftGroupConfig);
+
+ return null;
+ });
+
+ // Let's clear the storages and check them out.
+ assertThat(tableStorage.clearPartition(PARTITION_ID),
willCompleteSuccessfully());
checkLastApplied(mvPartitionStorage, 0, 0, 0);
+ assertNull(mvPartitionStorage.committedGroupConfiguration());
+
+ checkForMissingRows(mvPartitionStorage, hashIndexStorage,
sortedIndexStorage, rows);
+ }
+
Review Comment:
Do we have tests that make sure that:
1. Operations active to the moment we initiate a cleanup still finish
successfully
2. No operations are possible while the cleanup is under way
3. The storage is fully operable after it has been cleaned up (all
operations function correctly)
?
--
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]