Check for lockref validity while guarding it 30/78130/2
authorMohammad Salehe <salehe@cs.toronto.edu>
Fri, 8 Feb 2019 16:22:33 +0000 (11:22 -0500)
committerMohammad Salehe <salehe@cs.toronto.edu>
Mon, 25 Feb 2019 03:23:39 +0000 (22:23 -0500)
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>
src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java

index ec694dd..cbc172d 100644 (file)
@@ -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