protected void createAndProposeNext()

in src/main/java/com/googlesource/gerrit/plugins/events/fsstore/UpdatableFileValue.java [178:204]


    protected void createAndProposeNext() throws IOException {
      if (!closed && !ours) {
        // In the default fast path (!closed && ours), we would not expect
        // it to be closed, so skip this check to get to the building faster.
        // Conversely, if not ours, a quick check here might allow us
        // to skip the slow building phase
        closed = Files.exists(upaths.closed);
      }
      if (!closed) {
        try (NextBuilder b =
            new NextBuilder(updatable.paths, updatable.serializer.fromGeneric(next))) { // Phase 3

          // Phase 4. Rename can only succeed if update/<uuid>/next/ is empty (desired) or
          // non-existent (not desired). The later case is detected after the move.
          Fs.tryAtomicMove(b.dir, upaths.next); // rename build/<tmp>/ -> update/<uuid>/next/
          // now there should be: update/<uuid>/next/closed/value(next)
        }

        // Do not use the result of the move to determine if it is closed.
        // The move result could provide false positives due to some filesystem
        // implementions allowing a second move to succeed after the transaction
        // has been finished and the first "closed" has been deleted under the
        // "delete" dir. Additionally, this check allows us to be able to detect
        // closes by other actors, not just ourselves.
        closed = Files.exists(upaths.closed);
      }
    }