sashapolo commented on code in PR #7273:
URL: https://github.com/apache/ignite-3/pull/7273#discussion_r2635051730
##########
modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItIndexBuildCompletenessTest.java:
##########
@@ -100,7 +98,7 @@ void
raceBetweenIndexBuildAndWriteFromDeadCoordinatorDoesNotCauseIndexIncomplete
for (int i = 0; i < transactions.size(); i++) {
Transaction tx = transactions.get(i);
try {
- kvView.put(tx, i, 11);
+ kvView.put(tx, i, 42);
Review Comment:
why did this line change?
##########
modules/index/src/test/java/org/apache/ignite/internal/index/IndexBuildControllerTest.java:
##########
@@ -112,13 +117,26 @@ void setUp() {
catalogManager = createCatalogManagerWithTestUpdateLog(NODE_NAME,
clock);
assertThat(catalogManager.startAsync(new ComponentContext()),
willCompleteSuccessfully());
+ PartitionReplicaLifecycleManager partitionReplicaLifecycleManager =
mock(PartitionReplicaLifecycleManager.class);
+ ZonePartitionResources zonePartitionResources =
mock(ZonePartitionResources.class);
+
doReturn(zonePartitionResources).when(partitionReplicaLifecycleManager).zonePartitionResourcesOrNull(any());
+
+ ZonePartitionReplicaListener replicaListener =
mock(ZonePartitionReplicaListener.class);
+
doReturn(completedFuture(replicaListener)).when(zonePartitionResources).replicaListenerFuture();
+
+ TableTxRwOperationTracker txRwOperationTracker =
mock(TableTxRwOperationTracker.class);
+ //noinspection unchecked
+ PendingComparableValuesTracker<HybridTimestamp, Void> safeTime =
mock(PendingComparableValuesTracker.class);
Review Comment:
I would suggest to inject the mocks using the `@Mock` annotation in order to
avoid the "unchecked" problem, but that's not a big deal
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java:
##########
@@ -296,7 +311,7 @@ private CompletableFuture<BatchToIndex>
createBatchToIndex(@Nullable RowId highe
assert transactionId != null;
// We only care about transactions which began after index
creation.
- if
(TransactionIds.beginTimestamp(transactionId).compareTo(indexCreationActivationTs)
< 0) {
+ if
(TransactionIds.beginTimestamp(transactionId).compareTo(hybridTimestamp(indexCreationInfo.activationTimestamp()))
< 0) {
Review Comment:
Please introduce some intermediate variables
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildController.java:
##########
@@ -435,23 +458,63 @@ private void scheduleBuildIndexAfterDisasterRecovery(
MvTableStorage mvTableStorage,
long enlistmentConsistencyToken
) {
+ ZonePartitionId zonePartitionId = new ZonePartitionId(zoneId,
partitionId);
+ ZonePartitionResources resources =
partitionReplicaLifecycleManager.zonePartitionResourcesOrNull(zonePartitionId);
+ if (resources == null) {
+ // Already stopped/destroyed, ignore.
+ return;
+ }
+
MvPartitionStorage mvPartition = mvPartitionStorage(mvTableStorage,
zoneId, tableId, partitionId);
IndexStorage indexStorage = indexStorage(mvTableStorage, partitionId,
indexDescriptor);
+ @Nullable ReplicaTableSegment segment =
replicaTableSegment(zonePartitionId, tableId, resources, indexDescriptor);
+ if (segment == null) {
+ return;
+ }
+
indexBuilder.scheduleBuildIndexAfterDisasterRecovery(
zoneId,
tableId,
partitionId,
indexDescriptor.id(),
indexStorage,
mvPartition,
+ segment.txRwOperationTracker(),
+ segment.safeTime(),
localNode(),
enlistmentConsistencyToken,
clockService.current()
);
}
+ private static @Nullable ReplicaTableSegment replicaTableSegment(
+ ZonePartitionId zonePartitionId,
+ int tableId,
+ ZonePartitionResources resources,
+ CatalogIndexDescriptor indexDescriptor
+ ) {
+ CompletableFuture<ZonePartitionReplicaListener> replicaListenerFuture
= resources.replicaListenerFuture();
+ assert replicaListenerFuture.isDone() : "Replica listener future is
not done for [zonePartitionId=" + zonePartitionId + "].";
+
+ ZonePartitionReplicaListener replicaListener =
replicaListenerFuture.join();
+ @Nullable ReplicaTableSegment segment =
replicaListener.segmentFor(tableId);
Review Comment:
It's strange that you use `@Nullable` here all of a sudden
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildController.java:
##########
@@ -435,23 +458,63 @@ private void scheduleBuildIndexAfterDisasterRecovery(
MvTableStorage mvTableStorage,
long enlistmentConsistencyToken
) {
+ ZonePartitionId zonePartitionId = new ZonePartitionId(zoneId,
partitionId);
+ ZonePartitionResources resources =
partitionReplicaLifecycleManager.zonePartitionResourcesOrNull(zonePartitionId);
+ if (resources == null) {
+ // Already stopped/destroyed, ignore.
+ return;
+ }
+
MvPartitionStorage mvPartition = mvPartitionStorage(mvTableStorage,
zoneId, tableId, partitionId);
IndexStorage indexStorage = indexStorage(mvTableStorage, partitionId,
indexDescriptor);
+ @Nullable ReplicaTableSegment segment =
replicaTableSegment(zonePartitionId, tableId, resources, indexDescriptor);
+ if (segment == null) {
+ return;
+ }
+
indexBuilder.scheduleBuildIndexAfterDisasterRecovery(
zoneId,
tableId,
partitionId,
indexDescriptor.id(),
indexStorage,
mvPartition,
+ segment.txRwOperationTracker(),
+ segment.safeTime(),
localNode(),
enlistmentConsistencyToken,
clockService.current()
);
}
+ private static @Nullable ReplicaTableSegment replicaTableSegment(
+ ZonePartitionId zonePartitionId,
+ int tableId,
+ ZonePartitionResources resources,
+ CatalogIndexDescriptor indexDescriptor
+ ) {
+ CompletableFuture<ZonePartitionReplicaListener> replicaListenerFuture
= resources.replicaListenerFuture();
+ assert replicaListenerFuture.isDone() : "Replica listener future is
not done for [zonePartitionId=" + zonePartitionId + "].";
+
+ ZonePartitionReplicaListener replicaListener =
replicaListenerFuture.join();
+ @Nullable ReplicaTableSegment segment =
replicaListener.segmentFor(tableId);
+
+ if (segment == null) {
Review Comment:
How can it be null? Could you please leave a comment about that?
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java:
##########
@@ -174,9 +188,10 @@ void start() {
}
try {
- statisticsLoggingListener.onIndexBuildStarted();
-
- supplyAsync(partitionStorage::highestRowId, executor)
+
txRwOperationTracker.awaitCompleteTxRwOperations(indexCreationInfo.catalogVersion())
Review Comment:
Please leave a comment about why we are waiting for all this stuff
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildController.java:
##########
@@ -409,17 +418,31 @@ private void scheduleBuildIndex(
long enlistmentConsistencyToken,
HybridTimestamp initialOperationTimestamp
) {
+ ZonePartitionId zonePartitionId = new ZonePartitionId(zoneId,
partitionId);
+ ZonePartitionResources resources =
partitionReplicaLifecycleManager.zonePartitionResourcesOrNull(zonePartitionId);
+ if (resources == null) {
+ // Already stopped/destroyed, ignore.
+ return;
+ }
+
MvPartitionStorage mvPartition = mvPartitionStorage(mvTableStorage,
zoneId, tableId, partitionId);
IndexStorage indexStorage = indexStorage(mvTableStorage, partitionId,
indexDescriptor);
+ @Nullable ReplicaTableSegment segment =
replicaTableSegment(zonePartitionId, tableId, resources, indexDescriptor);
Review Comment:
Minor nitpick, but it makes sense to move this code before you retrieve the
storages
##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java:
##########
@@ -80,14 +83,19 @@ class IndexBuildTask {
private final IndexBuildTaskId taskId;
- private final HybridTimestamp indexCreationActivationTs;
+ private final MetaIndexStatusChange indexCreationInfo;
Review Comment:
```suggestion
private final MetaIndexStatusChange indexCreationInfo;
```
##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableTxRwOperationTracker.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.partition.replicator;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Tracks the completion of RW transactions' operations before a dependent
process begins.
+ */
+public interface TableTxRwOperationTracker {
+ /**
+ * Waits for RW transactions operations to complete strictly lower than
the requested version.
Review Comment:
```suggestion
* Waits for RW transactions operations to complete strictly lower than
the requested catalog version.
```
##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ReplicaTableProcessor.java:
##########
@@ -38,4 +40,11 @@ public interface ReplicaTableProcessor {
/** Callback on replica shutdown. */
void onShutdown();
+
+ /** Returns tracker of RW transactions operations. */
+ TableTxRwOperationTracker txRwOperationTracker();
+
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-27405 as safe time
should not depend on the table.
Review Comment:
Would be nice to fix IGNITE-27405 first, as looks like it is not a big task
and will reduce the amount of code in this PR
--
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]