0 Replies Latest reply on Jun 16, 2017 6:05 AM by dalbani

    Extending expiration date of open-scoped node lock

    dalbani

      Hello,

       

      I've been trying to extend the expiration date of an open-scope node lock with Lock#refresh() but it doesn't seen to behave as expected.

      It seems that the expiration date is not affected by this call.

      My understanding is that the following code is triggered by Lock#refresh(): https://github.com/ModeShape/modeshape/blob/master/modeshape-jcr/src/main/java/org/modeshape/jcr/RepositoryLockManager.java#L759

      But no change related to the expiration date happens there.

      Yet the JCR spec says with regards to Lock#refresh():

      If this lock's time-to-live is governed by a timer, this method resets that timer so that the lock does not timeout and expire. If this lock's time-to-live is not governed by a timer, then this method has no effect.

       

      If I compare to another implementation like JackRabbit, I see a different implementation: https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java#L108

       

          /**
           * {@inheritDoc}
           * @throws LockException if this <code>Session</code> is not the lock holder
           * or if this <code>Lock</code> is not alive.
           */
          public void refresh() throws LockException, RepositoryException {
              if (!isLive()) {
                  info.throwLockException(
                          "Lock is not live any more",
                          (SessionImpl) node.getSession());
              } else if (!isLockOwningSession()) {
                  info.throwLockException(
                          "Session does not hold lock.",
                          (SessionImpl) node.getSession());
              } else {
                  // make sure the current session has sufficient privileges to refresh
                  // the lock.
                  SessionImpl session = (SessionImpl) node.getSession();
                  session.getAccessManager().checkPermission(
                          node.getPrimaryPath(), Permission.LOCK_MNGMT);
      
      
                  // Update the lock timeout
                  info.updateTimeoutTime();
              }
          }
      

       

      Where info.updateTimeoutTime() goes to https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java#L240

       

          /**
           * Updates the timeout time of this lock based on current time and
           * the timeout hint specified for this lock. The timeout time is always
           * rounded up.
           */
          public void updateTimeoutTime() {
              if (timeoutHint > 0 && timeoutHint <= MAXIMUM_TIMEOUT) {
                  long now = System.currentTimeMillis();
                  this.timeoutTime = now + timeoutHint * 1000;
              } else {
                  this.timeoutTime = Long.MAX_VALUE;
              }
          }
      

       

      So which implementation is correct here?