forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.1.0] Handle remote cache eviction when uploading inputs for remote…
… actions. (bazelbuild#17605) * Extract code for cleaning stale state when remote CAS evicted blobs into another class. PiperOrigin-RevId: 512049304 Change-Id: I87e9e6bcd4d4c4d8be27be13cfb8ba70b199b6e6 * Handle remote cache eviction when uploading inputs for remote actions. Previously, we handle remote cache eviction when downloading inputs for local actions. However, it's possible that when Bazel need to re-execute an remote action, it detected that some inputs are missing from remote CAS. In this case, Bazel will try to upload inputs by reading from local filesystem. Since the inputs were generated remotely, not downloaded and evicted remotely, the upload will fail with FileNotFoundException. This CL changes the code to correctly handles above case by reading through ActionFS when uploading inputs and propagate CacheNotFoundException. Related to bazelbuild#16660. PiperOrigin-RevId: 512568547 Change-Id: I3a28cadbb6285fa3727e1603f37abf8843c093c9 * Fix tests --------- Co-authored-by: kshyanashree <109167932+kshyanashree@users.noreply.github.com>
- Loading branch information
Showing
28 changed files
with
452 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/google/devtools/build/lib/remote/LeaseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2023 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.remote; | ||
|
||
import com.google.devtools.build.lib.actions.Action; | ||
import com.google.devtools.build.lib.actions.ActionCacheUtils; | ||
import com.google.devtools.build.lib.actions.ActionInput; | ||
import com.google.devtools.build.lib.actions.ActionLookupData; | ||
import com.google.devtools.build.lib.actions.ActionLookupValue; | ||
import com.google.devtools.build.lib.actions.Artifact; | ||
import com.google.devtools.build.lib.actions.cache.ActionCache; | ||
import com.google.devtools.build.skyframe.MemoizingEvaluator; | ||
import java.util.HashMap; | ||
import java.util.Set; | ||
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; | ||
|
||
public LeaseService(MemoizingEvaluator memoizingEvaluator, @Nullable ActionCache actionCache) { | ||
this.memoizingEvaluator = memoizingEvaluator; | ||
this.actionCache = actionCache; | ||
} | ||
|
||
/** Clean up internal state when files are evicted from remote CAS. */ | ||
public void handleMissingInputs(Set<ActionInput> missingActionInputs) { | ||
if (missingActionInputs.isEmpty()) { | ||
return; | ||
} | ||
|
||
var actions = new HashMap<ActionLookupData, Action>(); | ||
|
||
try { | ||
for (ActionInput actionInput : missingActionInputs) { | ||
if (actionInput instanceof Artifact.DerivedArtifact) { | ||
Artifact.DerivedArtifact output = (Artifact.DerivedArtifact) actionInput; | ||
ActionLookupData actionLookupData = output.getGeneratingActionKey(); | ||
var actionLookupValue = | ||
memoizingEvaluator.getExistingValue(actionLookupData.getActionLookupKey()); | ||
if (actionLookupValue instanceof ActionLookupValue) { | ||
Action action = | ||
((ActionLookupValue) actionLookupValue) | ||
.getAction(actionLookupData.getActionIndex()); | ||
actions.put(actionLookupData, action); | ||
} | ||
} | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
|
||
if (!actions.isEmpty()) { | ||
var actionKeys = actions.keySet(); | ||
memoizingEvaluator.delete(key -> key instanceof ActionLookupData && actionKeys.contains(key)); | ||
|
||
if (actionCache != null) { | ||
for (var action : actions.values()) { | ||
ActionCacheUtils.removeCacheEntry(actionCache, action); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.