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

[BugFix] fix pk concurrent apply issue (backport #51225) #51287

Merged
merged 2 commits into from
Sep 24, 2024
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
2 changes: 1 addition & 1 deletion be/src/storage/base_tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class BaseTablet : public std::enable_shared_from_this<BaseTablet> {
return flag;
}

protected:
virtual void on_shutdown() {}

protected:
void _gen_tablet_path();

TabletState _state;
Expand Down
1 change: 0 additions & 1 deletion be/src/storage/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ class Tablet : public BaseTablet {
// set true when start to drop tablet. only set in `TabletManager::drop_tablet` right now
void set_is_dropping(bool is_dropping) { _is_dropping = is_dropping; }

protected:
void on_shutdown() override;

private:
Expand Down
10 changes: 10 additions & 0 deletions be/src/storage/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@ Status TabletManager::drop_tablet(TTabletId tablet_id, TabletDropFlag flag) {
_add_shutdown_tablet_unlocked(tablet_id, std::move(drop_info));
} else {
DCHECK_EQ(kKeepMetaAndFiles, flag);
{
// If the tablet is the primary key table, there might still be ongoing apply tasks.
// We should stop the background apply tasks before deleting it; otherwise, if a new tablet is created,
// there could be a scenario where apply tasks are executed simultaneously.
// e.g.
// 1. drop and clone a new tablet with the same tablet_id.
// 2. compact rocksdb meta and reload tablet again.
std::unique_lock l(dropped_tablet->get_header_lock());
dropped_tablet->on_shutdown();
}
}
// erase tablet from tablet map
{
Expand Down
1 change: 1 addition & 0 deletions be/src/storage/tablet_updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ class TabletUpdates {
_last_compaction_time_ms = UnixMillis();
}
}
bool is_apply_stop() { return _apply_stopped.load(); }

bool compaction_running() { return _compaction_running; }

Expand Down
7 changes: 7 additions & 0 deletions be/test/storage/tablet_updates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3731,4 +3731,11 @@ TEST_F(TabletUpdatesTest, test_get_compaction_status) {
test_horizontal_compaction(false, true);
}

TEST_F(TabletUpdatesTest, test_drop_tablet_with_keep_meta_and_files) {
_tablet = create_tablet(rand(), rand());
ASSERT_FALSE(_tablet->updates()->is_apply_stop());
StorageEngine::instance()->tablet_manager()->drop_tablet(_tablet->tablet_id(), kKeepMetaAndFiles);
ASSERT_TRUE(_tablet->updates()->is_apply_stop());
}

} // namespace starrocks
Loading