From 0648eb0c6d9cacd5130b71e0d4da8baf28540827 Mon Sep 17 00:00:00 2001 From: Evgeny Lazin <4lazin@gmail.com> Date: Mon, 16 Dec 2024 06:09:07 -0500 Subject: [PATCH] archival: Convert assertion to exception The situation in which the assertion is triggered can only be caused by a race and is retrieable. There is no need to crash the whole process in that case. Signed-off-by: Evgeny Lazin <4lazin@gmail.com> --- src/v/cluster/archival/archival_policy.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/v/cluster/archival/archival_policy.cc b/src/v/cluster/archival/archival_policy.cc index aea1f0bb1802c..baa2b8308d9e9 100644 --- a/src/v/cluster/archival/archival_policy.cc +++ b/src/v/cluster/archival/archival_policy.cc @@ -358,10 +358,14 @@ ss::future> get_file_range( upl->max_timestamp = seek.ts; } // Recompute content_length based on file offsets - vassert( - upl->file_offset <= upl->final_file_offset, - "Invalid upload candidate {}", - upl); + if (upl->file_offset > upl->final_file_offset) { + // This could potentially happen if the log was truncated after + // file_offset is set. In this case the index could become empty which + // will trigger the condition above. The operation could be retried + // later so throwing makes more sense then the assertion. + throw std::runtime_error( + fmt_with_ctx(fmt::format, "Invalid upload candidate {}", upl)); + } upl->content_length = upl->final_file_offset - upl->file_offset; if (upl->content_length > segment->reader().file_size()) { throw std::runtime_error(fmt_with_ctx(