public long spinIncrement()

in src/main/java/com/googlesource/gerrit/plugins/events/fsstore/FsSequence.java [53:82]


  public long spinIncrement(long maxTries) throws IOException {
    long tries = 0;
    for (; tries < maxTries; tries++) {
      try (UpdateBuilder b = new UpdateBuilder(paths)) {
        for (; tries < maxTries; tries++) {
          UniqueUpdate update = null;
          // Phase 1
          if (Fs.tryAtomicMove(b.dir, paths.update)) { // rename build/<tmp>/ -> update/
            // now there should be: update/<uuid>/
            update = new UniqueUpdate(b.uuid, true, maxTries); // Advances through phases 2 - 6
          } else {
            update = (UniqueUpdate) completeOngoing(maxTries);
          }
          if (update != null) {
            tries += update.tries - 1;
            if (update.myCommit) {
              spun(tries);
              return update.next;
            }
            if (update.ours && update.finished) {
              break; // usurped -> outer loop can make a new transaction
            }
          }
        }
      }
    }
    spun(tries - 1);
    throw new IOException(
        "Cannot increment sequence file " + path + " after " + maxTries + " tries.");
  }