dmagda commented on a change in pull request #6976: IGNITE-6804 Warning if unordered map used in locking cache operation. URL: https://github.com/apache/ignite/pull/6976#discussion_r335757380
########## File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java ########## @@ -5175,6 +5197,58 @@ protected final void validateCacheKeys(Iterable<?> keys) { } } + /** + * Checks that given map is sorted or otherwise constant order. + * + * Issues developer warning otherwise. + * + * @param m Map to examine. + */ + protected void checkMapType(Map m, String op) { + if (m == null || m.size() <= 1) + return; + + if (m instanceof SortedMap || m instanceof LinkedHashMap || m instanceof GridSerializableMap) + return; + + Transaction tx = ctx.kernalContext().cache().transactions().tx(); + if (tx != null && !tx.implicit() && tx.concurrency() == OPTIMISTIC) + return; + + LT.warn(log, "Unordered map of type " + m.getClass().getSimpleName() + + " was passed to " + op + " operation on cache: " + name() + ". " + + "Locking order of keys cannot be guaranteed - this will lead to deadlock! " + Review comment: Please rephrase this sentence a bit - "Unordered map {type} is used for {name} operation. This can lead to a distributed deadlock. Switch to a sorted map like TreeMap instead" Let's use it in similar places below. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services