Add additional debugging info to group processing lock handling.

This commit is contained in:
Cody Henthorne 2024-07-29 12:37:40 -04:00
parent 585c8cd863
commit 8ca89d2024

View file

@ -19,7 +19,7 @@ public final class GroupsV2ProcessingLock {
private GroupsV2ProcessingLock() { private GroupsV2ProcessingLock() {
} }
private static final ReentrantLock lock = new ReentrantLock(); private static final GroupReentrantLock lock = new GroupReentrantLock();
@WorkerThread @WorkerThread
public static Closeable acquireGroupProcessingLock() throws GroupChangeBusyException { public static Closeable acquireGroupProcessingLock() throws GroupChangeBusyException {
@ -37,12 +37,12 @@ public final class GroupsV2ProcessingLock {
} }
@WorkerThread @WorkerThread
public static Closeable acquireGroupProcessingLock(long timeoutMs) throws GroupChangeBusyException { private static Closeable acquireGroupProcessingLock(long timeoutMs) throws GroupChangeBusyException {
ThreadUtil.assertNotMainThread(); ThreadUtil.assertNotMainThread();
try { try {
if (!lock.tryLock(timeoutMs, TimeUnit.MILLISECONDS)) { if (!lock.tryLock(timeoutMs, TimeUnit.MILLISECONDS)) {
throw new GroupChangeBusyException("Failed to get a lock on the group processing in the timeout period"); throw new GroupChangeBusyException("Failed to get a lock on the group processing in the timeout period. Owner: " + lock.getOwnerName());
} }
return lock::unlock; return lock::unlock;
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -50,4 +50,11 @@ public final class GroupsV2ProcessingLock {
throw new GroupChangeBusyException(e); throw new GroupChangeBusyException(e);
} }
} }
private static class GroupReentrantLock extends ReentrantLock {
String getOwnerName() {
Thread owner = super.getOwner();
return (owner != null) ? owner.getName() : "null";
}
}
} }