Skip to content

Commit

Permalink
[7.4.0] Lazily get action cache in lease service. (#23553)
Browse files Browse the repository at this point in the history
At construction time, the action cache is not loaded so it's always
`null`. Change it to lazily get the action cache when cleaning up it.

Fixes #22220.

PiperOrigin-RevId: 672522144
Change-Id: I2de8b33ab78c04a690b17cd261d18d17f8b292ab

Commit
9187a7e

Co-authored-by: Googler <chiwang@google.com>
  • Loading branch information
bazel-io and coeuvre authored Sep 9, 2024
1 parent d85b972 commit 293c131
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@
import com.google.devtools.build.lib.skyframe.TreeArtifactValue;
import com.google.devtools.build.skyframe.MemoizingEvaluator;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import javax.annotation.Nullable;

/** A lease service that manages the lease of remote blobs. */
public class LeaseService {
private final MemoizingEvaluator memoizingEvaluator;
@Nullable private final ActionCache actionCache;
private final Supplier<ActionCache> actionCacheSupplier;
private final AtomicBoolean leaseExtensionStarted = new AtomicBoolean(false);
@Nullable LeaseExtension leaseExtension;
private final AtomicBoolean hasMissingActionInputs = new AtomicBoolean(false);

public LeaseService(
MemoizingEvaluator memoizingEvaluator,
@Nullable ActionCache actionCache,
Supplier<ActionCache> actionCacheSupplier,
@Nullable LeaseExtension leaseExtension) {
this.memoizingEvaluator = memoizingEvaluator;
this.actionCache = actionCache;
this.actionCacheSupplier = actionCacheSupplier;
this.leaseExtension = leaseExtension;
}

Expand Down Expand Up @@ -97,6 +98,7 @@ private void handleMissingInputs() {
return false;
});

var actionCache = actionCacheSupplier.get();
if (actionCache != null) {
actionCache.removeIf(
entry -> !entry.getOutputFiles().isEmpty() || !entry.getOutputTrees().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ public void executorInit(CommandEnvironment env, BuildRequest request, ExecutorB
var leaseService =
new LeaseService(
env.getSkyframeExecutor().getEvaluator(),
env.getBlazeWorkspace().getPersistentActionCache(),
() -> env.getBlazeWorkspace().getPersistentActionCache(),
leaseExtension);
env.getEventBus().register(leaseService);

Expand Down

0 comments on commit 293c131

Please sign in to comment.