Skip to content

Commit

Permalink
Make CAS and AC server not to use the same store
Browse files Browse the repository at this point in the history
When CAS and AC uses the same store, it might produce unexpected
side-effects and wrong behaviors. To prevent system from such situation,
it currently raises an error when CAS and AC uses the same store.
An integration test is added for this using nix test file and github's
nix workflow.
  • Loading branch information
aleksdmladenovic committed Aug 16, 2024
1 parent 042f4a5 commit 57b63e8
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ jobs:
- name: Test nix run
run: |
nix run -L .#nativelink-prevent-store-conflict-test
nix run -L .#nativelink-is-executable-test
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@

local-image-test = pkgs.callPackage ./tools/local-image-test.nix {};

nativelink-prevent-store-conflict-test = pkgs.callPackage ./tools/nativelink-prevent-store-conflict-test.nix {inherit nativelink;};

nativelink-is-executable-test = pkgs.callPackage ./tools/nativelink-is-executable-test.nix {inherit nativelink;};

rbe-configs-gen = pkgs.callPackage ./local-remote-execution/rbe-configs-gen.nix {};
Expand Down Expand Up @@ -357,6 +359,7 @@
nativelink-debug
nativelink-image
nativelink-is-executable-test
nativelink-prevent-store-conflict-test
nativelink-worker-init
nativelink-x86_64-linux
publish-ghcr
Expand Down
10 changes: 4 additions & 6 deletions nativelink-scheduler/tests/utils/mock_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ use std::sync::Arc;
use async_trait::async_trait;
use nativelink_error::{make_input_err, Error};
use nativelink_metric::{MetricsComponent, RootMetricsComponent};
use nativelink_util::{
action_messages::{ActionInfo, OperationId},
known_platform_property_provider::KnownPlatformPropertyProvider,
operation_state_manager::{
ActionStateResult, ActionStateResultStream, ClientStateManager, OperationFilter,
},
use nativelink_util::action_messages::{ActionInfo, OperationId};
use nativelink_util::known_platform_property_provider::KnownPlatformPropertyProvider;
use nativelink_util::operation_state_manager::{
ActionStateResult, ActionStateResultStream, ClientStateManager, OperationFilter,
};
use tokio::sync::{mpsc, Mutex};

Expand Down
17 changes: 17 additions & 0 deletions src/bin/nativelink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ async fn inner_main(
// Currently we only support http as our socket type.
let ListenerConfig::http(http_config) = server_cfg.listener;

// Check if CAS and AC use the same store.
if let Some(cas_config) = &services.cas {
if let Some(ac_config) = &services.ac {
for (instance_name, cas_store_config) in cas_config {
if let Some(ac_store_config) = ac_config.get(instance_name) {
if cas_store_config.cas_store == ac_store_config.ac_store {
return Err(make_err!(
Code::InvalidArgument,
"CAS and AC cannot use the same store '{}' in the config",
cas_store_config.cas_store
))?;
}
}
}
}
}

let tonic_services = TonicServer::builder()
.add_optional_service(
services
Expand Down
72 changes: 72 additions & 0 deletions tools/nativelink-prevent-store-conflict-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
nativelink,
writeShellScriptBin,
}:
writeShellScriptBin "prevent-store-conflict-test" ''
set -xuo pipefail
cat > store_conflict_test.json <<EOF
{
"stores": {
"FILESYSTEM_STORE": {
"compression": {
"compression_algorithm": {
"lz4": {}
},
"backend": {
"filesystem": {
"content_path": "~/.cache/nativelink/content_path-cas",
"temp_path": "~/.cache/nativelink/tmp_path-cas",
"eviction_policy": {
// 10gb.
"max_bytes": 10000000000,
}
}
}
}
}
},
"servers": [{
"listener": {
"http": {
"socket_address": "0.0.0.0:50053"
}
},
"services": {
"cas": {
"main": {
"cas_store": "FILESYSTEM_STORE"
}
},
"ac": {
"main": {
"ac_store": "FILESYSTEM_STORE"
}
},
"capabilities": {},
"bytestream": {
"cas_stores": {
"main": "FILESYSTEM_STORE",
}
}
}
}]
}
EOF
nativelink_output="$(${nativelink}/bin/nativelink ./store_conflict_test.json 2>&1)"
rm ./store_conflict_test.json
print_error_output=$(cat <<EOF
Error: Error { code: InvalidArgument, messages: ["CAS and AC cannot use the same store 'FILESYSTEM_STORE' in the config"] }
EOF)
if [ "$nativelink_output" = "$print_error_output" ]; then
echo "The output of nativelink matches the print_error output."
else
echo 'The output of nativelink does not match the print_error output:'
diff <(echo "$nativelink_output") <(echo "$print_error_output") >&2
exit 1
fi
''

0 comments on commit 57b63e8

Please sign in to comment.