aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Martella <arthur.martella.1@att.com>2019-05-30 09:46:02 -0400
committerArthur Martella <arthur.martella.1@att.com>2019-05-30 10:17:25 -0400
commit65b45cafb4dff93bef52e91f2ab3f2a772e4472e (patch)
tree5e5406bf1dcd89ad60633606b38c20b05b960c13
parent97fe11b3e90ead341cecae5365340962c3896dea (diff)
Don't create extra locks while claiming ownership
Issue-ID: MUSIC-402 Signed-off-by: Martella, Arthur <arthur.martella.1@att.com> Change-Id: I12b9ff80be0429ff7a9fc68074a3ca2ec133aee2
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java7
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java17
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java4
3 files changed, 19 insertions, 9 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
index fc8897f..67ee5ab 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
@@ -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;
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
index d934473..67d30ff 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
@@ -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);
}
/**
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
index c7a2b5b..218993b 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
@@ -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;
}
}