Skip to content

Commit cc1d398

Browse files
Make CAS and AC server not to use the same store
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.
1 parent 7b5231f commit cc1d398

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

.github/workflows/nix.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ jobs:
134134
135135
- name: Test nix run
136136
run: |
137+
nix run -L .#nativelink-prevent-store-conflict-test
137138
nix run -L .#nativelink-is-executable-test

flake.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133

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

136+
nativelink-prevent-store-conflict-test = pkgs.callPackage ./tools/nativelink-prevent-store-conflict-test.nix {inherit nativelink;};
137+
136138
nativelink-is-executable-test = pkgs.callPackage ./tools/nativelink-is-executable-test.nix {inherit nativelink;};
137139

138140
rbe-configs-gen = pkgs.callPackage ./local-remote-execution/rbe-configs-gen.nix {};
@@ -251,7 +253,7 @@
251253
};
252254
};
253255
packages = rec {
254-
inherit publish-ghcr local-image-test nativelink-is-executable-test nativelink nativelink-debug native-cli lre-cc nativelink-worker-init;
256+
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;
255257
default = nativelink;
256258

257259
rbe-autogen-lre-cc = rbe-autogen lre-cc;

src/bin/nativelink.rs

+17
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,23 @@ async fn inner_main(
243243
// Currently we only support http as our socket type.
244244
let ListenerConfig::http(http_config) = server_cfg.listener;
245245

246+
// Check if CAS and AC use the same store.
247+
if let Some(cas_config) = &services.cas {
248+
if let Some(ac_config) = &services.ac {
249+
for (instance_name, cas_store_config) in cas_config {
250+
if let Some(ac_store_config) = ac_config.get(instance_name) {
251+
if cas_store_config.cas_store == ac_store_config.ac_store {
252+
return Err(make_err!(
253+
Code::InvalidArgument,
254+
"CAS and AC cannot use the same store '{}' in the config",
255+
cas_store_config.cas_store
256+
))?;
257+
}
258+
}
259+
}
260+
}
261+
}
262+
246263
let tonic_services = TonicServer::builder()
247264
.add_optional_service(
248265
services
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
nativelink,
3+
writeShellScriptBin,
4+
}:
5+
writeShellScriptBin "prevent-store-conflict-test" ''
6+
set -xuo pipefail
7+
8+
cat > store_conflict_test.json <<EOF
9+
{
10+
"stores": {
11+
"FILESYSTEM_STORE": {
12+
"compression": {
13+
"compression_algorithm": {
14+
"lz4": {}
15+
},
16+
"backend": {
17+
"filesystem": {
18+
"content_path": "~/.cache/nativelink/content_path-cas",
19+
"temp_path": "~/.cache/nativelink/tmp_path-cas",
20+
"eviction_policy": {
21+
// 10gb.
22+
"max_bytes": 10000000000,
23+
}
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"servers": [{
30+
"listener": {
31+
"http": {
32+
"socket_address": "0.0.0.0:50053"
33+
}
34+
},
35+
"services": {
36+
"cas": {
37+
"main": {
38+
"cas_store": "FILESYSTEM_STORE"
39+
}
40+
},
41+
"ac": {
42+
"main": {
43+
"ac_store": "FILESYSTEM_STORE"
44+
}
45+
},
46+
"capabilities": {},
47+
"bytestream": {
48+
"cas_stores": {
49+
"main": "FILESYSTEM_STORE",
50+
}
51+
}
52+
}
53+
}]
54+
}
55+
EOF
56+
57+
nativelink_output="$(${nativelink}/bin/nativelink ./store_conflict_test.json 2>&1)"
58+
59+
rm ./store_conflict_test.json
60+
61+
print_error_output=$(cat <<EOF
62+
Error: Error { code: InvalidArgument, messages: ["CAS and AC cannot use the same store 'FILESYSTEM_STORE' in the config"] }
63+
EOF)
64+
65+
if [ "$nativelink_output" = "$print_error_output" ]; then
66+
echo "The output of nativelink matches the print_error output."
67+
else
68+
echo 'The output of nativelink does not match the print_error output:'
69+
diff <(echo "$nativelink_output") <(echo "$print_error_output") >&2
70+
exit 1
71+
fi
72+
''

0 commit comments

Comments
 (0)