Skip to content

Commit

Permalink
Store lastBuildId and compare it with the one in StartBuildResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre authored and moroten committed Apr 16, 2024
1 parent bfba8d7 commit a0b896b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class BazelOutputService implements OutputService {
private final boolean verboseFailures;
private final RemoteRetrier retrier;
private final ReferenceCountedChannel channel;
@Nullable private final String lastBuildId;

@Nullable private String buildId;
@Nullable private PathFragment outputPathTarget;
Expand All @@ -100,7 +101,8 @@ public BazelOutputService(
String remoteOutputServiceOutputPathPrefix,
boolean verboseFailures,
RemoteRetrier retrier,
ReferenceCountedChannel channel) {
ReferenceCountedChannel channel,
@Nullable String lastBuildId) {
this.outputBaseId = DigestUtil.hashCodeToString(md5().hashString(outputBase.toString(), UTF_8));
this.execRootSupplier = execRootSupplier;
this.outputPathSupplier = outputPathSupplier;
Expand All @@ -111,6 +113,7 @@ public BazelOutputService(
this.verboseFailures = verboseFailures;
this.retrier = retrier;
this.channel = channel;
this.lastBuildId = lastBuildId;
}

public void shutdown() {
Expand Down Expand Up @@ -244,7 +247,12 @@ public ModifiedFileSet startBuild(
outputPathTarget = constructOutputPathTarget(outputPathPrefix, response);
prepareOutputPath(outputPath, outputPathTarget);

if (finalizeActions) {
if (finalizeActions && response.hasInitialOutputPathContents()) {
var initialOutputPathContents = response.getInitialOutputPathContents();
if (!initialOutputPathContents.getBuildId().equals(lastBuildId)) {
return ModifiedFileSet.EVERYTHING_DELETED;
}

// TODO(chiwang): Handle StartBuildResponse.initial_output_path_contents
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public final class RemoteModule extends BlazeModule {
@Nullable private TempPathGenerator tempPathGenerator;
@Nullable private BlockWaitingModule blockWaitingModule;
@Nullable private RemoteOutputChecker remoteOutputChecker;
@Nullable private String lastBuildId;

private ChannelFactory channelFactory =
new ChannelFactory() {
Expand Down Expand Up @@ -471,7 +472,8 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
remoteOptions.remoteOutputServiceOutputPathPrefix,
verboseFailures,
retrier,
bazelOutputServiceChannel);
bazelOutputServiceChannel,
lastBuildId);
} else {
outputService = new RemoteOutputService(env);
}
Expand Down Expand Up @@ -917,6 +919,8 @@ public void afterCommand() {
() -> afterCommandTask(actionContextProviderRef, tempPathGeneratorRef, rpcLogFileRef));
}

lastBuildId = Preconditions.checkNotNull(env).getCommandId().toString();

buildEventArtifactUploaderFactoryDelegate.reset();
repositoryRemoteExecutorFactoryDelegate.reset();
remoteDownloaderSupplier.set(null);
Expand Down

0 comments on commit a0b896b

Please sign in to comment.