GH-768 Store config uniqueness enforced by StoreManager#1555
GH-768 Store config uniqueness enforced by StoreManager#1555mkeen wants to merge 11 commits intoTraceMachina:mainfrom
Conversation
MarcusSorealheis
left a comment
There was a problem hiding this comment.
Beyond simplification requested, everything looks good.
| .await?, | ||
| ); | ||
| &StoreSpec::filesystem(FilesystemSpec { | ||
| content_path: current_dir |
There was a problem hiding this comment.
This is too complicated. Would be simpler to keep MemorySpec here. I know it isn't pure but we don't have consistent way to test FilesystemStore. We need one.
MarcusSorealheis
left a comment
There was a problem hiding this comment.
Looking good @mkeen There's a few things to tidy up and I also want one of two other maintainers to look at the rename and deletion of store_factory. After lots of thought, I'm in favor of that change, but we simply need to boost awareness.
I want to think just for a few more hours also about what the error text should say when there are conflicting store configurations. What you have is fine, but can it be improved. I'm not sure.
| 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( |
There was a problem hiding this comment.
For my understanding, what is the reason why you moved away from store_factory rather than modifying store_factory?
There was a problem hiding this comment.
Still using store_factory to build the Store, but wrapping up in make_and_add_store_to_manager because it makes building and adding a Store to a StoreManager a single step from a public-facing perspective.
| PublishBuildToolEventStreamRequest, PublishLifecycleEventRequest, StreamId, | ||
| }; | ||
| use nativelink_service::bep_server::BepServer; | ||
| use nativelink_store::default_store_factory::store_factory; |
There was a problem hiding this comment.
this seems heavy at first read but maybe it is an improvement to both the naming and the functionality. store_factory as a name says nothing about what its function is, but developers could go look at the definition. make_and_add_store_to_manager is definitely clearer.
There was a problem hiding this comment.
store_factory is still used but I made private and think that make_and_add_store_to_manager is better as a front-facing API because it makes and associates the Store with a StoreManager -- rather than leaving them as separate steps. The door is still open to manually build any Store instance though and call add_store on StoreManager.
| @@ -0,0 +1,48 @@ | |||
| // Copyright 2024 The NativeLink Authors. All rights reserved. | |||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
what are these spaces for?
There was a problem hiding this comment.
I will remove these and make sure formatting gets run again. My mistake on these spaces here.
| use std::collections::{HashMap, HashSet}; | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
and these? I mean empty lines.
|
|
||
|
|
||
|
|
||
|
|
| use nativelink_service::execution_server::ExecutionServer; | ||
| use nativelink_service::health_server::HealthServer; | ||
| use nativelink_service::worker_api_server::WorkerApiServer; | ||
| use nativelink_store::default_store_factory::store_factory; |
There was a problem hiding this comment.
@allada and @aaronmondal you two are going to need to sign off on moving away from store_factory. I would say this new name is more self-describing for sure.
There was a problem hiding this comment.
The big thing here guys is that make_and_add_store_to_manager enforces that all factory-built stores are part of a StoreManager so it's less likely that an unmanaged Store would be hanging around. Still possible to build them separately and pass into add_store this way though (useful for testing and probably other reasons). The old store_factory is still there and used by the new make_and_add_store_to_manager function, but store_factory is no longer public in this changeset.
| // limitations under the License. | ||
|
|
||
| use std::collections::HashMap; | ||
| use std::ptr; |
There was a problem hiding this comment.
We don't need this.. will remove
| } | ||
|
|
||
| for existing_store in stores.values().into_iter() { | ||
| if ptr::eq(&store, existing_store) { |
There was a problem hiding this comment.
Will remove this check. Thanks to rust's memory model and the fact that in this design, ownership of the struct instance is passed to the StoreManager on line 58. We don't have Store instance pointer being passed around with a risk of passing the same pointer N times. We have a single instance of which ownership is transferred exactly once in guaranteed fashion (thanks Rust).
So instance protection is no longer a goal or needed. But I do think the config overlap detection is valuable.
There was a problem hiding this comment.
Thanks Rust is an underrated comment.
allada
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 2 LGTMs obtained, and 0 of 14 files reviewed, and pending CI: Bazel Dev / macos-13, Bazel Dev / macos-14, Bazel Dev / ubuntu-24.04, NativeLink.com Cloud / Remote Cache / macos-14, NativeLink.com Cloud / Remote Cache / ubuntu-24.04, Remote / lre-cc / large-ubuntu-22.04, Remote / lre-rs / large-ubuntu-22.04, asan / ubuntu-22.04, docker-compose-compiles-nativelink (22.04), integration-tests (22.04), macos-13, pre-commit-checks, ubuntu-22.04, and 12 discussions need to be resolved
nativelink-config/src/stores.rs line 435 at r11 (raw file):
} impl StoreSpec {
nit: We don't allow complex functions in the config. We use these configs as simple definitions with some macro magic (like number->string conversions and such in serde).
Description
Ensuring that when new Stores are added to StoreManager, that
memory,experimental,filesystem,grpc, andredis_storestores will not experience overlap within aStoreManagerinstance. The same data store may be used for multiple values for the listed types only if relevantStoreSpecconfiguration values differ (such as connection details, key namespace, etc). Dictated bydisallow_duplicates_digestimplementation being present on the relevantStoreSpecenum type.Primary changes:
make_and_add_store_to_managerto make sure thestore_factoryfunction is not used for config that overlaps on enforced Store entitiesadd_storeso that duplicate-named items cannot be addedStoreSpecentities are defined instores.rsand enforced bystore_manager.rs.StoreSpecentities that don't need to be unique aren't encumbered by uniqueness enforcementDRAFT STATUS: Need to finalize tests and do a bit more cleanup where possible
Fixes #768
Type of change
not work as expected)
How Has This Been Tested?
Please also list any relevant details for your test configuration
Checklist
bazel test //...passes locallygit amendsee some docsThis change is