Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v24.1.x] storage: convert some vasserts to exceptions #22829

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/v/raft/tests/basic_raft_fixture_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ TEST_F(raft_fixture, test_empty_writes) {
auto reader = model::make_memory_record_batch_reader(
std::move(builder).build());

EXPECT_DEATH(
replicate(std::move(reader)).get(), "Assert failure.+Empty batch");
// Catch the error when appending.
auto res = replicate(std::move(reader)).get();
ASSERT_TRUE(res.has_error());
ASSERT_EQ(res.error(), errc::leader_append_failed);

// In this case there are no batches at all so we don't go to storage, and
// catch the error in Raft.
res = replicate(make_batches({})).get();
ASSERT_TRUE(res.has_error());
ASSERT_EQ(res.error(), errc::invalid_input_records);
}

TEST_F_CORO(raft_fixture, test_stuck_append_entries) {
Expand Down
32 changes: 18 additions & 14 deletions src/v/storage/segment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,25 +503,29 @@ ss::future<> segment::compaction_index_batch(const model::record_batch& b) {

ss::future<append_result> segment::do_append(const model::record_batch& b) {
check_segment_not_closed("append()");
vassert(
b.base_offset() <= b.last_offset(),
"Empty batch written to {}. Batch header: {}",
path(),
b.header());
vassert(
b.base_offset() >= _tracker.get_base_offset(),
"Invalid state. Attempted to append a batch with base_offset:{}, but "
"would invalidate our initial state base offset of:{}. Actual batch "
"header:{}, self:{}",
b.base_offset(),
_tracker.get_base_offset(),
b.header(),
*this);
vassert(
b.header().ctx.owner_shard,
"Shard not set when writing to: {} - header: {}",
*this,
b.header());
if (unlikely(b.base_offset() > b.last_offset())) {
return ss::make_exception_future<append_result>(
std::runtime_error(fmt::format(
"Empty batch written to {}. Batch header: {}",
path(),
b.header())));
}
if (unlikely(b.base_offset() < _tracker.get_base_offset())) {
return ss::make_exception_future<
append_result>(std::runtime_error(fmt::format(
"Invalid state. Attempted to append a batch with base_offset:{}, but "
"would invalidate our initial state base offset of:{}. Actual batch "
"header:{}, self:{}",
b.base_offset(),
_tracker.get_base_offset(),
b.header(),
*this)));
}
if (unlikely(b.compressed() && !b.header().attrs.is_valid_compression())) {
return ss::make_exception_future<
append_result>(std::runtime_error(fmt::format(
Expand Down
Loading