korlov42 commented on code in PR #1191:
URL: https://github.com/apache/ignite-3/pull/1191#discussion_r1000411729


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -814,25 +844,106 @@ private CompletableFuture<RowId> 
takeLocksForUpsert(ByteBuffer searchKey, UUID i
     /**
      * Takes all required locks on a key, before inserting the value.
      *
-     * @param searchKey Key to search.
-     * @param indexId   Index id.
-     * @param txId      Transaction id.
+     * @param tableRow Table row.
+     * @param txId Transaction id.
      * @return Future completes with {@link RowId} or {@code null} if there is 
no value.
      */
-    private CompletableFuture<RowId> takeLocksForInsert(ByteBuffer searchKey, 
UUID indexId, UUID txId) {
-        return lockManager.acquire(txId, new LockKey(indexId, searchKey), 
LockMode.S) // Index S lock
-                .thenCompose(sharedIdxLock -> {
-                    RowId rowId = rowIdByKey(indexId, searchKey);
-
-                    if (rowId == null) {
-                        return lockManager.acquire(txId, new LockKey(indexId, 
searchKey), LockMode.X) // Index X lock
-                                .thenCompose(exclusiveIdxLock ->
-                                        lockManager.acquire(txId, new 
LockKey(tableId), LockMode.IX) // IX lock on table
-                                                .thenApply(tblLock -> null));
-                    }
+    private CompletableFuture<?> takeLocksForInsert(BinaryRow tableRow, UUID 
txId) {
+        return takeLockOnIndexes(tableRow, txId)
+                .thenCompose(ignored -> lockManager.acquire(txId, new 
LockKey(tableId), LockMode.IX));
+    }
 
-                    return CompletableFuture.completedFuture(rowId);
-                });
+    private CompletableFuture<?> takeLockOnIndexes(BinaryRow tableRow, UUID 
txId) {
+        List<IndexStorage> indexes = activeIndexes.get();
+
+        if (nullOrEmpty(indexes)) {
+            return CompletableFuture.completedFuture(null);
+        }
+
+        CompletableFuture<?>[] locks = new CompletableFuture[indexes.size()];
+        int idx = 0;
+
+        for (IndexStorage index : indexes) {
+            ByteBuffer indexRow = toIndexKey(index, tableRow);
+
+            UUID indexId = indexId(index);
+
+            assert indexRow != null;
+
+            locks[idx++] = lockManager.acquire(txId, new LockKey(indexId, 
indexRow), LockMode.X);
+        }
+
+        return CompletableFuture.allOf(locks);
+    }
+
+    private UUID indexId(IndexStorage index) {
+        if (index instanceof HashIndexStorage) {

Review Comment:
   me to =(



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