Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Noop store #408

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
734 changes: 368 additions & 366 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

188 changes: 95 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ members = [
"gencargo/mock_running_actions_manager",
"gencargo/mock_scheduler",
"gencargo/mock_worker_api_client",
"gencargo/noop_store",
"gencargo/platform_property_manager",
"gencargo/property_modifier_scheduler",
"gencargo/property_modifier_scheduler_test",
Expand Down Expand Up @@ -212,6 +213,7 @@ metrics_utils = { path = "gencargo/metrics_utils" }
mock_running_actions_manager = { path = "gencargo/mock_running_actions_manager" }
mock_scheduler = { path = "gencargo/mock_scheduler" }
mock_worker_api_client = { path = "gencargo/mock_worker_api_client" }
noop_store = { path = "gencargo/noop_store" }
platform_property_manager = { path = "gencargo/platform_property_manager" }
property_modifier_scheduler = { path = "gencargo/property_modifier_scheduler" }
property_modifier_scheduler_test = { path = "gencargo/property_modifier_scheduler_test" }
Expand Down
17 changes: 17 additions & 0 deletions cas/store/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rust_library(
":filesystem_store",
":grpc_store",
":memory_store",
":noop_store",
":ref_store",
":s3_store",
":shard_store",
Expand Down Expand Up @@ -126,6 +127,22 @@ rust_library(
],
)

rust_library(
name = "noop_store",
srcs = ["noop_store.rs"],
proc_macro_deps = ["@crate_index//:async-trait"],
visibility = [
"//cas:__pkg__",
"//cas:__subpackages__",
],
deps = [
":traits",
"//util:buf_channel",
"//util:common",
"//util:error",
],
)

rust_library(
name = "verify_store",
srcs = ["verify_store.rs"],
Expand Down
2 changes: 2 additions & 0 deletions cas/store/default_store_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use filesystem_store::FilesystemStore;
use grpc_store::GrpcStore;
use memory_store::MemoryStore;
use metrics_utils::Registry;
use noop_store::NoopStore;
use ref_store::RefStore;
use s3_store::S3Store;
use shard_store::ShardStore;
Expand Down Expand Up @@ -75,6 +76,7 @@ pub fn store_factory<'a>(
store_factory(&config.upper_store, store_manager, None).await?,
)),
StoreConfig::grpc(config) => Arc::new(GrpcStore::new(config).await?),
StoreConfig::noop => Arc::new(NoopStore::new()),
StoreConfig::shard(config) => {
let stores = config
.stores
Expand Down
74 changes: 74 additions & 0 deletions cas/store/noop_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2023 The Native Link 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.

use std::pin::Pin;
use std::sync::Arc;

use async_trait::async_trait;

use buf_channel::{DropCloserReadHalf, DropCloserWriteHalf};
use common::DigestInfo;
use error::{make_err, Code, Error, ResultExt};
use traits::{StoreTrait, UploadSizeInfo};

#[derive(Default)]
pub struct NoopStore;

impl NoopStore {
pub fn new() -> Self {
NoopStore {}
}
}

#[async_trait]
impl StoreTrait for NoopStore {
async fn has_with_results(
self: Pin<&Self>,
_digests: &[DigestInfo],
results: &mut [Option<usize>],
) -> Result<(), Error> {
results.iter_mut().for_each(|r| *r = None);
Ok(())
}

async fn update(
self: Pin<&Self>,
_digest: DigestInfo,
mut reader: DropCloserReadHalf,
_size_info: UploadSizeInfo,
) -> Result<(), Error> {
// We need to drain the reader to avoid the writer complaining that we dropped
// the connection prematurely.
loop {
if reader.recv().await.err_tip(|| "In NoopStore::update")?.is_empty() {
break; // EOF.
}
}
Ok(())
}

async fn get_part_ref(
self: Pin<&Self>,
_digest: DigestInfo,
_writer: &mut DropCloserWriteHalf,
_offset: usize,
_length: Option<usize>,
) -> Result<(), Error> {
Err(make_err!(Code::NotFound, "Not found in noop store"))
}

fn as_any(self: Arc<Self>) -> Box<dyn std::any::Any + Send> {
Box::new(self)
}
}
29 changes: 14 additions & 15 deletions config/examples/basic_cas.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{
"stores": {
"CAS_MAIN_STORE": {
"memory": {
"eviction_policy": {
// 1gb.
"max_bytes": 1000000000,
}
}
},
"AC_MAIN_STORE": {
"memory": {
"eviction_policy": {
Expand All @@ -31,9 +23,12 @@
}
},
"slow": {
"ref_store": {
"name": "CAS_MAIN_STORE",
}
/// Discard data.
/// This example usage has the CAS and the Worker live in the same place,
/// so they share the same underlying CAS. Since workers require a fast_slow
/// store, we use the fast store as our primary data store, and the slow store
/// is just a noop, since there's no shared storage in this config.
"noop": {}
}
}
}
Expand All @@ -56,7 +51,9 @@
"cpu_arch": "Exact",
"cpu_model": "Exact",
"kernel_version": "Exact",
"docker_image": "Priority",
// Example of how to set which docker images are available and set
// them in the platform properties.
// "docker_image": "Priority",
}
}
}
Expand Down Expand Up @@ -84,9 +81,11 @@
"cpu_arch": {
"values": ["x86_64"],
},
"docker_image": {
"query_cmd": "docker images --format {{.Repository}}:{{.Tag}}",
}
// Example of how to set which docker images are available and set
// them in the platform properties.
// "docker_image": {
// "query_cmd": "docker images --format {{.Repository}}:{{.Tag}}",
// }
}
}
}],
Expand Down
6 changes: 6 additions & 0 deletions config/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ pub enum StoreConfig {
/// this store directly without being a child of any store there are no
/// side effects and is the most efficient way to use it.
grpc(GrpcStore),

/// Noop store is a store that sends streams into the void and all data
/// retrieval will return 404 (NotFound). This can be useful for cases
/// where you may need to partition your data and part of your data needs
/// to be discarded.
noop,
}

/// Configuration for an individual shard of the store.
Expand Down
1 change: 1 addition & 0 deletions gencargo/default_store_factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fast_slow_store = { workspace = true }
filesystem_store = { workspace = true }
grpc_store = { workspace = true }
memory_store = { workspace = true }
noop_store = { workspace = true }
ref_store = { workspace = true }
s3_store = { workspace = true }
shard_store = { workspace = true }
Expand Down
28 changes: 28 additions & 0 deletions gencargo/noop_store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is automatically generated from `tools/build_cargo_manifest.py`.
# If you want to add a dependency add it to `tools/cargo_shared.bzl`
# then run `python tools/build_cargo_manifest.py`.
# Do not edit this file directly.

[package]
name = "noop_store"
version = "0.0.0"
edition = "2021"
autobins = false
autoexamples = false
autotests = false
autobenches = false

[lib]
name = "noop_store"
path = "../../cas/store/noop_store.rs"
# TODO(allada) We should support doctests.
doctest = false

[dependencies]
async-trait = { workspace = true }

# Local libraries.
traits = { workspace = true }
buf_channel = { workspace = true }
common = { workspace = true }
error = { workspace = true }