Skip to content

Commit

Permalink
[BugFix] fix error rowset_stat after retry apply (backport #51486) (#…
Browse files Browse the repository at this point in the history
…51499)

Signed-off-by: sevev <[email protected]>
Co-authored-by: zhangqiang <[email protected]>
  • Loading branch information
mergify[bot] and sevev authored Sep 27, 2024
1 parent 0286806 commit 56bcf6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
31 changes: 7 additions & 24 deletions be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,13 @@ Status TabletUpdates::_apply_normal_rowset_commit(const EditVersionInfo& version
manager->update_state_cache().remove(state_entry);
int64_t t_index = MonotonicMillis();

// NOTE:
// If the apply fails at the following stages, an intolerable error must be returned right now.
// Because the metadata may have already been persisted.
// If you need to return a tolerable error, please make sure the following:
// 1. The latest meta should be roll back.
// 2. The del_vec cache maybe invalid, maybe clear cache is necessary.
// 3. The rowset stats maybe invalid, need to recalculate
span->AddEvent("gen_delvec");
size_t ndelvec = new_deletes.size();
vector<std::pair<uint32_t, DelVectorPtr>> new_del_vecs(ndelvec);
Expand Down Expand Up @@ -1622,12 +1629,6 @@ Status TabletUpdates::_apply_normal_rowset_commit(const EditVersionInfo& version
StarRocksMetrics::instance()->update_del_vector_deletes_new.increment(new_del);
int64_t t_delvec = MonotonicMillis();

// NOTE:
// If the apply fails at the following stages, an intolerable error must be returned right now.
// Because the metadata may have already been persisted.
// If you need to return a tolerable error, please make sure the following:
// 1. The latest meta should be roll back.
// 2. The del_vec cache maybe invalid, maybe clear cache is necessary.
{
std::lock_guard wl(_lock);
FAIL_POINT_TRIGGER_EXECUTE(tablet_apply_tablet_drop, { _edit_version_infos.clear(); });
Expand Down Expand Up @@ -5550,24 +5551,6 @@ void TabletUpdates::_reset_apply_status(const EditVersionInfo& version_info_appl
manager->index_cache().update_object_size(index_entry, index.memory_usage());
}
}

// 3. reset rowset_stats
{
std::lock_guard lg(_rowset_stats_lock);
_rowset_stats.clear();
for (auto& [rsid, rowset] : _rowsets) {
auto stats = std::make_unique<RowsetStats>();
stats->num_segments = rowset->num_segments();
stats->num_rows = rowset->num_rows();
stats->byte_size = rowset->data_disk_size();
stats->num_dels = 0;
stats->partial_update_by_column = rowset->is_column_mode_partial_update();
DCHECK_LE(stats->num_dels, stats->num_rows) << " tabletid:" << _tablet.tablet_id() << " rowset:" << rsid;
_calc_compaction_score(stats.get());
_rowset_stats.emplace(rsid, std::move(stats));
}
}
_update_total_stats(version_info_apply.rowsets, nullptr, nullptr);
}

} // namespace starrocks
13 changes: 0 additions & 13 deletions be/test/storage/tablet_updates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3599,19 +3599,6 @@ TEST_F(TabletUpdatesTest, test_normal_apply_retry) {

// 14. get del_vec failed
test_fail_point("tablet_apply_get_del_vec_failed", 15, N / 2);

// 15. write meta failed
test_fail_point("tablet_meta_manager_apply_rowset_manager_internal_error", 16, N / 2);

// 16. cache del vec failed
trigger_mode.set_mode(FailPointTriggerModeType::ENABLE);
fp_name = "tablet_meta_manager_apply_rowset_manager_fake_ok";
fp = starrocks::failpoint::FailPointRegistry::GetInstance()->get(fp_name);
fp->setMode(trigger_mode);
test_fail_point("tablet_apply_cache_del_vec_failed", 17, N / 2);

trigger_mode.set_mode(FailPointTriggerModeType::DISABLE);
fp->setMode(trigger_mode);
}

TEST_F(TabletUpdatesTest, test_column_mode_partial_update_apply_retry) {}
Expand Down

0 comments on commit 56bcf6f

Please sign in to comment.