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

L2 Cache Deadlock Prevention #2270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public void releaseDeferredLock() throws ConcurrencyException {
throw ConcurrencyException.waitWasInterrupted(interrupted.getMessage());
}
}
} catch (Error error) {
} catch (Error | Exception error) {
if (!releaseAllLocksAquiredByThreadAlreadyPerformed) {
THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS.remove(currentThread);
AbstractSessionLog.getLog().logThrowable(SessionLog.SEVERE, SessionLog.CACHE, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,47 @@ protected Object getObjectForMerge(MergeManager mergeManager, AbstractSession se
CacheKey cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, descriptor.getJavaClass(), descriptor, true);
if (cacheKey != null) {
if (cacheKey.acquireReadLockNoWait()) {
domainObject = cacheKey.getObject();
cacheKey.releaseReadLock();
try {
domainObject = cacheKey.getObject();
} catch (Exception exception) {
exception.printStackTrace();
}
finally {
cacheKey.releaseReadLock();
}
} else {
if (!mergeManager.isTransitionedToDeferredLocks()) {
session.getIdentityMapAccessorInstance().getWriteLockManager().transitionToDeferredLocks(mergeManager);
}
cacheKey.acquireDeferredLock();
domainObject = cacheKey.getObject();
int tries = 0;
while (domainObject == null) {
++tries;
if (tries > MAX_TRIES){
session.getParent().log(SessionLog.SEVERE, SessionLog.CACHE, "entity_not_available_during_merge", new Object[]{descriptor.getJavaClassName(), cacheKey.getKey(), Thread.currentThread().getName(), cacheKey.getActiveThread()});
break;
}
synchronized (cacheKey) {
if (cacheKey.isAcquired()) {
try {
cacheKey.wait(10);
} catch (InterruptedException e) {
//ignore and return
try {
domainObject = cacheKey.getObject();
int tries = 0;
while (domainObject == null) {
++tries;
if (tries > MAX_TRIES){
if (session.getParent() != null) {
session.getParent().log(SessionLog.SEVERE, SessionLog.CACHE, "entity_not_available_during_merge", new Object[]{descriptor.getJavaClassName(), cacheKey.getKey(), Thread.currentThread().getName(), cacheKey.getActiveThread()});
}
break;
}
synchronized (cacheKey) {
if (cacheKey.isAcquired()) {
try {
cacheKey.wait(10);
} catch (InterruptedException e) {
//ignore and return
}
}
domainObject = cacheKey.getObject();
}
domainObject = cacheKey.getObject();
}
} catch (Exception exception) {
exception.printStackTrace();
}
finally {
cacheKey.releaseDeferredLock();
}
cacheKey.releaseDeferredLock();
}
} else {
domainObject = mergeManager.registerExistingObjectOfReadOnlyClassInNestedTransaction(getUnitOfWorkClone(), descriptor, session);
Expand Down
Loading