Skip to content

Commit

Permalink
feat: add support for GCS Store using tonic/grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
asr2003 committed Dec 18, 2024
1 parent f672af7 commit 19074d1
Show file tree
Hide file tree
Showing 7 changed files with 671 additions and 1 deletion.
53 changes: 52 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions nativelink-config/src/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub enum StoreSpec {
///
memory(MemorySpec),

/// TODO(asr2003): Add documentation.
experimental_gcs_store(GCSSpec),

/// S3 store will use Amazon's S3 service as a backend to store
/// the files. This configuration can be used to share files
/// across multiple instances.
Expand Down Expand Up @@ -724,6 +727,61 @@ pub struct EvictionPolicy {
pub max_count: u64,
}

#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
pub struct GCSSpec {
/// GCS region or location. Example: US, US-CENTRAL1, EUROPE-WEST1.
#[serde(default, deserialize_with = "convert_string_with_shellexpand")]
pub location: String,

/// Bucket name to use as the backend.
#[serde(default, deserialize_with = "convert_string_with_shellexpand")]
pub bucket: String,

/// Optional prefix for object keys. If None, no prefix will be used.
#[serde(default)]
pub key_prefix: Option<String>,

/// Retry configuration to use when a network request fails.
#[serde(default)]
pub retry: Retry,

/// Time in seconds after which an object is considered "expired."
/// Allows external tools to clean up unused objects.
/// Default: 0. Zero means never consider an object expired.
#[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
pub consider_expired_after_s: u32,

/// Maximum buffer size to retain in case of a retryable error during upload.
/// Setting this to zero will disable upload buffering.
/// Default: 5MB.
pub max_retry_buffer_per_request: Option<usize>,

/// Enable resumable uploads for large objects.
/// Default: true.
#[serde(default)]
pub enable_resumable_uploads: bool,

/// The maximum size of chunks (in bytes) for resumable uploads.
/// Default: 8MB.
pub resumable_chunk_size: Option<usize>,

/// Allow unencrypted HTTP connections. Only use this for local testing.
/// Default: false
#[serde(default)]
pub insecure_allow_http: bool,

/// Disable http/2 connections and only use http/1.1.
/// Default: false
#[serde(default)]
pub disable_http2: bool,

/// Optional configuration for client authentication.
/// Example: Path to a service account JSON key file or environment-based authentication.
#[serde(default)]
pub auth_key_file: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
pub struct S3Spec {
Expand Down
3 changes: 3 additions & 0 deletions nativelink-store/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rust_library(
"src/existence_cache_store.rs",
"src/fast_slow_store.rs",
"src/filesystem_store.rs",
"src/gcs_store.rs",
"src/grpc_store.rs",
"src/lib.rs",
"src/memory_store.rs",
Expand Down Expand Up @@ -52,9 +53,11 @@ rust_library(
"@crates//:bytes",
"@crates//:bytes-utils",
"@crates//:const_format",
"@crates//:crc32c",
"@crates//:filetime",
"@crates//:fred",
"@crates//:futures",
"@crates//:googleapis-tonic-google-storage-v2",
"@crates//:hex",
"@crates//:http-body",
"@crates//:hyper-0.14.31",
Expand Down
2 changes: 2 additions & 0 deletions nativelink-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ tokio-util = { version = "0.7.13" }
tonic = { version = "0.12.3", features = ["transport", "tls"], default-features = false }
tracing = { version = "0.1.41", default-features = false }
uuid = { version = "1.11.0", default-features = false, features = ["v4", "serde"] }
googleapis-tonic-google-storage-v2 = "0.16.0"
crc32c = "0.6.8"

[dev-dependencies]
nativelink-macro = { path = "../nativelink-macro" }
Expand Down
2 changes: 2 additions & 0 deletions nativelink-store/src/default_store_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::dedup_store::DedupStore;
use crate::existence_cache_store::ExistenceCacheStore;
use crate::fast_slow_store::FastSlowStore;
use crate::filesystem_store::FilesystemStore;
use crate::gcs_store::GCSStore;
use crate::grpc_store::GrpcStore;
use crate::memory_store::MemoryStore;
use crate::noop_store::NoopStore;
Expand All @@ -51,6 +52,7 @@ pub fn store_factory<'a>(
let store: Arc<dyn StoreDriver> = match backend {
StoreSpec::memory(spec) => MemoryStore::new(spec),
StoreSpec::experimental_s3_store(spec) => S3Store::new(spec, SystemTime::now).await?,
StoreSpec::experimental_gcs_store(spec) => GCSStore::new(spec, SystemTime::now).await?,
StoreSpec::redis_store(spec) => RedisStore::new(spec.clone())?,
StoreSpec::verify(spec) => VerifyStore::new(
spec,
Expand Down
Loading

0 comments on commit 19074d1

Please sign in to comment.