rpuch commented on code in PR #6810:
URL: https://github.com/apache/ignite-3/pull/6810#discussion_r2448170418


##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java:
##########
@@ -236,27 +257,68 @@ private CompletableFuture<Void> handleNextBatch() {
         }
     }
 
-    private List<RowId> createBatchRowIds() {
+    private CompletableFuture<BatchToIndex> createBatchToIndex() {
         RowId nextRowIdToBuild = indexStorage.getNextRowIdToBuild();
 
-        List<RowId> batch = new ArrayList<>(batchSize);
+        List<RowId> rowIds = new ArrayList<>(batchSize);
+        Map<UUID, CommitPartitionId> transactionsToResolve = new HashMap<>();
 
-        for (int i = 0; i < batchSize && nextRowIdToBuild != null; i++) {
-            nextRowIdToBuild = partitionStorage.closestRowId(nextRowIdToBuild);
+        while (rowIds.size() < batchSize && nextRowIdToBuild != null) {
+            @Nullable RowMeta row = 
partitionStorage.closestRow(nextRowIdToBuild);
 
-            if (nextRowIdToBuild == null) {
+            if (row == null) {
                 break;
             }
 
-            batch.add(nextRowIdToBuild);
+            rowIds.add(row.rowId());
+
+            if (row.isWriteIntent()) {
+                UUID transactionId = row.transactionId();
+                assert transactionId != null;
+
+                // We only care about transactions which began after index 
creation.
+                if 
(TransactionIds.beginTimestamp(transactionId).compareTo(indexCreationActivationTs)
 < 0) {
+                    transactionsToResolve.put(
+                            row.transactionId(),
+                            new CommitPartitionId(row.commitTableOrZoneId(), 
row.commitPartitionId())
+                    );
+                }
+            }
 
-            nextRowIdToBuild = nextRowIdToBuild.increment();
+            nextRowIdToBuild = row.rowId().increment();
         }
 
-        return batch;
+        Map<UUID, CompletableFuture<TxState>> txStateResolveFutures = 
transactionsToResolve.entrySet().stream()
+                .map(entry -> Map.entry(entry.getKey(), 
resolveFinalTxStateIfNeeded(entry.getKey(), entry.getValue())))
+                .collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+        return CompletableFutures.allOf(txStateResolveFutures.values())
+                .thenApply(unused -> {
+                    Set<UUID> abortedTransactionIds = 
txStateResolveFutures.entrySet().stream()
+                            .filter(entry -> entry.getValue().join() == 
TxState.ABORTED)

Review Comment:
   This is by design. We have to resolve WI's transaction states, but this 
resolution is not guaranteed to finish timely (if the commit partition of a 
transaction is unavailable because it lost the majority)



-- 
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]

Reply via email to