diff --git a/be/src/storage/tablet_updates.cpp b/be/src/storage/tablet_updates.cpp index e8fffec5531fa..621636ae96d9d 100644 --- a/be/src/storage/tablet_updates.cpp +++ b/be/src/storage/tablet_updates.cpp @@ -1021,14 +1021,18 @@ void TabletUpdates::do_apply() { _apply_stopped_cond.notify_all(); } -void TabletUpdates::_stop_and_wait_apply_done() { - _apply_stopped = true; +void TabletUpdates::_wait_apply_done() { std::unique_lock ul(_apply_running_lock); while (_apply_running) { _apply_stopped_cond.wait(ul); } } +void TabletUpdates::_stop_and_wait_apply_done() { + _apply_stopped = true; + _wait_apply_done(); +} + Status TabletUpdates::get_latest_applied_version(EditVersion* latest_applied_version) { std::lock_guard l(_lock); if (_edit_version_infos.empty()) { diff --git a/be/src/storage/tablet_updates.h b/be/src/storage/tablet_updates.h index e886532077df0..74bdd31c541f1 100644 --- a/be/src/storage/tablet_updates.h +++ b/be/src/storage/tablet_updates.h @@ -439,6 +439,7 @@ class TabletUpdates { Status _commit_compaction(std::unique_ptr* info, const RowsetSharedPtr& rowset, EditVersion* commit_version); + void _wait_apply_done(); void _stop_and_wait_apply_done(); Status _do_compaction(std::unique_ptr* pinfo); @@ -507,6 +508,7 @@ class TabletUpdates { _last_compaction_time_ms = UnixMillis(); } } + void wait_apply_done() { _wait_apply_done(); } bool is_apply_stop() { return _apply_stopped.load(); } bool compaction_running() { return _compaction_running; } diff --git a/be/test/storage/tablet_updates_test.cpp b/be/test/storage/tablet_updates_test.cpp index 1d449a898e4c5..001b0ed1b214e 100644 --- a/be/test/storage/tablet_updates_test.cpp +++ b/be/test/storage/tablet_updates_test.cpp @@ -3694,14 +3694,14 @@ TEST_F(TabletUpdatesTest, test_compaction_apply_retry) { _tablet->updates()->check_for_apply(); // Verify the read result - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + _tablet->updates()->wait_apply_done(); ASSERT_TRUE(_tablet->updates()->is_error()); ASSERT_TRUE(!_tablet->updates()->compaction_running()); }; _tablet->updates()->stop_compaction(false); _tablet->updates()->compaction(_compaction_mem_tracker.get()); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + _tablet->updates()->wait_apply_done(); ASSERT_TRUE(_tablet->updates()->is_error()); // 2. get pindex meta failed