Skip to content

Commit

Permalink
DeadLock detection diagnostic - WriteLockManager.acquireLocksForClone…
Browse files Browse the repository at this point in the history
… message change

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Feb 27, 2025
1 parent afb6102 commit 751b8b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ protected String createInformationAboutAllResourcesAcquiredAndDeferredByAllThrea
allRelevantThreads.addAll(concurrencyManagerState.getUnifiedMapOfThreadsStuckTryingToAcquireWriteLock().keySet());
allRelevantThreads.addAll(concurrencyManagerState.getDeferredLockManagerMapClone().keySet());
allRelevantThreads.addAll(concurrencyManagerState.getReadLockManagerMapClone().keySet());
allRelevantThreads.addAll(concurrencyManagerState.getMapThreadToWaitOnAcquireReadLockClone().keySet());

// (b) print information about all threads
StringWriter writer = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -170,7 +170,7 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto
// to indicate that the current thread is now stuck trying to acquire some arbitrary
// cache key for writing
lastCacheKeyWeNeededToWaitToAcquire = toWaitOn;
lastCacheKeyWeNeededToWaitToAcquire.putThreadAsWaitingToAcquireLockForWriting(currentThread, ACQUIRE_LOCK_FOR_CLONE_METHOD_NAME);
lastCacheKeyWeNeededToWaitToAcquire.putThreadAsWaitingToAcquireLockForReading(currentThread, ACQUIRE_LOCK_FOR_CLONE_METHOD_NAME);

// Since we know this one of those methods that can appear in the dead locks
// we threads frozen here forever inside of the wait that used to have no timeout
Expand Down Expand Up @@ -206,7 +206,7 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto
throw ConcurrencyException.maxTriesLockOnCloneExceded(objectForClone);
} finally {
if (lastCacheKeyWeNeededToWaitToAcquire != null) {
lastCacheKeyWeNeededToWaitToAcquire.removeThreadNoLongerWaitingToAcquireLockForWriting(currentThread);
lastCacheKeyWeNeededToWaitToAcquire.removeThreadNoLongerWaitingToAcquireLockForReading(currentThread);
}
if (!successful) {//did not acquire locks but we are exiting
for (Iterator lockedList = lockedObjects.values().iterator(); lockedList.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
import org.eclipse.persistence.testing.models.jpa.deadlock.diagnostic.CacheDeadLockDetectionDetail;
import org.eclipse.persistence.testing.models.jpa.deadlock.diagnostic.CacheDeadLockDetectionMaster;
import org.eclipse.persistence.testing.models.jpa.deadlock.diagnostic.DeadLockDiagnosticTableCreator;
import org.junit.Assert;

import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CacheDeadLockManagersTest extends JUnitTestCase {

Expand Down Expand Up @@ -120,6 +117,9 @@ public void testWriteLockManagerAcquireLocksForClone() {
Map map = writeLockManager.acquireLocksForClone(result, descriptor, cacheKey, serverSession);
} catch (Exception e) {
assertEquals(2, logWrapper.getMessageCount(WriteLockManager.class.getName() + ".acquireLocksForClone"));
//WriteLockManager.acquireLocksForClone acquire read lock, not write lock -> not any "...acquire writing.." message
assertEquals(0, logWrapper.getMessageCount("waitingOnAcquireWritingCacheKey: true waiting to acquire writing: --- CacheKey (org.eclipse.persistence.testing.models.jpa.deadlock.diagnostic.CacheDeadLockDetectionMaster): (primaryKey: 1)"));
assertEquals(1, logWrapper.getMessageCount("Waiting to acquire (read lock): --- CacheKey (org.eclipse.persistence.testing.models.jpa.deadlock.diagnostic.CacheDeadLockDetectionMaster): (primaryKey: 1)"));
} finally {
if (em != null) {
if (em.isOpen()) {
Expand Down

0 comments on commit 751b8b6

Please sign in to comment.