Skip to content

Commit

Permalink
HSEARCH-374 Fix a couple of race conditions on timeout manager
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelbernard committed Nov 5, 2010
1 parent 1a069fb commit 6557155
Showing 1 changed file with 25 additions and 4 deletions.
Expand Up @@ -41,12 +41,25 @@ private Long getTimeoutLeft(long factor) {
return null;
}
else {
long left = timeout - (System.nanoTime() - start);
final long currentTime = System.nanoTime();
if ( isTimedOut( currentTime ) ) {
//0 means no limit so we return the lowest possible value
return 1l;
}
long left = timeout - ( currentTime - start);
long result;
if ( left % factor == 0 ) {
return left / factor;
result = left / factor;
}
else {
return (left / factor) + 1;
result = (left / factor) + 1;
}
if ( result <= 0 ) {
//0 means no limit so we return the lowest possible value
return 1l;
}
else {
return result;
}
}
}
Expand All @@ -60,12 +73,20 @@ public void setBestEffort(boolean bestEffort) {
}

public boolean isTimedOut() {
if ( timeout == null ) return false;
if ( timedOut ) {
return true;
}
return isTimedOut( System.nanoTime() );
}

private boolean isTimedOut(long currentTime) {
if ( timeout == null ) return false;
if ( timedOut ) {
return true;
}
else {
final long elapsedTime = System.nanoTime() - start;
final long elapsedTime = currentTime - start;
timedOut = elapsedTime > timeout;
if ( ! bestEffort ) {
throw new QueryTimeoutException(
Expand Down

0 comments on commit 6557155

Please sign in to comment.