keith-turner commented on code in PR #4785:
URL: https://github.com/apache/accumulo/pull/4785#discussion_r1706098227


##########
core/src/main/java/org/apache/accumulo/core/fate/ZooStore.java:
##########
@@ -164,8 +164,10 @@ public long reserve() {
             }
 
             if (deferred.containsKey(tid)) {
-              if (deferred.get(tid).elapsed().compareTo(Duration.ZERO) > 0) {
-                deferred.remove(tid);
+              long deferredTime = deferred.get(tid);
+              long currentTime = System.nanoTime();
+              if (currentTime >= deferredTime) {

Review Comment:
   What do think of adding the following to Timer?
   
   ```java
   
    private Timer(long offset) {
       this.startNanos = System.nanoTime() + offset;
     }
   
   /**
    *  Creates a timer with an offset from the current time.
     */
   public static startNew(Duration offset){
       return new Timer(offset.toNanos());
   }
   ```
   
   If we had that then could track timers and create them with the offset.  
This would cause the elapsed time to be negative until the offset is reached.
   
   ```java
   deferred.put(tid, Time.startNow(deferTime));
   ```
   
   Once the elapsed time for a timer is no longer negative then we know its 
expired
   
   ```java
   Timer deferredTime = deferred.get(tid);
   if(deferredTime.hasElapsed(0, TimeUntil.MILLIS) {
      // this timer has reached the offset
   }
   ```
   
   For the case of finding the minimum sleep time could do the following.
   
   ```
              // A timer with a negative elapsed time has not reached the 
offset and still has time to sleep.  A timer with a positive elapsed time has 
surpassed its offset and does not need to sleep.
               long maxElapsed = deferred.values().stream()
                     .mapToLong(timer -> 
timer.elapsed(MILLIS)).max().orElseThrow();
               if(maxElapsed < 0) {
                   this.wait(maxElapsed * -1);
               }
   ```
   
   



-- 
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]

Reply via email to