Fail when distributed lock not obtained.
Hazelcast tryLock returns a boolean to indicate lock success, which is currently ignored, resulting in unsafe operations.
@@ -3,6 +3,8 @@ package com.orientechnologies.orient.server.hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.orientechnologies.common.types.OModifiableInteger;
import com.orientechnologies.orient.server.distributed.ODistributedLockManager;
+import com.orientechnologies.orient.server.distributed.task.ODistributedLockException;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -33,9 +35,16 @@ public class OHazelcastLockManager implements ODistributedLockManager {
if (timeout != 0) {
try {
- hazelcast.getLock(resource).tryLock(timeout, TimeUnit.MILLISECONDS);
+ if (!hazelcast.getLock(resource).tryLock(timeout, TimeUnit.MILLISECONDS)) {
+ throw new ODistributedLockException(
+ String.format("Timed out after %d ms attempting to obtain lock for resource '%s' on node '%s'",
+ timeout, resource, nodeSource));
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
+ throw new ODistributedLockException(
+ String.format("Interrupted while attempting to obtain lock for resource '%s' on node '%s'",
+ timeout, resource, nodeSource));
}
} else {
hazelcast.getLock(resource).lock();
