Phillippko commented on code in PR #6810:
URL: https://github.com/apache/ignite-3/pull/6810#discussion_r2447805737
##########
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:
```if the state is unknown, the Backfill freezes until the uncertainty is
resolved```
I wonder if it should freeze indefinitely... Considering transactions could
be stuck for a long time
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/handlers/BuildIndexRowVersionChooser.java:
##########
@@ -81,6 +92,9 @@ List<BinaryRowAndRowId> chooseForBuildIndex(RowId rowId) {
if (beginTs(readResult) >= createIndexActivationTs) {
continue;
}
+ if
(abortedTransactionIds.contains(readResult.transactionId())) {
Review Comment:
(not insisting) combine these if's?
##########
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())))
Review Comment:
IndexBuildTask works with just one partition storage -> all rows will have
the same commitPartitionId, yes? Could we make it a field and replace map with
a set?
--
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]