Skip to content

Commit

Permalink
fix trash loop and utest
Browse files Browse the repository at this point in the history
Signed-off-by: wanghai01 <[email protected]>
  • Loading branch information
SeanHai authored and wuhongsong committed Dec 11, 2023
1 parent abe27ed commit c8de94b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
18 changes: 12 additions & 6 deletions curvefs/src/metaserver/trash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void TrashImpl::Remove(uint64_t inodeId) {

void TrashImpl::ScanTrash() {
LockGuard lgScan(scanMutex_);
LOG(INFO) << "ScanTrash, fsId = " << fsId_
<< ", partitionId = " << partitionId_
<< ", trashItems size = " << trashItems_.size();
// only scan on leader
if (copysetNode_ == nullptr || !copysetNode_->IsLeaderTerm()) {
return;
Expand All @@ -103,22 +106,25 @@ void TrashImpl::ScanTrash() {
trashItems_.swap(temp);
}

for (auto& it : temp) {
for (auto it = temp.begin(); it != temp.end();) {
if (isStop_ || !copysetNode_->IsLeaderTerm()) {
return;
}
if (NeedDelete(it.second)) {
MetaStatusCode ret = DeleteInodeAndData(it.first);
if (NeedDelete(it->second)) {
MetaStatusCode ret = DeleteInodeAndData(it->first);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "DeleteInodeAndData fail, fsId = " << fsId_
<< ", inodeId = " << it.first
<< ", inodeId = " << it->first
<< ", ret = " << MetaStatusCode_Name(ret);
it++;
continue;
}
LOG(INFO) << "Trash delete inode, fsId = " << fsId_
<< ", partitionId = " << partitionId_
<< ", inodeId = " << it.first;
temp.erase(it.first);
<< ", inodeId = " << it->first;
it = temp.erase(it);
} else {
it++;
}
}

Expand Down
2 changes: 1 addition & 1 deletion curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ TEST_F(RaftCliService2Test, ChangePeerTest) {
brpc::Controller cntl;
CliService2_Stub stub(&channel_);
stub.ChangePeers(&cntl, &request, &response, nullptr);
ASSERT_FALSE(cntl.Failed());
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();

// check response
ASSERT_EQ(3, response.oldpeers_size());
Expand Down
12 changes: 6 additions & 6 deletions curvefs/test/metaserver/trash_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
option.mdsClient = mdsClient_;
option.s3Adaptor = s3Adaptor_;
FLAGS_trash_scanPeriodSec = 1;
FLAGS_trash_expiredAfterSec = 1;
FLAGS_trash_expiredAfterSec = 4;
trashManager_->Init(option);
trashManager_->Run();
auto trash1 = std::make_shared<TrashImpl>(inodeStorage_, 1, 1, 1, 1);
auto trash2 = std::make_shared<TrashImpl>(inodeStorage_, 2, 2, 2, 2);
auto trash2 = std::make_shared<TrashImpl>(inodeStorage_, 2, 1, 2, 2);
trashManager_->Add(1, trash1);
trashManager_->Add(2, trash2);
trash1->SetCopysetNode(copysetNode_);
Expand Down Expand Up @@ -214,12 +214,12 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
task.done->Run();
}));

uint64_t dtime = curve::common::TimeUtility::GetTimeofDaySec() - 2;
trash1->Add(1, dtime);
trash1->Add(2, dtime);
uint64_t dtime = curve::common::TimeUtility::GetTimeofDaySec();
trash1->Add(1, dtime - 6);
trash1->Add(2, dtime - 2);
trash2->Add(1, dtime);

std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(5));

ASSERT_EQ(0, trashManager_->Size());
ASSERT_EQ(inodeStorage_->Size(), 0);
Expand Down

0 comments on commit c8de94b

Please sign in to comment.