core/src/main/java/com/orientechnologies/orient/core/metadata/sequence/OSequenceCached.java
protected long nextWithNewCurrentValue(long currentValue, boolean executeViaDistributed)
      throws OSequenceLimitReachedException, ODatabaseException {
    if (!executeViaDistributed) {
      //we don't want synchronization on whole method, because called with executeViaDistributed == true
      //will later call nextWithNewCurrentValue with parameter executeViaDistributed == false
      //and that will cause deadlock
      synchronized (this) {
        cacheStart = currentValue;
        return nextWork();
      }
    } else {
      try{
        return sendSequenceActionSetAndNext(currentValue);
      }
      catch (InterruptedException | ExecutionException exc){
        OLogManager.instance().error(this, exc.getMessage(), exc, (Object[]) null);
        throw new ODatabaseException(exc.getMessage());
      }
    }
  }
protected long nextWithNewCurrentValue(long currentValue, boolean executeViaDistributed)
      throws OSequenceLimitReachedException, ODatabaseException {
    if (!executeViaDistributed) {
      //we don't want synchronization on whole method, because called with executeViaDistributed == true
      //will later call nextWithNewCurrentValue with parameter executeViaDistributed == false
      //and that will cause deadlock
      synchronized (this) {
        cacheStart = currentValue;
        return nextWork();
      }
    } else {
      try{
        return sendSequenceActionSetAndNext(currentValue);
      }
      catch (InterruptedException | ExecutionException exc){
        OLogManager.instance().error(this, exc.getMessage(), exc, (Object[]) null);
        throw new ODatabaseException(exc.getMessage());
      }
    }
  }
first set new current value then call next