Implement voluntaryReleaseLock retry logic 35/78135/5
authorMohammad Salehe <salehe@cs.toronto.edu>
Fri, 8 Feb 2019 16:34:41 +0000 (11:34 -0500)
committerMohammad Salehe <salehe@cs.toronto.edu>
Mon, 25 Feb 2019 03:23:39 +0000 (22:23 -0500)
Add retry logic for voluntaryReleaseLock inside atomicPut

Change-Id: Iedb474c673541f3f79d4ae4ee76e15f14a387ed7
Issue-ID: MUSIC-148
Signed-off-by: Mohammad Salehe <salehe@cs.toronto.edu>
src/main/java/org/onap/music/service/impl/MusicCassaCore.java

index 7eebf65..e334748 100644 (file)
@@ -668,7 +668,23 @@ public class MusicCassaCore implements MusicCoreService {
             ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
                     queryObject, lockReference, conditionInfo);
             long criticalPutTime = System.currentTimeMillis();
-            voluntaryReleaseLock(fullyQualifiedKey, lockReference);
+
+            int releaseTries = 0;
+            while (true) {
+                MusicLockState rs = voluntaryReleaseLock(fullyQualifiedKey, lockReference);
+                releaseTries++;
+                if (rs.getLockStatus() != MusicLockState.LockStatus.UNLOCKED) {
+                    try {
+                        Thread.sleep(Integer.min(100, (int) Math.pow(2, releaseTries - 1)));
+                    } catch (InterruptedException e) {
+                    }
+                } else
+                    break;
+            }
+            if (releaseTries > 1) {
+                System.out.print((char) (Integer.min(releaseTries, 9) + 78));
+            }
+
             long lockDeleteTime = System.currentTimeMillis();
             String timingInfo = "|lock creation time:" + (lockCreationTime - start)
                     + "|lock accquire time:" + (lockAcqTime - lockCreationTime)