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 8, 2024
1 parent c3f648e commit 22de268
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
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
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,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 @@ -251,7 +253,7 @@
};
};
packages = rec {
inherit publish-ghcr local-image-test nativelink-is-executable-test nativelink nativelink-debug native-cli lre-cc nativelink-worker-init;
inherit publish-ghcr local-image-test nativelink-prevent-store-conflict-test nativelink-is-executable-test nativelink nativelink-debug native-cli lre-cc nativelink-worker-init;
default = nativelink;

rbe-autogen-lre-cc = rbe-autogen lre-cc;
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 22de268

Please sign in to comment.