You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ibessonov (via GitHub)" <gi...@apache.org> on 2023/09/08 09:38:31 UTC

[GitHub] [ignite-3] ibessonov commented on a diff in pull request #2555: IGNITE-20345 Replace key-only rows with BinaryTuples

ibessonov commented on code in PR #2555:
URL: https://github.com/apache/ignite-3/pull/2555#discussion_r1318275829


##########
modules/client/src/test/java/org/apache/ignite/client/fakes/FakeInternalTable.java:
##########
@@ -123,10 +121,10 @@ public CompletableFuture<BinaryRow> get(
         return null;
     }
 
-    private BinaryRow getImpl(BinaryTuple key, BinaryRow keyRow) {
+    private BinaryRow getImpl(ByteBuffer key, BinaryRow keyRow) {

Review Comment:
   What a peculiar name! Almost as if it returns an implementation of some sort. This is just a comment. I'd rather see a `get0`, but I know that it's not your code.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replication/request/MultipleRowPkReplicaRequest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.table.distributed.replication.request;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.table.distributed.replicator.action.RequestType;
+import org.apache.ignite.network.annotations.Marshallable;
+
+/**
+ * Multiple row replica request involving table's Primary Keys.
+ */
+public interface MultipleRowPkReplicaRequest extends ReplicaRequest {
+    List<BinaryTupleMessage> primaryKeyMessages();
+
+    /**
+     * Deserializes binary row byte buffers into binary rows.
+     */
+    default List<BinaryTuple> primaryKeys() {
+        List<BinaryTupleMessage> primaryKeyMessages = primaryKeyMessages();
+
+        var result = new ArrayList<BinaryTuple>(primaryKeyMessages.size());
+
+        for (BinaryTupleMessage message : primaryKeyMessages) {
+            result.add(message.asBinaryTuple());
+        }
+
+        return result;
+    }
+
+    @Marshallable

Review Comment:
   It would be nice to replace this with an ordinal/ID in the future. Let's do that in a separate issue



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -1827,6 +1762,94 @@ private CompletableFuture<Object> processMultiEntryAction(ReadWriteMultiRowRepli
         }
     }
 
+    /**
+     * Precesses multi request.
+     *
+     * @param request Multi request operation.
+     * @param txCoordinatorId Transaction coordinator id.
+     * @return Listener response.
+     */
+    private CompletableFuture<Object> processMultiEntryAction(ReadWriteMultiRowPkReplicaRequest request, String txCoordinatorId) {
+        UUID txId = request.transactionId();
+        TablePartitionId committedPartitionId = request.commitPartitionId();
+        List<BinaryTuple> primaryKeys = request.primaryKeys();
+
+        assert committedPartitionId != null || request.requestType() == RequestType.RW_GET_ALL
+                : "Commit partition is null [type=" + request.requestType() + ']';
+
+        switch (request.requestType()) {
+            case RW_GET_ALL: {
+                CompletableFuture<BinaryRow>[] rowFuts = new CompletableFuture[primaryKeys.size()];
+
+                int i = 0;
+
+                for (BinaryTuple primaryKey : primaryKeys) {
+                    rowFuts[i++] = resolveRowByPk(primaryKey, txId, (rowId, row) -> {
+                        if (rowId == null) {
+                            return completedFuture(null);
+                        }
+
+                        return takeLocksForGet(rowId, txId)
+                                .thenApply(ignored -> row);
+                    });
+                }
+
+                return allOf(rowFuts)
+                        .thenApply(ignored -> {
+                            var result = new ArrayList<BinaryRow>(primaryKeys.size());
+
+                            for (CompletableFuture<BinaryRow> rowFut : rowFuts) {
+                                result.add(rowFut.join());
+                            }
+
+                            return result;
+                        });
+            }
+            case RW_DELETE_ALL: {
+                CompletableFuture<RowId>[] rowIdLockFuts = new CompletableFuture[primaryKeys.size()];
+
+                for (int i = 0; i < primaryKeys.size(); i++) {
+                    rowIdLockFuts[i] = resolveRowByPk(primaryKeys.get(i), txId, (rowId, row) -> {
+                        if (rowId == null) {
+                            return completedFuture(null);
+                        }

Review Comment:
   This is not related to your changes, I guess, but let's examine the following situation (table is empty at the start):
   ```
       |   TX 1   |   TX 2   |
   ts0 |   start  |   start  |
   ts1 | delete A | delete B |
   ts2 | insert B | insert A |
   ts3 |  commit  | commit   |
   ```
   In serializable transactions, either A or B will be missing after the execution. But, according to this code, we will ignore locks on delete, resulting in both A and B being inserted by corresponding transactions. It breaks the protocol. We should consult owners of the feature.
   My guess - taking locks based on RowId is a wrong idea. We should take locks based exclusively on PK. We don't even need to resolve it to do so. What do you think?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replication/request/ReadWriteMultiRowPkReplicaRequest.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.table.distributed.replication.request;
+
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.table.distributed.TableMessageGroup;
+import org.apache.ignite.network.annotations.Marshallable;
+import org.apache.ignite.network.annotations.Transferable;
+
+/**
+ * Read-write multi-row replica request involving table's Primary Keys.
+ */
+@Transferable(TableMessageGroup.RW_MULTI_ROW_PK_REPLICA_REQUEST)
+public interface ReadWriteMultiRowPkReplicaRequest extends MultipleRowPkReplicaRequest, ReadWriteReplicaRequest, CommittableTxRequest {
+    /**
+     * Gets a commit partition id.
+     *
+     * @return Table partition id.
+     */
+    @Marshallable
+    TablePartitionId commitPartitionId();

Review Comment:
   There's a `TablePartitionIdMessage`, please use it instead.
   I don't really get why that interface is serializable, can you please fix that as well? Thank you!



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org