Relinquish Locks aptly based on partition 04/90404/2
authorstatta <statta@research.att.com>
Mon, 24 Jun 2019 16:27:38 +0000 (12:27 -0400)
committerst782s <statta@research.att.com>
Mon, 24 Jun 2019 21:16:12 +0000 (17:16 -0400)
Issue-ID: MUSIC-402
Change-Id: I9b54939920521b13649253794d82789b46727acd
Signed-off-by: statta <statta@research.att.com>
mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java
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
mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java

index 3cbd1e0..61ce6bd 100755 (executable)
@@ -240,6 +240,15 @@ public class MdbcConnection implements Connection {
         }
         jdbcConn.rollback();
         progressKeeper.reinitializeTxProgress(id);
+        
+        //\TODO try to execute outside of the critical path of commit
+        try {
+            if(partition != null) {
+                mi.relinquish(partition);
+            }
+        } catch (MDBCServiceException e) {
+            logger.warn("Error trying to relinquish: "+partition.toString());
+        }
     }
 
     /**
index 62259a8..3d0cc0a 100755 (executable)
@@ -281,8 +281,11 @@ public interface MusicInterface {
      */
        public void relinquish(DatabasePartition partition) throws MDBCServiceException;
        
+    @Deprecated
        /**
-     * This functions relinquishes a range
+     * This functions relinquishes a range;
+     * Deprecated because it does not have the mechanism to set the partition lock to null
+     * see relinquish(DatabasePartition partition)
      * @param lockId id of the lock to be relinquished
      * @param rangeId id of the range to be relinquished
      * @throws MusicLockingException
index 6939d78..f22daa3 100644 (file)
@@ -1307,6 +1307,11 @@ public class MusicMixin implements MusicInterface {
             return;
         }
 
+        //Add creation type of transaction digest
+        if(transactionDigest == null || transactionDigest.isEmpty()) {
+            return;
+        }
+        
         UUID mriIndex = partition.getMRIIndex();
         String fullyQualifiedMriKey = music_ns+"."+ this.musicRangeInformationTableName+"."+mriIndex;
         //0. See if reference to lock was already created
@@ -1315,10 +1320,6 @@ public class MusicMixin implements MusicInterface {
             throw new MDBCServiceException("Not able to commit, as you are no longer the lock-holder for this partition");
         }
 
-        //Add creation type of transaction digest
-        if(transactionDigest == null || transactionDigest.isEmpty()) {
-            return;
-        }
 
         final MusicTxDigestId digestId = new MusicTxDigestId(MDBCUtils.generateUniqueKey(), -1);
         Callable<Boolean> insertDigestCallable =()-> {
@@ -2193,12 +2194,13 @@ public class MusicMixin implements MusicInterface {
 
     @Override
     public void relinquish(DatabasePartition partition) throws MDBCServiceException {
-        String ownerId = partition.getLockId();
+        String lockId = partition.getLockId();
         String rangeId = partition.getMRIIndex().toString();
-        if(ownerId==null||ownerId.isEmpty()||rangeId==null||rangeId.isEmpty()){
+        if(lockId==null||lockId.isEmpty()||rangeId==null||rangeId.isEmpty()){
             return;
         }
-        unlockKeyInMusic(musicRangeInformationTableName, rangeId, ownerId);
+        unlockKeyInMusic(musicRangeInformationTableName, rangeId, lockId);
+        partition.setLockId(null);
     }
 
     @Override
@@ -2206,7 +2208,9 @@ public class MusicMixin implements MusicInterface {
         if(lockId==null||lockId.isEmpty()||rangeId==null||rangeId.isEmpty()){
             return;
         }
+        
         unlockKeyInMusic(musicRangeInformationTableName, rangeId, lockId);
+        
     }
 
     /**
index 218993b..854eb5f 100644 (file)
@@ -367,12 +367,13 @@ public class OwnershipAndCheckpoint{
                         logger.warn("Locking failed, retrying",e);
                     }
                 }
+                // TODO look into updating the partition object with the latest lockId; 
                 if(owned){
                     toOwn.setOwn(node);
                     newLocks.put(uuidToOwn,result);
                 }
                 else{
-                   mi.relinquish(lockId, partition.getMRIIndex().toString());
+                    mi.relinquish(lockId,uuidToOwn.toString());
                     break;
                 }
             }
index 06ad252..a31a2a0 100644 (file)
@@ -96,7 +96,7 @@ public class QueryProcessor {
         try {
             sqlNode = getSqlParser(query).parseStmt();
         } catch (SqlParseException e) {
-            logger.error(EELFLoggerDelegate.errorLogger, "Unable to parse query: " + query +". " + e.getMessage());
+            logger.warn(EELFLoggerDelegate.errorLogger, "Unable to parse query: " + query + "; Falling back to Secondary basic parser",e);
             return basicStringParser(query, tables);
         }