/**
* 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
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;
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);
}
@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
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
@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);
}
/**
} 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;
newLocks.put(uuidToOwn,result);
}
else{
+ mi.relinquish(lockId, partition.getMRIIndex().toString());
break;
}
}