diff options
author | Mohammad Salehe <salehe@cs.toronto.edu> | 2019-02-08 11:22:33 -0500 |
---|---|---|
committer | Mohammad Salehe <salehe@cs.toronto.edu> | 2019-02-24 22:23:39 -0500 |
commit | dee199dd21b286e4c9e3af36fbc0d646168615e4 (patch) | |
tree | c595324332461fcaf69b5dcff6ed1044e96d301a | |
parent | fdc837a3e2b654cff60e8b9e1142840c07047338 (diff) |
Check for lockref validity while guarding it
Lock references are not unique until the guard is updated, so
in case of contention, we might not be able to use the lock
reference we have. We should abort so the caller can try again
Change-Id: I52cfb8c6979cced81dd20f4ef9b55b79121f121f
Issue-ID: MUSIC-148
Signed-off-by: Mohammad Salehe <salehe@cs.toronto.edu>
-rw-r--r-- | src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java b/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java index ec694ddc..cbc172db 100644 --- a/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java +++ b/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java @@ -119,8 +119,6 @@ public class CassaLockStore { long lockEpochMillis = System.currentTimeMillis(); // System.out.println("guard(" + lockName + "): " + prevGuard + "->" + lockRef); - logger.info(EELFLoggerDelegate.applicationLogger, - "Created lock reference for " + keyspace + "." + table + "." + lockName + ":" + lockRef); queryObject = new PreparedQueryObject(); String insQuery = "BEGIN BATCH" + @@ -141,6 +139,11 @@ public class CassaLockStore { queryObject.addValue(isWriteLock); queryObject.appendQueryString(insQuery); boolean pResult = dsHandle.executePut(queryObject, "critical"); + + if (pResult == false) // LockReference is used by another actor before we could guard it + throw new MusicServiceException("LockReference went out of hand"); + logger.info(EELFLoggerDelegate.applicationLogger, + "Created+Enq lock reference for " + keyspace + "." + table + "." + lockName + ":" + lockRef); return String.valueOf(lockRef); } finally { @@ -172,8 +175,7 @@ public class CassaLockStore { } return lockQueue; } - - + /** * Returns a result set containing the list of clients waiting for a particular lock * @param keyspace |