Skip to content

Commit a5f2813

Browse files
Remote: Only waits for background tasks from remote execution. (bazelbuild#14752)
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 bazelbuild#14620. Closes bazelbuild#14634. PiperOrigin-RevId: 424296966 (cherry picked from commit 3836ad0) Co-authored-by: Chi Wang <[email protected]>
1 parent 60f757c commit a5f2813

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

@@ -1160,13 +1162,18 @@ public void uploadOutputs(RemoteAction action, SpawnResult spawnResult)
11601162
.subscribe(
11611163
new SingleObserver<ActionResult>() {
11621164
@Override
1163-
public void onSubscribe(@NonNull Disposable d) {}
1165+
public void onSubscribe(@NonNull Disposable d) {
1166+
backgroundTaskPhaser.register();
1167+
}
11641168

11651169
@Override
1166-
public void onSuccess(@NonNull ActionResult actionResult) {}
1170+
public void onSuccess(@NonNull ActionResult actionResult) {
1171+
backgroundTaskPhaser.arriveAndDeregister();
1172+
}
11671173

11681174
@Override
11691175
public void onError(@NonNull Throwable e) {
1176+
backgroundTaskPhaser.arriveAndDeregister();
11701177
reportUploadError(e);
11711178
}
11721179
});
@@ -1300,7 +1307,7 @@ public void shutdown() {
13001307
remoteCache.release();
13011308

13021309
try {
1303-
remoteCache.awaitTermination();
1310+
backgroundTaskPhaser.awaitAdvanceInterruptibly(backgroundTaskPhaser.arrive());
13041311
} catch (InterruptedException e) {
13051312
buildInterrupted.set(true);
13061313
remoteCache.shutdownNow();

0 commit comments

Comments
 (0)