SammyVimes commented on code in PR #1657:
URL: https://github.com/apache/ignite-3/pull/1657#discussion_r1101723883
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java:
##########
@@ -133,6 +147,117 @@ public void handleUpdateAll(
});
}
+ /**
+ * Tries removing previous write's index.
+ *
+ * @param rowId Row id.
+ * @param previousRow Previous write value.
+ */
+ private void tryRemovePreviousWritesIndex(RowId rowId, BinaryRow
previousRow) {
+ try (Cursor<ReadResult> cursor = storage.scanVersions(rowId)) {
+ if (!cursor.hasNext()) {
+ return;
+ }
+
+ tryRemoveFromIndexes(previousRow, rowId, cursor);
+ }
+ }
+
+ /**
+ * Handles the abortion of a transaction.
+ *
+ * @param pendingRowIds Row ids of write-intents to be rolled back.
+ * @param onReplication On replication callback.
+ */
+ public void handleTransactionAbortion(Set<RowId> pendingRowIds, Runnable
onReplication) {
+ storage.runConsistently(() -> {
+ for (RowId rowId : pendingRowIds) {
+ try (Cursor<ReadResult> cursor = storage.scanVersions(rowId)) {
+ if (!cursor.hasNext()) {
+ continue;
+ }
+
+ ReadResult item = cursor.next();
+
+ assert item.isWriteIntent();
+
+ BinaryRow rowToRemove = item.binaryRow();
+
+ if (rowToRemove == null) {
+ continue;
+ }
+
+ tryRemoveFromIndexes(rowToRemove, rowId, cursor);
+ }
+ }
+
+ pendingRowIds.forEach(storage::abortWrite);
+
+ onReplication.run();
+
+ return null;
+ });
+ }
+
+ /**
+ * Tries removing indexed row from evey index.
+ * Removes the row only if no previous value's index matches index of the
row to remove, because if it matches, then the index
+ * might still be in use.
+ *
+ * @param rowToRemove Row to remove from indexes.
+ * @param rowId Row id.
+ * @param previousValues Cursor with previous version of the row.
+ */
+ private void tryRemoveFromIndexes(BinaryRow rowToRemove, RowId rowId,
Cursor<ReadResult> previousValues) {
+ TableSchemaAwareIndexStorage[] indexes =
this.indexes.get().values().toArray(new TableSchemaAwareIndexStorage[0]);
+
+ ByteBuffer[] indexValues = new ByteBuffer[indexes.length];
+
+ // Precalculate value for every index.
+ for (int i = 0, indexesLength = indexes.length; i < indexesLength;
i++) {
Review Comment:
Yes.
--
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]