Don't create extra locks while claiming ownership 97/88897/2
authorArthur Martella <arthur.martella.1@att.com>
Thu, 30 May 2019 13:46:02 +0000 (09:46 -0400)
committerArthur Martella <arthur.martella.1@att.com>
Thu, 30 May 2019 14:17:25 +0000 (10:17 -0400)
Issue-ID: MUSIC-402
Signed-off-by: Martella, Arthur <arthur.martella.1@att.com>
Change-Id: I12b9ff80be0429ff7a9fc68074a3ca2ec133aee2

mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java

index fc8897f..67ee5ab 100755 (executable)
@@ -276,11 +276,11 @@ public interface MusicInterface {
 
        /**
      * This functions relinquishes a range
-     * @param ownerId id of the current ownerh
+     * @param lockId id of the lock to be relinquished
      * @param rangeId id of the range to be relinquished
      * @throws MusicLockingException
      */
-       void relinquish(String ownerId, String rangeId) throws MDBCServiceException;
+       void relinquish(String lockId, String rangeId) throws MDBCServiceException;
 
     /**
      * This function return all the range indexes that are currently hold by any of the connections in the system
@@ -309,7 +309,8 @@ public interface MusicInterface {
 
     void updateNodeInfoTableWithTxTimeIDKey(UUID txTimeID, String nodeName) throws MDBCServiceException;
 
-    LockResult requestLock(LockRequest request) throws MDBCServiceException;
+    String createLock(LockRequest request) throws MDBCServiceException;
+    LockResult acquireLock(LockRequest request, String lockId) throws MDBCServiceException;
 
     void releaseLocks(Map<UUID, LockResult> newLocks) throws MDBCServiceException;
 
index d934473..67d30ff 100644 (file)
@@ -1535,7 +1535,7 @@ public class MusicMixin implements MusicInterface {
         try {
             newRow = executeMusicLockedGet(music_ns, musicRangeDependencyTableName,pQueryObject,tableWithoutDot,null);
         } catch (MDBCServiceException e) {
-            logger.error("Get operationt error: Failure to get row from MRI "+musicRangeInformationTableName+" trying for table "+tableWithoutDot);
+            logger.error("Get operation  error: Failure to get row from " + musicRangeDependencyTableName + " trying for table " + tableWithoutDot);
             throw new MDBCServiceException("Initialization error:Failure to add new row to transaction information for table "+tableWithoutDot, e);
         }
         return getRangeDependenciesFromCassandraRow(newRow);
@@ -2074,10 +2074,16 @@ public class MusicMixin implements MusicInterface {
     }
 
     @Override
-    public LockResult requestLock(LockRequest request) throws MDBCServiceException{
+    public String createLock(LockRequest request) throws MDBCServiceException{
         String fullyQualifiedKey= music_ns+"."+ musicRangeInformationTableName + "." + request.getId();
         boolean isWrite = (request.getLockType()==SQLOperationType.WRITE);
         String lockId = MusicCore.createLockReference(fullyQualifiedKey, isWrite);
+        return lockId;
+    }
+
+    @Override
+    public LockResult acquireLock(LockRequest request, String lockId) throws MDBCServiceException{
+        String fullyQualifiedKey= music_ns+"."+ musicRangeInformationTableName + "." + request.getId();
         ReturnType lockReturn = acquireLock(fullyQualifiedKey,lockId);
         if(lockReturn.getResult() == ResultType.FAILURE) {
             //\TODO Improve the exponential backoff
@@ -2092,6 +2098,7 @@ public class MusicMixin implements MusicInterface {
         return new LockResult(true, request.getId(),lockId,true,null);
     }
 
+
     /**
      *  fixes the DAG in case the previous owner failed while trying to own the row
      * @param latestDag
@@ -2186,11 +2193,11 @@ public class MusicMixin implements MusicInterface {
 
 
     @Override
-    public void relinquish(String ownerId, String rangeId) throws MDBCServiceException{
-        if(ownerId==null||ownerId.isEmpty()||rangeId==null||rangeId.isEmpty()){
+    public void relinquish(String lockId, String rangeId) throws MDBCServiceException{
+        if(lockId==null||lockId.isEmpty()||rangeId==null||rangeId.isEmpty()){
             return;
         }
-        unlockKeyInMusic(musicRangeInformationTableName, rangeId, ownerId);
+        unlockKeyInMusic(musicRangeInformationTableName, rangeId, lockId);
     }
 
     /**
index c7a2b5b..218993b 100644 (file)
@@ -345,11 +345,12 @@ public class OwnershipAndCheckpoint{
             } else {
                 LockRequest request = new LockRequest(uuidToOwn,
                         new ArrayList<>(node.getRangeSet()), lockType);
+                String lockId = mi.createLock(request);
                 LockResult result = null;
                 boolean owned = false;
                 while(!owned && !timeout(opId)){
                     try {
-                        result = mi.requestLock(request);
+                        result = mi.acquireLock(request, lockId);
                         if (result.wasSuccessful()) {
                             owned = true;
                             continue;
@@ -371,6 +372,7 @@ public class OwnershipAndCheckpoint{
                     newLocks.put(uuidToOwn,result);
                 }
                 else{
+                   mi.relinquish(lockId, partition.getMRIIndex().toString());
                     break;
                 }
             }