-
Notifications
You must be signed in to change notification settings - Fork 15
Add new getLockState() debugging endpoint #5302
Conversation
Allows for easier, more targetted debugging than would be possible with previous logCurrentState() endpoint
Generate changelog in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this is a best-effort debugging endpoint, broadly looks okay.
I have a few questions + refactoring suggestions.
@jeremyk-91 would appreciate +2 on this one.
Map<LockRequest, LockClient> requests = new HashMap<>(); | ||
outstandingLockRequestMultimap.forEach((client, request) -> { | ||
if (request.getLockDescriptors().contains(descriptor)) { | ||
requests.put(request, client); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map<LockRequest, LockClient> requests = new HashMap<>(); | |
outstandingLockRequestMultimap.forEach((client, request) -> { | |
if (request.getLockDescriptors().contains(descriptor)) { | |
requests.put(request, client); | |
} | |
}); | |
Map<LockRequest, LockClient> requests = KeyedStream.stream(outstandingLockRequestMultimap) | |
.filterEntries((client, request) -> request.getLockDescriptors().contains(descriptor)) | |
.mapEntries((client, request) -> Maps.immutableEntry(request, client)) | |
.collectToMap(); |
List<HeldLocksToken> heldLocks = new ArrayList<>(); | ||
heldLocksTokenMap.keySet().stream() | ||
.filter(token -> token.getLockDescriptors().contains(descriptor)) | ||
.forEach(heldLocks::add); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List<HeldLocksToken> heldLocks = new ArrayList<>(); | |
heldLocksTokenMap.keySet().stream() | |
.filter(token -> token.getLockDescriptors().contains(descriptor)) | |
.forEach(heldLocks::add); | |
List<HeldLocksToken> heldLocks = heldLocksTokenMap.keySet().stream() | |
.filter(token -> token.getLockDescriptors().contains(descriptor)) | |
.collect(Collectors.toList()); |
.versionId(Optional.ofNullable(request.getVersionId())) | ||
.requestingThread(request.getCreatingThreadName()) | ||
.build())); | ||
return lockState.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can extract util methods for above; these static methods could live in LockState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think factories for creating a LockHolder/LockRequester from the request and/or lock object would be nice, though requests.forEach(...) in the body here seems fine to me
.isWriteLocked(false) | ||
.isFrozen(false) | ||
.build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare a constant?
List<LockClient> lockHolders; | ||
if (readHolders.isEmpty()) { | ||
if (writeHolders == null) { | ||
lockHolders = ImmutableList.of(); | ||
} else { | ||
lockHolders = ImmutableList.of(writeHolders); | ||
} | ||
} else { | ||
lockHolders = readHolders; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract out method, maybe something like -
List<LockClient> lockHolders; | |
if (readHolders.isEmpty()) { | |
if (writeHolders == null) { | |
lockHolders = ImmutableList.of(); | |
} else { | |
lockHolders = ImmutableList.of(writeHolders); | |
} | |
} else { | |
lockHolders = readHolders; | |
} | |
private static List<LockClient> getLockClients(List<LockClient> readHolders, LockClient writeHolders) { | |
return readHolders.isEmpty() | |
? Optional.ofNullable(writeHolders).map(ImmutableList::of).orElseGet(ImmutableList::of) | |
: readHolders; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a lot of fanciness for not a lot of benefit, but either way's fine by me!
* -The logCurrentState tryLock() call times out after LOG_STATE_DEBUG_LOCK_WAIT_TIME_IN_MILLIS | ||
* and the call moves on to logCurrentStateInconsistent() | ||
*/ | ||
barrier.await(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment needs to be modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. On reread, it's not needed at all. removing
@@ -260,7 +260,7 @@ private synchronized void decrementReadCount(int clientIndex) { | |||
} | |||
} | |||
|
|||
private synchronized Iterable<Integer> getReadClients() { | |||
/* package */ synchronized Iterable<Integer> getReadClients() { | |||
if (readLockHolders == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we don't use the "package" comment anywhere else in this class
/* package */ LockServerSync getSync() { | ||
return sync; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we remove the package comment for uniformity. Also can we move the package-private method below public methods?
@Override | ||
public LockState getLockState(LockDescriptor lock) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this right? If so, can we have a comment to explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly makes sense, though I'm pretty sure RLSA needs to be different. I think @sudiksha27 had a number of good suggestions.
|
||
@Override | ||
public LockState getLockState(LockDescriptor lock) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely namespaceAgnosticLockRpcClient.getLockState(lock);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops!
.versionId(Optional.ofNullable(request.getVersionId())) | ||
.requestingThread(request.getCreatingThreadName()) | ||
.build())); | ||
return lockState.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think factories for creating a LockHolder/LockRequester from the request and/or lock object would be nice, though requests.forEach(...) in the body here seems fine to me
Updated! Let me know if there's anything else to do. Otherwise, would live to get this in time for the weekly release :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 let's merge this!
Released 0.307.2 |
Allows for easier, more targetted debugging than would be
possible with previous logCurrentState() endpoint