tkalkirill commented on code in PR #3399:
URL: https://github.com/apache/ignite-3/pull/3399#discussion_r1523383359
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/PageMemoryIndexes.java:
##########
@@ -105,8 +109,17 @@ void performRecovery(
StorageIndexDescriptor indexDescriptor =
indexDescriptorSupplier.get(indexId);
if (indexDescriptor == null) {
- // TODO: IGNITE-21671 destroy the index if it can't be
found in the Catalog.
- continue;
+ // Index has not been found in the Catalog, we can treat
it as destroyed and remove the storage.
+ runConsistently.accept(locker -> {
+ destroyIndexOnRecovery(indexMeta, indexStorageFactory,
indexMetaTree)
+ .whenComplete((v, e) -> {
+ if (e != null) {
+ LOG.error("Unable to destroy existing
index that has been removed from the Catalog", e);
Review Comment:
Let's indicate which index could not be deleted.
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/meta/IndexMeta.java:
##########
@@ -27,6 +27,37 @@
* Index meta information.
*/
public class IndexMeta extends IndexMetaKey {
+ /** Index type. */
+ public enum IndexType {
Review Comment:
Maybe separate class file?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/CatalogStorageIndexDescriptorSupplier.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.storage.index.StorageIndexDescriptor;
+import org.apache.ignite.internal.storage.index.StorageIndexDescriptorSupplier;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Index descriptor supplier from catalog.
+ */
+class CatalogStorageIndexDescriptorSupplier implements
StorageIndexDescriptorSupplier {
+ private final CatalogService catalogService;
+
+ private final LowWatermark lowWatermark;
+
+ CatalogStorageIndexDescriptorSupplier(CatalogService catalogService,
LowWatermark lowWatermark) {
+ this.catalogService = catalogService;
+ this.lowWatermark = lowWatermark;
+ }
+
+ @Override
+ public @Nullable StorageIndexDescriptor get(int indexId) {
+ // Search for the index in the catalog history, which versions
correspond to (lowWatermark, now] timestamp range.
+ int latestCatalogVersion = catalogService.latestCatalogVersion();
+
+ HybridTimestamp lowWatermarkTimestamp = lowWatermark.getLowWatermark();
Review Comment:
I think there may be a race here, as soon as we read the lwm it can
immediately change and the index should already begin to be destroyed, I think
this can be repaired by a consumer who will give the lwm and will not change it
while you are working with it.
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/PageMemoryIndexes.java:
##########
@@ -124,6 +137,27 @@ void performRecovery(
}
}
+ private CompletableFuture<Void> destroyIndexOnRecovery(
+ IndexMeta indexMeta,
+ IndexStorageFactory indexStorageFactory,
+ IndexMetaTree indexMetaTree
+ ) {
+ switch (indexMeta.indexType()) {
+ case HASH:
+ PageMemoryHashIndexStorage hashIndexStorage =
indexStorageFactory.restoreHashIndexStorageForDestroy(indexMeta);
+
+ return destroyStorage(indexMeta.indexId(), hashIndexStorage,
indexMetaTree);
+
+ case SORTED:
+ PageMemorySortedIndexStorage sortedIndexStorage =
indexStorageFactory.restoreSortedIndexStorageForDestroy(indexMeta);
+
+ return destroyStorage(indexMeta.indexId(), sortedIndexStorage,
indexMetaTree);
+
+ default:
+ throw new AssertionError("Unexpected index type: " +
indexMeta.indexType());
Review Comment:
Let's indicate which index.
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvTableStorageTest.java:
##########
@@ -760,6 +801,41 @@ void testNextRowIdToBuiltAfterRestart() throws Exception {
}
}
+ @Test
+ public void testIndexDestructionOnRecovery() throws Exception {
+ Assumptions.assumeFalse(tableStorage.isVolatile(), "Volatile storages
do not support index recovery");
Review Comment:
Maybe static import?
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvTableStorageTest.java:
##########
@@ -113,7 +114,40 @@ public abstract class AbstractMvTableStorageTest extends
BaseMvStoragesTest {
protected StorageHashIndexDescriptor hashIdx;
- protected final CatalogService catalogService = mock(CatalogService.class);
+ private final CatalogService catalogService = mock(CatalogService.class);
+
+ protected final StorageIndexDescriptorSupplier indexDescriptorSupplier =
new StorageIndexDescriptorSupplier() {
+ @Override
+ public @Nullable StorageIndexDescriptor get(int indexId) {
+ int catalogVersion = catalogService.latestCatalogVersion();
+
+ CatalogIndexDescriptor indexDescriptor =
catalogService.index(indexId, catalogVersion);
+
+ if (indexDescriptor == null) {
+ return null;
+ }
+
+ CatalogTableDescriptor tableDescriptor =
catalogService.table(indexDescriptor.tableId(), catalogVersion);
+
+ assertThat(tableDescriptor, is(notNullValue()));
+
+ return StorageIndexDescriptor.create(tableDescriptor,
indexDescriptor);
+ }
+ };
+
+ private class TestRow {
Review Comment:
Meow
--
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]