diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-24 17:09:01 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-31 17:15:46 +0100 |
commit | 66df7f4956c6fe1823eb43d31c3cbac7d8716125 (patch) | |
tree | 3f8bf106b3e189eeb4cfa01f97e8f9bb18678406 /src/other_tools/root_maps/distdir_git_map.cpp | |
parent | 3dc81b4b5a89f4e37af45ec9954723c79c3017cf (diff) | |
download | justbuild-66df7f4956c6fe1823eb43d31c3cbac7d8716125.tar.gz |
just-mr: Failure in serve api root tree requests should be fatal
The requests to retrieve the tree of a commit, archive, or distdir
also set up those trees in a way that the serve endpoint can later
build against them, besides allowing just-mr to set up roots
locally. Therefore, if the witnessing entity (Git commit, content
blob, or distdir, respectively) is known to the serve endpoint,
then failing to set up the root tree there should result in a
failure also of the just-mr setup on the client side.
Diffstat (limited to 'src/other_tools/root_maps/distdir_git_map.cpp')
-rw-r--r-- | src/other_tools/root_maps/distdir_git_map.cpp | 88 |
1 files changed, 70 insertions, 18 deletions
diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp index 7646882b..2ee0265f 100644 --- a/src/other_tools/root_maps/distdir_git_map.cpp +++ b/src/other_tools/root_maps/distdir_git_map.cpp @@ -191,6 +191,7 @@ auto CreateDistdirGitMap( ts, {std::move(op_key)}, [distdir_tree_id = *distdir_tree_id, + content_id = key.content_id, key, serve_api_exists, remote_api, @@ -216,24 +217,45 @@ auto CreateDistdirGitMap( if (not *has_tree) { // try to see if serve endpoint has the // information to prepare the root itself - if (auto served_tree_id = - ServeApi::RetrieveTreeFromDistdir( - key.content_list, - /*sync_tree=*/false)) { + auto serve_result = + ServeApi::RetrieveTreeFromDistdir( + key.content_list, + /*sync_tree=*/false); + if (std::holds_alternative<std::string>( + serve_result)) { // if serve has set up the tree, it must // match what we expect - if (distdir_tree_id != *served_tree_id) { + auto const& served_tree_id = + std::get<std::string>(serve_result); + if (distdir_tree_id != served_tree_id) { (*logger)( fmt::format( "Mismatch in served root tree " "id:\nexpected {}, but got {}", distdir_tree_id, - *served_tree_id), + served_tree_id), /*fatal=*/true); return; } } else { + // check if serve failure was due to distdir + // content not being found or it is + // otherwise fatal + auto const& is_fatal = + std::get<bool>(serve_result); + if (is_fatal) { + (*logger)( + fmt::format( + "Serve endpoint failed to set " + "up root from known distdir " + "content {}", + content_id), + /*fatal=*/true); + return; + } + // at this point we cannot continue without + // the remote api if (not remote_api) { (*logger)( fmt::format( @@ -344,17 +366,20 @@ auto CreateDistdirGitMap( } // try to see if serve endpoint has the information to // prepare the root itself - if (auto served_tree_id = ServeApi::RetrieveTreeFromDistdir( - key.content_list, - /*sync_tree=*/false)) { - // if serve has set up the tree, it must match what we - // expect - if (tree_id != *served_tree_id) { + auto serve_result = + ServeApi::RetrieveTreeFromDistdir(key.content_list, + /*sync_tree=*/false); + if (std::holds_alternative<std::string>(serve_result)) { + // if serve has set up the tree, it must + // match what we expect + auto const& served_tree_id = + std::get<std::string>(serve_result); + if (tree_id != served_tree_id) { (*logger)( fmt::format("Mismatch in served root tree " "id:\nexpected {}, but got {}", tree_id, - *served_tree_id), + served_tree_id), /*fatal=*/true); return; } @@ -365,6 +390,17 @@ auto CreateDistdirGitMap( /*is_cache_hit=*/false)); return; } + // check if serve failure was due to distdir content not + // being found or it is otherwise fatal + auto const& is_fatal = std::get<bool>(serve_result); + if (is_fatal) { + (*logger)( + fmt::format("Serve endpoint failed to set up root " + "from known distdir content {}", + key.content_id), + /*fatal=*/true); + return; + } // at this point we cannot continue without the remote api if (not remote_api) { (*logger)( @@ -467,16 +503,19 @@ auto CreateDistdirGitMap( } // now ask serve endpoint if it can set up the root if (serve_api_exists and remote_api) { - if (auto served_tree_id = - ServeApi::RetrieveTreeFromDistdir(key.content_list, - /*sync_tree=*/true)) { + auto serve_result = + ServeApi::RetrieveTreeFromDistdir(key.content_list, + /*sync_tree=*/true); + if (std::holds_alternative<std::string>(serve_result)) { // if serve has set up the tree, it must match what we // expect - if (tree_id != *served_tree_id) { + auto const& served_tree_id = + std::get<std::string>(serve_result); + if (tree_id != served_tree_id) { (*logger)(fmt::format("Mismatch in served root tree " "id:\nexpected {}, but got {}", tree_id, - *served_tree_id), + served_tree_id), /*fatal=*/true); return; } @@ -484,6 +523,19 @@ auto CreateDistdirGitMap( // root, as we will check the remote CAS for the // resulting tree anyway } + else { + // check if serve failure was due to distdir content not + // being found or it is otherwise fatal + auto const& is_fatal = std::get<bool>(serve_result); + if (is_fatal) { + (*logger)( + fmt::format("Serve endpoint failed to set up root " + "from known distdir content {}", + key.content_id), + /*fatal=*/true); + return; + } + } } // check the remote CAS for the tree if (remote_api and |