-
Notifications
You must be signed in to change notification settings - Fork 127
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
GH-768 Store config uniqueness enforced by StoreManager #1555
base: main
Are you sure you want to change the base?
Changes from 10 commits
324df36
9f67019
ccca3a6
6bb7cc2
01f23a7
4a4d11a
d361abf
91a3557
9adeef3
0022bdf
aff36b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,20 +12,21 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::env; | ||
use std::pin::Pin; | ||
use std::sync::Arc; | ||
|
||
use bytes::BytesMut; | ||
use maplit::hashmap; | ||
use nativelink_config::stores::{MemorySpec, StoreSpec}; | ||
use nativelink_config::stores::{FilesystemSpec, MemorySpec, StoreSpec}; | ||
use nativelink_error::Error; | ||
use nativelink_macro::nativelink_test; | ||
use nativelink_proto::build::bazel::remote::execution::v2::action_cache_server::ActionCache; | ||
use nativelink_proto::build::bazel::remote::execution::v2::{ | ||
digest_function, ActionResult, Digest, GetActionResultRequest, UpdateActionResultRequest, | ||
}; | ||
use nativelink_service::ac_server::AcServer; | ||
use nativelink_store::default_store_factory::store_factory; | ||
use nativelink_store::default_store_factory::make_and_add_store_to_manager; | ||
use nativelink_store::store_manager::StoreManager; | ||
use nativelink_util::common::DigestInfo; | ||
use nativelink_util::store_trait::StoreLike; | ||
|
@@ -48,29 +49,46 @@ async fn insert_into_store<T: Message>( | |
let data_len = store_data.len(); | ||
let digest = DigestInfo::try_new(hash, action_size)?; | ||
store.update_oneshot(digest, store_data.freeze()).await?; | ||
|
||
Ok(data_len.try_into().unwrap()) | ||
} | ||
|
||
async fn make_store_manager() -> Result<Arc<StoreManager>, Error> { | ||
let store_manager = Arc::new(StoreManager::new()); | ||
store_manager.add_store( | ||
make_and_add_store_to_manager( | ||
"main_cas", | ||
store_factory( | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await?, | ||
); | ||
store_manager.add_store( | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await?; | ||
|
||
let current_dir = env::current_dir().expect("Failed to get current directory"); | ||
|
||
let default_filesystem_spec = FilesystemSpec::default(); | ||
|
||
make_and_add_store_to_manager( | ||
"main_ac", | ||
store_factory( | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await?, | ||
); | ||
&StoreSpec::filesystem(FilesystemSpec { | ||
content_path: current_dir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is too complicated. Would be simpler to keep |
||
.join("testing_data/ac/content_path") | ||
.into_os_string() | ||
.into_string() | ||
.unwrap(), | ||
temp_path: current_dir | ||
.join("testing_data/ac/tmp_path") | ||
.into_os_string() | ||
.into_string() | ||
.unwrap(), | ||
read_buffer_size: default_filesystem_spec.read_buffer_size, | ||
eviction_policy: default_filesystem_spec.eviction_policy, | ||
block_size: default_filesystem_spec.block_size, | ||
}), | ||
&store_manager, | ||
None, | ||
) | ||
.await?; | ||
|
||
Ok(store_manager) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ use nativelink_proto::google::devtools::build::v1::{ | |
PublishBuildToolEventStreamRequest, PublishLifecycleEventRequest, StreamId, | ||
}; | ||
use nativelink_service::bep_server::BepServer; | ||
use nativelink_store::default_store_factory::store_factory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems heavy at first read but maybe it is an improvement to both the naming and the functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
use nativelink_store::default_store_factory::make_and_add_store_to_manager; | ||
use nativelink_store::store_manager::StoreManager; | ||
use nativelink_util::buf_channel::make_buf_channel_pair; | ||
use nativelink_util::channel_body_for_tests::ChannelBody; | ||
|
@@ -52,15 +52,14 @@ const BEP_STORE_NAME: &str = "main_bep"; | |
/// Utility function to construct a [`StoreManager`] | ||
async fn make_store_manager() -> Result<Arc<StoreManager>, Error> { | ||
let store_manager = Arc::new(StoreManager::new()); | ||
store_manager.add_store( | ||
make_and_add_store_to_manager( | ||
BEP_STORE_NAME, | ||
store_factory( | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await?, | ||
); | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await?; | ||
|
||
Ok(store_manager) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2024 The NativeLink Authors. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PERFECT! |
||
// | ||
// 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::sync::Arc; | ||
|
||
use nativelink_config::stores::{MemorySpec, StoreSpec}; | ||
use nativelink_error::Error; | ||
use nativelink_macro::nativelink_test; | ||
use nativelink_store::default_store_factory::make_and_add_store_to_manager; | ||
use nativelink_store::store_manager::StoreManager; | ||
|
||
#[nativelink_test] | ||
async fn same_datasource_disallowed_simple() -> Result<(), Error> { | ||
let store_manager = Arc::new(StoreManager::new()); | ||
assert!(make_and_add_store_to_manager( | ||
"main_cas", | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await | ||
.is_ok()); | ||
|
||
assert!(make_and_add_store_to_manager( | ||
"main_ac", | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await | ||
.is_err()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[nativelink_test] | ||
async fn same_datasource_disallowed_complex() -> Result<(), Error> { | ||
let store_manager = Arc::new(StoreManager::new()); | ||
assert!(make_and_add_store_to_manager( | ||
"main_cas", | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await | ||
.is_ok()); | ||
|
||
assert!(make_and_add_store_to_manager( | ||
"main_ac", | ||
&StoreSpec::memory(MemorySpec::default()), | ||
&store_manager, | ||
None, | ||
) | ||
.await | ||
.is_err()); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding, what is the reason why you moved away from
store_factory
rather than modifyingstore_factory
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still using
store_factory
to build the Store, but wrapping up inmake_and_add_store_to_manager
because it makes building and adding a Store to a StoreManager a single step from a public-facing perspective.