maksaska commented on code in PR #12128:
URL: https://github.com/apache/ignite/pull/12128#discussion_r2157332609


##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientCache.java:
##########
@@ -1616,4 +1650,77 @@ private void 
checkDataReplicationSupported(ProtocolContext protocolCtx)
         if 
(!protocolCtx.isFeatureSupported(ProtocolBitmaskFeature.DATA_REPLICATION_OPERATIONS))
             throw new 
ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.DATA_REPLICATION_OPERATIONS);
     }
+
+    /**
+     * Warns if an unordered map is used in an operation that may lead to a 
distributed deadlock
+     * during an explicit transaction.
+     * <p>
+     * This check is relevant only for explicit user-managed transactions. 
Implicit transactions
+     * (such as those started automatically by the system) are not inspected 
by this method.
+     * </p>
+     *
+     * @param m        The map being used in the cache operation.
+     */
+    protected void warnIfUnordered(Map<?, ?> m) {
+        if (m == null || m.size() <= 1)
+            return;
+
+        TcpClientTransaction tx = transactions.tx();
+
+        // Only explicit transactions are checked
+        if (tx == null)
+            return;
+
+        if (m instanceof SortedMap || m instanceof GridSerializableMap)
+            return;
+
+        if (!canBlockTx(false, tx.getConcurrency(), tx.getIsolation()))
+            return;
+
+        LT.warn(log, "Unordered map " + m.getClass().getName() + " is used for 
putAll operation on cache " +
+            name + ". This can lead to a distributed deadlock. Switch to a 
sorted map like TreeMap instead.");
+    }
+
+    /**
+     * Warns if an unordered map is used in an operation that may lead to a 
distributed deadlock
+     * during an explicit transaction.
+     * <p>
+     * This check is relevant only for explicit user-managed transactions. 
Implicit transactions
+     * (such as those started automatically by the system) are not inspected 
by this method.
+     * </p>
+     *
+     * @param coll        The collection being used in the cache operation.
+     * @param isGetOp  {@code true} if the operation is a get (e.g., {@code 
getAll}).
+     */
+    protected void warnIfUnordered(Collection<?> coll, boolean isGetOp) {
+        if (coll == null || coll.size() <= 1)
+            return;
+
+        TcpClientTransaction tx = transactions.tx();
+
+        // Only explicit transactions are checked

Review Comment:
   Done!



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