Skip to content

Commit

Permalink
Reduce DUPLICATE_OUTPUT_STREAM future to write
Browse files Browse the repository at this point in the history
Move future completion into the only scope it was actually missing from
- getOutput for Write, rather than inducing all `put` calls into posts
to backplane via onPut with duplicates.
  • Loading branch information
werkt authored and 80degreeswest committed Jun 2, 2024
1 parent bb1f766 commit ece844a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/build/buildfarm/cas/cfc/CASFileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public void cancel() throws IOException {
}
}

Write newWrite(BlobWriteKey key, ListenableFuture<Long> future) {
Write newWrite(BlobWriteKey key, SettableFuture<Long> future) {
Write write =
new Write() {
CancellableOutputStream out = null;
Expand Down Expand Up @@ -1004,11 +1004,12 @@ public synchronized FeedbackOutputStream getOutput(
}
}
SettableFuture<Void> outClosedFuture = SettableFuture.create();
Digest digest = key.getDigest();
UniqueWriteOutputStream uniqueOut =
createUniqueWriteOutput(
out,
key.getCompressor(),
key.getDigest(),
digest,
UUID.fromString(key.getIdentifier()),
cancelled -> {
if (cancelled) {
Expand All @@ -1018,6 +1019,10 @@ public synchronized FeedbackOutputStream getOutput(
},
this::isComplete,
isReset);
if (uniqueOut.getPath() == null) {
// this is a duplicate output stream and the write is complete
future.set(key.getDigest().getSizeBytes());
}
commitOpenState(uniqueOut.delegate(), outClosedFuture);
return uniqueOut;
}
Expand Down Expand Up @@ -2637,9 +2642,6 @@ private CancellableOutputStream putImpl(
onInsert,
isReset);
if (out == DUPLICATE_OUTPUT_STREAM) {
log.log(Level.FINER, format("duplicate output stream, completing %s for %s", key, writeId));
writeWinner.get();
onInsert.run();
return null;
}
log.log(Level.FINER, format("entry %s is missing, downloading and populating", key));
Expand Down

0 comments on commit ece844a

Please sign in to comment.