Skip to content

Commit 3836ad0

Browse files
coeuvrecopybara-github
authored andcommitted
Remote: Only waits for background tasks from remote execution.
We added the block waiting behaviour after each command in remote module to wait for background uploads when introducing async upload. However, not all background uploads should be waited, e.g. uploads from BES module but with flag `--bes_upload_mode=fully_async`. This PR updates remote module so that only uploads initiated by remote module are waited after the command. This also enable us to implement something like `--remote_upload_mode=fully_async` in the future. Fixes #14620. Closes #14634. PiperOrigin-RevId: 424296966
1 parent 621649d commit 3836ad0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
import java.util.TreeSet;
143143
import java.util.concurrent.ConcurrentLinkedQueue;
144144
import java.util.concurrent.Executor;
145+
import java.util.concurrent.Phaser;
145146
import java.util.concurrent.atomic.AtomicBoolean;
146147
import javax.annotation.Nullable;
147148

@@ -164,6 +165,7 @@ public class RemoteExecutionService {
164165
@Nullable private final Path captureCorruptedOutputsDir;
165166
private final Cache<Object, MerkleTree> merkleTreeCache;
166167
private final Set<String> reportedErrors = new HashSet<>();
168+
private final Phaser backgroundTaskPhaser = new Phaser(1);
167169

168170
private final Scheduler scheduler;
169171

@@ -1162,13 +1164,18 @@ public void uploadOutputs(RemoteAction action, SpawnResult spawnResult)
11621164
.subscribe(
11631165
new SingleObserver<ActionResult>() {
11641166
@Override
1165-
public void onSubscribe(@NonNull Disposable d) {}
1167+
public void onSubscribe(@NonNull Disposable d) {
1168+
backgroundTaskPhaser.register();
1169+
}
11661170

11671171
@Override
1168-
public void onSuccess(@NonNull ActionResult actionResult) {}
1172+
public void onSuccess(@NonNull ActionResult actionResult) {
1173+
backgroundTaskPhaser.arriveAndDeregister();
1174+
}
11691175

11701176
@Override
11711177
public void onError(@NonNull Throwable e) {
1178+
backgroundTaskPhaser.arriveAndDeregister();
11721179
reportUploadError(e);
11731180
}
11741181
});
@@ -1302,7 +1309,7 @@ public void shutdown() {
13021309
remoteCache.release();
13031310

13041311
try {
1305-
remoteCache.awaitTermination();
1312+
backgroundTaskPhaser.awaitAdvanceInterruptibly(backgroundTaskPhaser.arrive());
13061313
} catch (InterruptedException e) {
13071314
buildInterrupted.set(true);
13081315
remoteCache.shutdownNow();

0 commit comments

Comments
 (0)