manifest_key = hash.digest();
- const auto manifest_path =
- ctx.storage.get(*manifest_key, core::CacheEntryType::manifest);
+ auto manifest_path = ctx.storage.get(*manifest_key,
+ core::CacheEntryType::manifest,
+ storage::Storage::Mode::primary_only);
if (manifest_path) {
LOG("Looking for result key in {}", *manifest_path);
LOG_RAW("Did not find result key in manifest");
}
}
+ // Check secondary storage if not found in primary
+ if (!result_key) {
+ manifest_path = ctx.storage.get(*manifest_key,
+ core::CacheEntryType::manifest,
+ storage::Storage::Mode::secondary_only);
+ if (manifest_path) {
+ LOG("Looking for result key in fetched secondary manifest {}",
+ *manifest_path);
+ MTR_BEGIN("manifest", "secondary_manifest_get");
+ try {
+ const auto manifest = read_manifest(*manifest_path);
+ result_key = manifest.look_up_result_digest(ctx);
+ } catch (const core::Error& e) {
+ LOG(
+ "Failed to look up result key in {}: {}", *manifest_path, e.what());
+ }
+ MTR_END("manifest", "secondary_manifest_get");
+ if (result_key) {
+ LOG_RAW("Got result key from fetched secondary manifest");
+ } else {
+ LOG_RAW("Did not find result key in fetched secondary manifest");
+ }
+ }
+ }
} else if (ctx.args_info.arch_args.empty()) {
const auto digest = get_result_key_from_cpp(ctx, preprocessor_args, hash);
if (!digest) {
}
std::optional<std::string>
-Storage::get(const Digest& key, const core::CacheEntryType type)
+Storage::get(const Digest& key,
+ const core::CacheEntryType type,
+ const Mode mode)
{
MTR_SCOPE("storage", "get");
- auto path = primary.get(key, type);
- primary.increment_statistic(path ? core::Statistic::primary_storage_hit
- : core::Statistic::primary_storage_miss);
- if (path) {
- if (m_config.reshare()) {
- // Temporary optimization until primary storage API has been refactored to
- // pass data via memory instead of files.
- const bool should_put_in_secondary_storage =
- std::any_of(m_secondary_storages.begin(),
- m_secondary_storages.end(),
- [](const auto& entry) { return !entry->config.read_only; });
- if (should_put_in_secondary_storage) {
- std::string value;
- try {
- value = Util::read_file(*path);
- } catch (const core::Error& e) {
- LOG("Failed to read {}: {}", *path, e.what());
- return path; // Don't indicate failure since primary storage was OK.
+ if (mode != Mode::secondary_only) {
+ const auto path = primary.get(key, type);
+ primary.increment_statistic(path ? core::Statistic::primary_storage_hit
+ : core::Statistic::primary_storage_miss);
+ if (path) {
+ if (m_config.reshare()) {
+ // Temporary optimization until primary storage API has been refactored
+ // to pass data via memory instead of files.
+ const bool should_put_in_secondary_storage = std::any_of(
+ m_secondary_storages.begin(),
+ m_secondary_storages.end(),
+ [](const auto& entry) { return !entry->config.read_only; });
+ if (should_put_in_secondary_storage) {
+ std::string value;
+ try {
+ value = Util::read_file(*path);
+ } catch (const core::Error& e) {
+ LOG("Failed to read {}: {}", *path, e.what());
+ return path; // Don't indicate failure since primary storage was OK.
+ }
+ put_in_secondary_storage(key, value, true);
}
- put_in_secondary_storage(key, value, true);
}
+
+ return path;
}
+ }
- return path;
+ if (mode == Mode::primary_only) {
+ return std::nullopt;
}
const auto value_and_share_hits = get_from_secondary_storage(key);
primary::PrimaryStorage primary;
// Returns a path to a file containing the value.
- std::optional<std::string> get(const Digest& key, core::CacheEntryType type);
+ enum class Mode { secondary_fallback, secondary_only, primary_only };
+ std::optional<std::string> get(const Digest& key,
+ core::CacheEntryType type,
+ const Mode mode = Mode::secondary_fallback);
bool put(const Digest& key,
core::CacheEntryType type,