Skip to content

Commit

Permalink
[UT] Fix unstable ut (#54686)
Browse files Browse the repository at this point in the history
Signed-off-by: sevev <[email protected]>
  • Loading branch information
sevev authored Jan 6, 2025
1 parent 9bf5750 commit 8f6bd26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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()) {
Expand Down
2 changes: 2 additions & 0 deletions be/src/storage/tablet_updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class TabletUpdates {
Status _commit_compaction(std::unique_ptr<CompactionInfo>* info, const RowsetSharedPtr& rowset,
EditVersion* commit_version);

void _wait_apply_done();
void _stop_and_wait_apply_done();

Status _do_compaction(std::unique_ptr<CompactionInfo>* pinfo);
Expand Down Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions be/test/storage/tablet_updates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f6bd26

Please sign in to comment.