aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
diff options
context:
space:
mode:
authorArthur Martella <arthur.martella.1@att.com>2019-09-27 16:38:37 -0400
committerArthur Martella <arthur.martella.1@att.com>2019-09-27 16:54:20 -0400
commit3c1bd98f91094be3b9a3484e4afba0b29f621b40 (patch)
tree121683c61a981d7708c95964dc1d7a1f58b378c9 /mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
parent524904eaedd84201ae008c9098aebcaa69181d14 (diff)
Deadlock detection and recovery with new Music version
Update MDBC to new Music version Fix errors caused by update Deadlock detection and recovery Replaces improperly stacked commits at https://gerrit.onap.org/r/c/music/mdbc/+/96357/2 Issue-ID: MUSIC-502 Signed-off-by: Martella, Arthur <arthur.martella.1@att.com> Change-Id: I96b87ba73b811a672e03895e0124d78d9bf409b1
Diffstat (limited to 'mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java')
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java29
1 files changed, 24 insertions, 5 deletions
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 00180a0..ec32210 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
@@ -27,9 +27,11 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.music.exceptions.MDBCServiceException;
+import org.onap.music.exceptions.MusicDeadlockException;
import org.onap.music.logging.EELFLoggerDelegate;
import org.onap.music.mdbc.DatabasePartition;
import org.onap.music.mdbc.Range;
+import org.onap.music.mdbc.Utils;
import org.onap.music.mdbc.mixins.DBInterface;
import org.onap.music.mdbc.mixins.LockRequest;
import org.onap.music.mdbc.mixins.LockResult;
@@ -275,8 +277,9 @@ public class OwnershipAndCheckpoint{
* @param r
* @param partitionIndex
* @param index
+ * @throws MDBCServiceException
*/
- private void updateCheckpointLocations(MusicInterface mi, DBInterface dbi, Range r, UUID partitionIndex, MusicTxDigestId txdigest) {
+ private void updateCheckpointLocations(MusicInterface mi, DBInterface dbi, Range r, UUID partitionIndex, MusicTxDigestId txdigest) throws MDBCServiceException {
dbi.updateCheckpointLocations(r, Pair.of(partitionIndex, txdigest.index));
mi.updateCheckpointLocations(r, Pair.of(partitionIndex, txdigest.index));
}
@@ -322,7 +325,11 @@ public class OwnershipAndCheckpoint{
*/
public OwnershipReturn own(MusicInterface mi, Set<Range> ranges,
DatabasePartition currPartition, UUID opId, SQLOperationType lockType) throws MDBCServiceException {
-
+ return own(mi, ranges, currPartition, opId, lockType, null);
+ }
+
+ public OwnershipReturn own(MusicInterface mi, Set<Range> ranges,
+ DatabasePartition currPartition, UUID opId, SQLOperationType lockType, String ownerId) throws MDBCServiceException {
if (ranges == null || ranges.isEmpty()) {
return null;
}
@@ -342,7 +349,19 @@ public class OwnershipAndCheckpoint{
while ( (toOwn.isDifferent(currentlyOwn) || !currentlyOwn.isOwned() ) &&
!timeout(opId)
) {
- takeOwnershipOfDag(mi, currPartition, opId, locksForOwnership, toOwn, lockType);
+ try {
+ takeOwnershipOfDag(mi, currPartition, opId, locksForOwnership, toOwn, lockType, ownerId);
+ } catch (MDBCServiceException e) {
+ MusicDeadlockException de = Utils.getDeadlockException(e);
+ if (de!=null) {
+// System.out.println("IN O&C.OWN, DETECTED DEADLOCK, REMOVING " + currPartition + ", RELEASING " + locksForOwnership);
+ locksForOwnership.remove(currPartition.getMRIIndex());
+ mi.releaseLocks(locksForOwnership);
+ stopOwnershipTimeoutClock(opId);
+ logger.error("Error when owning a range: Deadlock detected");
+ }
+ throw e;
+ }
currentlyOwn=toOwn;
//TODO instead of comparing dags, compare rows
rangesToOwnRows = extractRowsForRange(mi, rangesToOwn, false);
@@ -373,7 +392,7 @@ public class OwnershipAndCheckpoint{
* @throws MDBCServiceException
*/
private void takeOwnershipOfDag(MusicInterface mi, DatabasePartition partition, UUID opId,
- Map<UUID, LockResult> ownershipLocks, Dag toOwn, SQLOperationType lockType) throws MDBCServiceException {
+ Map<UUID, LockResult> ownershipLocks, Dag toOwn, SQLOperationType lockType, String ownerId) throws MDBCServiceException {
while(toOwn.hasNextToOwn()){
DagNode node = toOwn.nextToOwn();
@@ -394,7 +413,7 @@ public class OwnershipAndCheckpoint{
} else {
LockRequest request = new LockRequest(uuidToOwn,
new ArrayList<>(node.getRangeSet()), lockType);
- String lockId = mi.createLock(request);
+ String lockId = mi.createLock(request, ownerId);
LockResult result = null;
boolean owned = false;
while(!owned && !timeout(opId)){