mbaedke commented on code in PR #2660:
URL: https://github.com/apache/jackrabbit-oak/pull/2660#discussion_r2664478410
##########
oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java:
##########
@@ -363,28 +366,31 @@ public boolean isCopyInProgress(LocalIndexFile file) {
* @param timeoutMillis
*/
public void waitForCopyCompletion(LocalIndexFile file, long timeoutMillis)
{
- final Monitor.Guard notCopyingGuard = new
Monitor.Guard(copyCompletionMonitor) {
- @Override
- public boolean isSatisfied() {
- return !isCopyInProgress(file);
- }
- };
long localLength = file.actualSize();
long lastLocalLength = localLength;
boolean notCopying = !isCopyInProgress(file);
while (!notCopying) {
+ final long deadline = System.nanoTime() +
TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
+ copyCompletionLock.lock();
try {
if (log.isDebugEnabled()) {
log.debug("Checking for copy completion of {} - {}",
file.getKey(), file.copyLog());
}
- notCopying = copyCompletionMonitor.enterWhen(notCopyingGuard,
timeoutMillis, TimeUnit.MILLISECONDS);
- if (notCopying) {
- copyCompletionMonitor.leave();
+ while (isCopyInProgress(file)) {
+ long remaining = deadline - System.nanoTime();
+ if (remaining <= 0) {
+ // timeout
+ break;
+ }
+ notCopyingCondition.awaitNanos(remaining);
Review Comment:
This whole nano calculation seems clumsy. Why not just
`notCopyingCondition.await(timeoutMillis, TimeUnit.MILLISECONDS)` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]