This is an automated email from the ASF dual-hosted git repository.
rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 002f9688ea5 IGNITE-27001 Do not access catalog by WI's beginTs during
Raft snapshot installation (#6940)
002f9688ea5 is described below
commit 002f9688ea5ed36d7f5f0616fb4099cda5b47cda
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Wed Nov 12 11:03:21 2025 +0400
IGNITE-27001 Do not access catalog by WI's beginTs during Raft snapshot
installation (#6940)
---
.../table/distributed/index/IndexMeta.java | 17 ++++++++
.../snapshot/FullStateTransferIndexChooser.java | 12 +++---
.../table/distributed/index/IndexMetaTest.java | 45 ++++++++++++++++++++++
.../FullStateTransferIndexChooserTest.java | 32 ++++++++++++++-
4 files changed, 100 insertions(+), 6 deletions(-)
diff --git
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/index/IndexMeta.java
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/index/IndexMeta.java
index f14d8c44581..732c2b33fb4 100644
---
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/index/IndexMeta.java
+++
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/index/IndexMeta.java
@@ -18,9 +18,13 @@
package org.apache.ignite.internal.table.distributed.index;
import static java.util.Collections.unmodifiableMap;
+import static java.util.Collections.unmodifiableNavigableMap;
import java.util.EnumMap;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.TreeMap;
import org.apache.ignite.internal.catalog.Catalog;
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
@@ -45,6 +49,8 @@ public class IndexMeta {
@IgniteToStringInclude
private final Map<MetaIndexStatus, MetaIndexStatusChange> statusChanges;
+ private final NavigableMap<Long, MetaIndexStatus> statusActivationTimeline;
+
/**
* Constructor.
*
@@ -72,6 +78,12 @@ public class IndexMeta {
this.indexName = indexName;
this.currentStatus = currentStatus;
this.statusChanges = unmodifiableMap(statusChanges);
+
+ NavigableMap<Long, MetaIndexStatus> timeline = new TreeMap<>();
+ for (Entry<MetaIndexStatus, MetaIndexStatusChange> entry :
statusChanges.entrySet()) {
+ timeline.put(entry.getValue().activationTimestamp(),
entry.getKey());
+ }
+ this.statusActivationTimeline = unmodifiableNavigableMap(timeline);
}
/**
@@ -180,6 +192,11 @@ public class IndexMeta {
);
}
+ public @Nullable MetaIndexStatus statusAt(long timestamp) {
+ Entry<Long, MetaIndexStatus> floorEntry =
statusActivationTimeline.floorEntry(timestamp);
+ return floorEntry != null ? floorEntry.getValue() : null;
+ }
+
/** Returns a map of index statuses with change info (for example catalog
version) in which they appeared. */
public Map<MetaIndexStatus, MetaIndexStatusChange> statusChanges() {
return statusChanges;
diff --git
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooser.java
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooser.java
index 3e5d95b3448..90d3b4e4261 100644
---
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooser.java
+++
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooser.java
@@ -35,7 +35,6 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
-import org.apache.ignite.internal.catalog.Catalog;
import org.apache.ignite.internal.catalog.CatalogService;
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus;
@@ -121,13 +120,16 @@ public class FullStateTransferIndexChooser implements
ManuallyCloseable {
*/
public List<IndexIdAndTableVersion> chooseForAddWrite(int catalogVersion,
int tableId, HybridTimestamp beginTs) {
return inBusyLock(busyLock, () -> {
- Catalog catalog =
catalogService.activeCatalog(beginTs.longValue());
-
List<Integer> fromCatalog = chooseFromCatalogBusy(catalogVersion,
tableId, index -> {
if (index.status() == REGISTERED) {
- CatalogIndexDescriptor indexAtBeginTs =
catalog.index(index.id());
+ IndexMeta indexMeta =
indexMetaStorage.indexMeta(index.id());
+ if (indexMeta == null) {
+ // No index meta, allow the index to be used.
+ return true;
+ }
- return indexAtBeginTs != null && indexAtBeginTs.status()
== REGISTERED;
+ MetaIndexStatus statusAtTxBegin =
indexMeta.statusAt(beginTs.longValue());
+ return statusAtTxBegin == MetaIndexStatus.REGISTERED;
}
return true;
diff --git
a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/index/IndexMetaTest.java
b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/index/IndexMetaTest.java
new file mode 100644
index 00000000000..3956d3c73dc
--- /dev/null
+++
b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/index/IndexMetaTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.index;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+class IndexMetaTest {
+ @Test
+ void statusAtReturnsCorrespondingStatus() {
+ Map<MetaIndexStatus, MetaIndexStatusChange> statusChanges = Map.of(
+ MetaIndexStatus.REGISTERED, new MetaIndexStatusChange(1, 10),
+ MetaIndexStatus.BUILDING, new MetaIndexStatusChange(2, 20)
+ );
+ IndexMeta indexMeta = new IndexMeta(2, 1, 1, 1, "test",
MetaIndexStatus.BUILDING, statusChanges);
+
+ assertThat(indexMeta.statusAt(9), is(nullValue()));
+
+ assertThat(indexMeta.statusAt(10), is(MetaIndexStatus.REGISTERED));
+ assertThat(indexMeta.statusAt(11), is(MetaIndexStatus.REGISTERED));
+ assertThat(indexMeta.statusAt(19), is(MetaIndexStatus.REGISTERED));
+
+ assertThat(indexMeta.statusAt(20), is(MetaIndexStatus.BUILDING));
+ assertThat(indexMeta.statusAt(2000), is(MetaIndexStatus.BUILDING));
+ }
+}
diff --git
a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooserTest.java
b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooserTest.java
index c3ac389c215..77cb2f65d55 100644
---
a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooserTest.java
+++
b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/raft/snapshot/FullStateTransferIndexChooserTest.java
@@ -43,11 +43,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.spy;
import java.util.List;
import org.apache.ignite.internal.catalog.Catalog;
import org.apache.ignite.internal.catalog.CatalogCommand;
import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.CatalogNotFoundException;
import org.apache.ignite.internal.catalog.CatalogTestUtils;
import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnCommand;
import org.apache.ignite.internal.catalog.commands.ColumnParams;
@@ -99,7 +102,7 @@ public class FullStateTransferIndexChooserTest extends
BaseIgniteAbstractTest {
void setUp() {
metaStorageManager = StandaloneMetaStorageManager.create(NODE_NAME,
clock);
- catalogManager =
CatalogTestUtils.createCatalogManagerWithTestUpdateLog(NODE_NAME, clock);
+ catalogManager =
spy(CatalogTestUtils.createCatalogManagerWithTestUpdateLog(NODE_NAME, clock));
indexMetaStorage = new IndexMetaStorage(catalogManager, lowWatermark,
metaStorageManager);
@@ -412,6 +415,33 @@ public class FullStateTransferIndexChooserTest extends
BaseIgniteAbstractTest {
assertThat(indexIds(chooseForAddWriteCommittedLatest()),
contains(pkIndexId, buildingIndexId));
}
+ @Test
+ void testWriteIntentWithTxBeginTsPointingAtMissingCatalogVersion() {
+ HybridTimestamp txBeginTs = HybridTimestamp.MIN_VALUE;
+
lenient().when(catalogManager.activeCatalog(txBeginTs.longValue())).thenThrow(new
CatalogNotFoundException("For testing purposes"));
+ lenient().when(catalogManager.catalog(0)).thenThrow(new
CatalogNotFoundException("For testing purposes"));
+
+ int pkIndexId = indexId(PK_INDEX_NAME);
+ assertThat(indexIds(chooseForAddWriteLatest(txBeginTs)),
contains(pkIndexId));
+
+ // Registered index will not be included as the transaction started
before its creation and hence there is a guarantee
+ // that the write intent will be considered by the index builder when
the build starts.
+ createSimpleRegisteredIndex(REGISTERED_INDEX_NAME);
+ assertThat(indexIds(chooseForAddWriteLatest(txBeginTs)),
contains(pkIndexId));
+
+ int buildingIndexId = createSimpleBuildingIndex(BUILDING_INDEX_NAME);
+ assertThat(indexIds(chooseForAddWriteLatest(txBeginTs)),
contains(pkIndexId, buildingIndexId));
+
+ int availableIndexId =
createSimpleAvailableIndex(AVAILABLE_INDEX_NAME);
+ assertThat(indexIds(chooseForAddWriteLatest(txBeginTs)),
contains(pkIndexId, buildingIndexId, availableIndexId));
+
+ int stoppingIndexId = createSimpleStoppingIndex(STOPPING_INDEX_NAME);
+ assertThat(
+ indexIds(chooseForAddWriteLatest(txBeginTs)),
+ contains(pkIndexId, buildingIndexId, availableIndexId,
stoppingIndexId)
+ );
+ }
+
private List<IndexIdAndTableVersion> chooseForAddWriteCommittedLatest(int
tableId, HybridTimestamp commitTs) {
return indexChooser.chooseForAddWriteCommitted(latestCatalogVersion(),
tableId, commitTs);
}