ptupitsyn commented on code in PR #5752:
URL: https://github.com/apache/ignite-3/pull/5752#discussion_r2079837757


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTupleSerializer.java:
##########
@@ -456,14 +456,11 @@ public static PartitionAwarenessProvider 
getPartitionAwarenessProvider(Collectio
                 return hash;
             }
 
-            while (iter.hasNext()) {
-                Tuple next = iter.next();
-                if (hash != getColocationHash(schema, next)) {
-                    return null;
-                }
+            // Temporary disable direct mapping for batches.

Review Comment:
   Do we have a ticket to remove temporary behavior?



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientTransactionInflights.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.client;
+
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
+
+/**
+ * Client transaction inflights tracker.
+ */
+public class ClientTransactionInflights {
+    /** Hint for maximum concurrent txns. */
+    private static final int MAX_CONCURRENT_TXNS = 1024;
+
+    /** Txn contexts. */
+    private final ConcurrentHashMap<UUID, TxContext> txCtxMap = new 
ConcurrentHashMap<>(MAX_CONCURRENT_TXNS);
+
+    /**
+     * Registers the inflight update for a transaction.
+     *
+     * @param txId The transaction id.
+     */
+    public void addInflight(UUID txId) {
+        txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                ctx = new TxContext();
+            }
+
+            ctx.addInflight();
+
+            return ctx;
+        });
+    }
+
+    /**
+     * Unregisters the inflight for a transaction.
+     *
+     * @param txId The transaction id.
+     * @param t Not null on error from a server.
+     */
+    public void removeInflight(UUID txId, @Nullable Throwable t) {
+        var ctx0 = txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                throw new AssertionError();
+            }
+
+            ctx.removeInflight(txId);
+
+            if (t != null && ctx.err == null) {
+                ctx.err = t; // Retain only first exception.
+            }
+
+            return ctx;
+        });
+
+        // Avoid completion under lock.
+        if (ctx0.finishFut != null && ctx0.inflights == 0) {
+            if (t != null) {
+                ctx0.finishFut.completeExceptionally(t);
+            } else {
+                ctx0.finishFut.complete(null);

Review Comment:
   Looks like this call might run user continuations on IO (Netty) thread, 
consider using `asyncContinuationExecutor` to complete user-facing futures.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java:
##########
@@ -130,6 +130,9 @@ public final class ReliableChannel implements AutoCloseable 
{
     @Nullable
     private ScheduledExecutorService streamerFlushExecutor;
 
+    /** Inflights. */
+    private final ClientTransactionInflights inflights;

Review Comment:
   This is global across all server connections. Does it mean that inflight 
notifications can be received on a connection that is different from the tx 
coordinator?
   
   I don't see how it is possible in `ClientInboundMessageHandler` - looks like 
we handle everything within one connection.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/TcpClientChannel.java:
##########
@@ -511,10 +518,13 @@ private void handlePartitionAssignmentChange(int flags, 
ClientMessageUnpacker un
     private void handleNotification(long id, ClientMessageUnpacker unpacker, 
@Nullable Throwable err) {
         // One-shot notification handler - remove immediately.
         CompletableFuture<PayloadInputChannel> handler = 
notificationHandlers.remove(id);
+
         if (handler == null) {
-            log.error("Unexpected notification ID [remoteAddress=" + 
cfg.getAddress() + "]: " + id);
+            // Default notification handler. Used to deliver delayed 
replication acks.

Review Comment:
   This looks a bit dirty to me, and might prevent us from extending the 
protocol in the future. Can we use `notificationHandlers` as usual?



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientTransactionInflights.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.client;
+
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
+
+/**
+ * Client transaction inflights tracker.
+ */
+public class ClientTransactionInflights {
+    /** Hint for maximum concurrent txns. */
+    private static final int MAX_CONCURRENT_TXNS = 1024;
+
+    /** Txn contexts. */
+    private final ConcurrentHashMap<UUID, TxContext> txCtxMap = new 
ConcurrentHashMap<>(MAX_CONCURRENT_TXNS);
+
+    /**
+     * Registers the inflight update for a transaction.
+     *
+     * @param txId The transaction id.
+     */
+    public void addInflight(UUID txId) {
+        txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                ctx = new TxContext();
+            }
+
+            ctx.addInflight();
+
+            return ctx;
+        });
+    }
+
+    /**
+     * Unregisters the inflight for a transaction.
+     *
+     * @param txId The transaction id.
+     * @param t Not null on error from a server.
+     */
+    public void removeInflight(UUID txId, @Nullable Throwable t) {
+        var ctx0 = txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                throw new AssertionError();
+            }
+
+            ctx.removeInflight(txId);
+
+            if (t != null && ctx.err == null) {
+                ctx.err = t; // Retain only first exception.
+            }
+
+            return ctx;
+        });
+
+        // Avoid completion under lock.
+        if (ctx0.finishFut != null && ctx0.inflights == 0) {
+            if (t != null) {
+                ctx0.finishFut.completeExceptionally(t);
+            } else {
+                ctx0.finishFut.complete(null);
+            }
+        }
+    }
+
+    /**
+     * Get finish future.
+     *
+     * @param txId Transaction id.
+     * @return The future.
+     */
+    public CompletableFuture<Void> finishFuture(UUID txId) {
+        // No new operations can be enlisted an this point, so concurrent 
inflights counter can only go down.
+        TxContext ctx0 = txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                return null; // Empty transaction.
+            }
+
+            if (ctx.finishFut == null) {
+                ctx.finishFut =

Review Comment:
   Nitpick: nested condition might be difficult to read.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientTransactionInflights.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.client;
+
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
+
+/**
+ * Client transaction inflights tracker.
+ */
+public class ClientTransactionInflights {
+    /** Hint for maximum concurrent txns. */
+    private static final int MAX_CONCURRENT_TXNS = 1024;
+
+    /** Txn contexts. */
+    private final ConcurrentHashMap<UUID, TxContext> txCtxMap = new 
ConcurrentHashMap<>(MAX_CONCURRENT_TXNS);
+
+    /**
+     * Registers the inflight update for a transaction.
+     *
+     * @param txId The transaction id.
+     */
+    public void addInflight(UUID txId) {
+        txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                ctx = new TxContext();
+            }
+
+            ctx.addInflight();
+
+            return ctx;
+        });
+    }
+
+    /**
+     * Unregisters the inflight for a transaction.
+     *
+     * @param txId The transaction id.
+     * @param t Not null on error from a server.
+     */
+    public void removeInflight(UUID txId, @Nullable Throwable t) {
+        var ctx0 = txCtxMap.compute(txId, (uuid, ctx) -> {
+            if (ctx == null) {
+                throw new AssertionError();
+            }
+
+            ctx.removeInflight(txId);
+
+            if (t != null && ctx.err == null) {
+                ctx.err = t; // Retain only first exception.

Review Comment:
   Not sure about swallowed exceptions, should we use `addSuppressed` instead? 



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientTransactionInflights.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.client;
+
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
+
+/**
+ * Client transaction inflights tracker.
+ */
+public class ClientTransactionInflights {
+    /** Hint for maximum concurrent txns. */
+    private static final int MAX_CONCURRENT_TXNS = 1024;

Review Comment:
   - Misleading name, this is not a limit, but initial capacity
   - 1024 seems too much, I would remove this altogether and use the default 
map ctor



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to