Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW-53073: Allow Thread Interruption for WriteLockManager #1

Open
wants to merge 14 commits into
base: 2.7
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.iml
.idea/*
.DS_Store
*.class
*test.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
// - 526957 : Split the logging and trace messages
package org.eclipse.persistence.internal.helper;

import java.time.Duration;
import java.time.Instant;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.FetchGroupManager;
Expand Down Expand Up @@ -60,11 +64,13 @@
* @since 10.0.3
*/
public class WriteLockManager {
private static Logger logger = Logger.getLogger(WriteLockManager.class.getSimpleName());

// this will allow us to prevent a readlock thread from looping forever.
public static final int MAXTRIES = 10000;

public static final int MAX_WAIT = 600000; //10 mins
private static final int MAX_SECS_WAIT = 60; //1 minute

/* This attribute stores the list of threads that have had a problem acquiring locks */
/* the first element in this list will be the prevailing thread */
Expand All @@ -84,6 +90,7 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto
IdentityHashMap lockedObjects = new IdentityHashMap();
IdentityHashMap refreshedObjects = new IdentityHashMap();
try {
long startTimeInMillis = System.currentTimeMillis();
// if the descriptor has indirection for all mappings then wait as there will be no deadlock risks
CacheKey toWaitOn = acquireLockAndRelatedLocks(objectForClone, lockedObjects, refreshedObjects, cacheKey, descriptor, cloningSession);
int tries = 0;
Expand All @@ -98,7 +105,18 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto
toWaitOn.wait();// wait for lock on object to be released
}
} catch (InterruptedException ex) {
// Ignore exception thread should continue.
//https://jira.site1.hyperwallet.local/browse/HW-53073
//Custom change to allow thread interruptions for bad threads stuck in org.eclipse.persistence.internal.helper.WriteLockManager.acquireLocksForClone pattern
jportner-hw marked this conversation as resolved.
Show resolved Hide resolved
Long secondsElapsed = (System.currentTimeMillis() - startTimeInMillis) / 1000;

if (secondsElapsed >= MAX_SECS_WAIT) {
logger.log(Level.SEVERE, "Reached threshold to interrupt. Attempts: {0}, Time elapsed in seconds: {1}", new Object[]{tries,
secondsElapsed});
throw ConcurrencyException.waitWasInterrupted(ex.getMessage());
} else {
agupta-hw marked this conversation as resolved.
Show resolved Hide resolved
logger.log(Level.WARNING, "This is a custom eclipselink change to allow interrupts, it will not interrupt till 1 minute. Attempts: {0}, Time elapsed in seconds: {1}", new Object[]{tries,
secondsElapsed});
}
}
}
Object waitObject = toWaitOn.getObject();
Expand Down