Skip to content

Commit

Permalink
[Enhancement] Wait apply finish out of tablet meta lock when set tabl…
Browse files Browse the repository at this point in the history
…et state as SHUTDOWN (#56266)

Signed-off-by: srlch <[email protected]>
(cherry picked from commit 76db0ef)
  • Loading branch information
srlch authored and mergify[bot] committed Feb 27, 2025
1 parent 4abadfc commit 2f4df04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion be/src/storage/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ Status Tablet::rowset_commit(int64_t version, const RowsetSharedPtr& rowset, uin

void Tablet::on_shutdown() {
if (_updates) {
_updates->_stop_and_wait_apply_done();
_updates->stop_and_wait_apply_done();
}
}

Expand Down
21 changes: 21 additions & 0 deletions be/src/storage/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ Status TabletManager::drop_tablet(TTabletId tablet_id, TabletDropFlag flag) {

DroppedTabletInfo drop_info{.tablet = dropped_tablet, .flag = flag};

// meta lock free shutdown for primary key table. In current impl, TabletUpdates's context
// is protected by specified lock defined in TabletUpdates itself but not tablet meta lock
// It is safe call stop_and_wait_apply_done out of tablet meta lock
if (dropped_tablet->updates() != nullptr) {
dropped_tablet->updates()->stop_and_wait_apply_done();
}

if (flag == kDeleteFiles) {
{
// NOTE: Other threads may save the tablet meta back to storage again after we
Expand Down Expand Up @@ -492,6 +499,13 @@ Status TabletManager::drop_tablets_on_error_root_path(const std::vector<TabletIn
}

for (const auto& dropped_tablet : dropped_tablets) {
// meta lock free shutdown for primary key table. In current impl, TabletUpdates's context
// is protected by specified lock defined in TabletUpdates itself but not tablet meta lock
// It is safe call stop_and_wait_apply_done out of tablet meta lock
if (dropped_tablet->updates() != nullptr) {
dropped_tablet->updates()->stop_and_wait_apply_done();
}

// make sure dropped tablet state is TABLET_SHUTDOWN IN MEMORY ONLY!
// any persistent operation is useless because the disk has failed
// and the IO operation should be always failed in this case.
Expand Down Expand Up @@ -1520,6 +1534,13 @@ Status TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, TabletDropFlag

DroppedTabletInfo drop_info{.tablet = dropped_tablet, .flag = flag};

// meta lock free shutdown for primary key table. In current impl, TabletUpdates's context
// is protected by specified lock defined in TabletUpdates itself but not tablet meta lock
// It is safe call stop_and_wait_apply_done out of tablet meta lock
if (dropped_tablet->updates() != nullptr) {
dropped_tablet->updates()->stop_and_wait_apply_done();
}

if (flag == kDeleteFiles) {
{
// NOTE: Other threads may save the tablet meta back to storage again after we
Expand Down
8 changes: 4 additions & 4 deletions be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::string EditVersion::to_string() const {
TabletUpdates::TabletUpdates(Tablet& tablet) : _tablet(tablet), _unused_rowsets(UINT64_MAX) {}

TabletUpdates::~TabletUpdates() {
_stop_and_wait_apply_done();
stop_and_wait_apply_done();
}

template <class Itr1, class Itr2>
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void TabletUpdates::_wait_apply_done() {
}
}

void TabletUpdates::_stop_and_wait_apply_done() {
void TabletUpdates::stop_and_wait_apply_done() {
_apply_stopped = true;
_wait_apply_done();
}
Expand Down Expand Up @@ -4843,7 +4843,7 @@ Status TabletUpdates::load_snapshot(const SnapshotMeta& snapshot_meta, bool rest
RETURN_IF_ERROR(check_rowset_files(rowset_meta_pb));
}
// Stop apply thread.
_stop_and_wait_apply_done();
stop_and_wait_apply_done();

DeferOp defer([&]() {
if (!_error.load()) {
Expand Down Expand Up @@ -5570,7 +5570,7 @@ Status TabletUpdates::recover() {
}
LOG(INFO) << "Tablet " << _tablet.tablet_id() << " begin do recover: " << _error_msg;
// Stop apply thread.
_stop_and_wait_apply_done();
stop_and_wait_apply_done();

DeferOp defer([&]() {
if (!_error.load()) {
Expand Down
3 changes: 2 additions & 1 deletion be/src/storage/tablet_updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ class TabletUpdates {

void rewrite_rs_meta(bool is_fatal);

void stop_and_wait_apply_done();

private:
friend class Tablet;
friend class PrimaryIndex;
Expand Down Expand Up @@ -435,7 +437,6 @@ class TabletUpdates {
EditVersion* commit_version);

void _wait_apply_done();
void _stop_and_wait_apply_done();

Status _do_compaction(std::unique_ptr<CompactionInfo>* pinfo);

Expand Down

0 comments on commit 2f4df04

Please sign in to comment.