Return correct value on lockref dequeue exception 33/78133/5
authorMohammad Salehe <salehe@cs.toronto.edu>
Fri, 8 Feb 2019 16:29:08 +0000 (11:29 -0500)
committerMohammad Salehe <salehe@cs.toronto.edu>
Mon, 25 Feb 2019 03:23:39 +0000 (22:23 -0500)
If we can not dequeue the lock reference, we should not return
same result, so the caller can try again

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

index 343ba1f..824dc0c 100644 (file)
@@ -401,12 +401,14 @@ public class MusicCassaCore implements MusicCoreService {
             String primaryKeyValue = splitString[2];
             try {
                 getLockingServiceHandle().deQueueLockRef(keyspace, table, primaryKeyValue, lockReference);
-            } catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
-                logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.DESTROYLOCK + lockReference, ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+            } catch (MusicServiceException | MusicQueryException | MusicLockingException e) {
+                logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.DESTROYLOCK + " " + primaryKeyValue + " " + lockReference, ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+                logger.info(EELFLoggerDelegate.applicationLogger, "Lock not destroyed " + primaryKeyValue + " " + lockReference + " " + " :" + e.getMessage());
+                return new MusicLockState(MusicLockState.LockStatus.LOCKED, "");
             }
             long end = System.currentTimeMillis();
-            logger.info(EELFLoggerDelegate.applicationLogger, "Time taken to destroy lock reference:" + (end - start) + " ms");
-            return getMusicLockState(fullyQualifiedKey);
+            logger.info(EELFLoggerDelegate.applicationLogger, "Time taken to destroy lock reference " + primaryKeyValue + " " + lockReference + " " + " :" + (end - start) + " ms");
+            return new MusicLockState(MusicLockState.LockStatus.UNLOCKED, "");
         }
         finally {
             TimeMeasureInstance.instance().exit();
@@ -624,7 +626,7 @@ public class MusicCassaCore implements MusicCoreService {
                     try {
                         Thread.sleep(Integer.min(100, (int) Math.pow(2, createLockReferenceTries - 1)));
                     } catch (InterruptedException e) {
-                        e.printStackTrace();
+                        logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
                     }
                 } else
                     break;
@@ -644,7 +646,7 @@ public class MusicCassaCore implements MusicCoreService {
                     try {
                         Thread.sleep(Integer.min(100, (int) Math.pow(2, acquireLockTries - 1)));
                     } catch (InterruptedException e) {
-                        e.printStackTrace();
+                        logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
                     }
                 } else
                     break;
@@ -679,9 +681,6 @@ public class MusicCassaCore implements MusicCoreService {
             TimeMeasureInstance.instance().exit();
         }
     }
-    
-
-
 
     /**
      * This method performs DDL operation on cassasndra, when the lock for the resource is acquired.
@@ -713,13 +712,10 @@ public class MusicCassaCore implements MusicCoreService {
             return null;
         }
     }
-    
-    
+
     public static MusicLockState getMusicLockState(String fullyQualifiedKey) {
                return null;
     }
-
-  
     
     /**
      * @param lockName
@@ -738,15 +734,6 @@ public class MusicCassaCore implements MusicCoreService {
         resultMap.put("keyspace",keyspace);
         return resultMap;
     }
-    
-
-       public static void main(String[] args) {
-               String x = "axe top";
-               x = x.replaceFirst("top", "sword");
-               System.out.print(x); //returns sword pickaxe
-       }
-
-
 
        @Override
        public ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,