Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[8.1.0] Use Single.using instead of onError/onSuccess for async uploads #25251

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import io.grpc.Status.Code;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.SingleObserver;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -160,6 +157,7 @@
import java.util.concurrent.Phaser;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -1794,45 +1792,33 @@ public void uploadOutputs(RemoteAction action, SpawnResult spawnResult, Runnable

if (remoteOptions.remoteCacheAsync
&& !action.getSpawn().getResourceOwner().mayModifySpawnOutputsAfterExecution()) {
Single.using(
combinedCache::retain,
combinedCache ->
buildUploadManifestAsync(action, spawnResult)
.flatMap(
manifest ->
manifest.uploadAsync(
action.getRemoteActionExecutionContext(),
combinedCache,
reporter)),
CombinedCache::release)
.subscribeOn(scheduler)
.subscribe(
new SingleObserver<ActionResult>() {
long startTime = 0;

@Override
public void onSubscribe(@NonNull Disposable d) {
backgroundTaskPhaser.register();
startTime = Profiler.nanoTimeMaybe();
}

@Override
public void onSuccess(@NonNull ActionResult actionResult) {
Profiler.instance()
.completeTask(startTime, ProfilerTask.UPLOAD_TIME, "upload outputs");
backgroundTaskPhaser.arriveAndDeregister();
onUploadComplete.run();
}

@Override
public void onError(@NonNull Throwable e) {
Profiler.instance()
.completeTask(startTime, ProfilerTask.UPLOAD_TIME, "upload outputs");
backgroundTaskPhaser.arriveAndDeregister();
reportUploadError(e);
onUploadComplete.run();
}
});
AtomicLong startTime = new AtomicLong();
var unused =
Single.using(
() -> {
backgroundTaskPhaser.register();
CombinedCache cache = combinedCache.retain();
startTime.set(Profiler.nanoTimeMaybe());
return cache;
},
combinedCache ->
buildUploadManifestAsync(action, spawnResult)
.flatMap(
manifest ->
manifest.uploadAsync(
action.getRemoteActionExecutionContext(),
combinedCache,
reporter)),
cacheResource -> {
Profiler.instance()
.completeTask(startTime.get(), ProfilerTask.UPLOAD_TIME, "upload outputs");
backgroundTaskPhaser.arriveAndDeregister();
onUploadComplete.run();
cacheResource.release();
},
/* eager= */ false)
.subscribeOn(scheduler)
.subscribe(result -> {}, this::reportUploadError);
} else {
try (SilentCloseable c =
Profiler.instance().profile(ProfilerTask.UPLOAD_TIME, "upload outputs")) {
Expand Down
Loading