Skip to content

Commit c8de94b

Browse files
SeanHaiwuhongsong
authored andcommitted
fix trash loop and utest
Signed-off-by: wanghai01 <seanhaizi@163.com>
1 parent abe27ed commit c8de94b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

curvefs/src/metaserver/trash.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ void TrashImpl::Remove(uint64_t inodeId) {
9292

9393
void TrashImpl::ScanTrash() {
9494
LockGuard lgScan(scanMutex_);
95+
LOG(INFO) << "ScanTrash, fsId = " << fsId_
96+
<< ", partitionId = " << partitionId_
97+
<< ", trashItems size = " << trashItems_.size();
9598
// only scan on leader
9699
if (copysetNode_ == nullptr || !copysetNode_->IsLeaderTerm()) {
97100
return;
@@ -103,22 +106,25 @@ void TrashImpl::ScanTrash() {
103106
trashItems_.swap(temp);
104107
}
105108

106-
for (auto& it : temp) {
109+
for (auto it = temp.begin(); it != temp.end();) {
107110
if (isStop_ || !copysetNode_->IsLeaderTerm()) {
108111
return;
109112
}
110-
if (NeedDelete(it.second)) {
111-
MetaStatusCode ret = DeleteInodeAndData(it.first);
113+
if (NeedDelete(it->second)) {
114+
MetaStatusCode ret = DeleteInodeAndData(it->first);
112115
if (ret != MetaStatusCode::OK) {
113116
LOG(ERROR) << "DeleteInodeAndData fail, fsId = " << fsId_
114-
<< ", inodeId = " << it.first
117+
<< ", inodeId = " << it->first
115118
<< ", ret = " << MetaStatusCode_Name(ret);
119+
it++;
116120
continue;
117121
}
118122
LOG(INFO) << "Trash delete inode, fsId = " << fsId_
119123
<< ", partitionId = " << partitionId_
120-
<< ", inodeId = " << it.first;
121-
temp.erase(it.first);
124+
<< ", inodeId = " << it->first;
125+
it = temp.erase(it);
126+
} else {
127+
it++;
122128
}
123129
}
124130

curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ TEST_F(RaftCliService2Test, ChangePeerTest) {
495495
brpc::Controller cntl;
496496
CliService2_Stub stub(&channel_);
497497
stub.ChangePeers(&cntl, &request, &response, nullptr);
498-
ASSERT_FALSE(cntl.Failed());
498+
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
499499

500500
// check response
501501
ASSERT_EQ(3, response.oldpeers_size());

curvefs/test/metaserver/trash_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
162162
option.mdsClient = mdsClient_;
163163
option.s3Adaptor = s3Adaptor_;
164164
FLAGS_trash_scanPeriodSec = 1;
165-
FLAGS_trash_expiredAfterSec = 1;
165+
FLAGS_trash_expiredAfterSec = 4;
166166
trashManager_->Init(option);
167167
trashManager_->Run();
168168
auto trash1 = std::make_shared<TrashImpl>(inodeStorage_, 1, 1, 1, 1);
169-
auto trash2 = std::make_shared<TrashImpl>(inodeStorage_, 2, 2, 2, 2);
169+
auto trash2 = std::make_shared<TrashImpl>(inodeStorage_, 2, 1, 2, 2);
170170
trashManager_->Add(1, trash1);
171171
trashManager_->Add(2, trash2);
172172
trash1->SetCopysetNode(copysetNode_);
@@ -214,12 +214,12 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
214214
task.done->Run();
215215
}));
216216

217-
uint64_t dtime = curve::common::TimeUtility::GetTimeofDaySec() - 2;
218-
trash1->Add(1, dtime);
219-
trash1->Add(2, dtime);
217+
uint64_t dtime = curve::common::TimeUtility::GetTimeofDaySec();
218+
trash1->Add(1, dtime - 6);
219+
trash1->Add(2, dtime - 2);
220220
trash2->Add(1, dtime);
221221

222-
std::this_thread::sleep_for(std::chrono::seconds(2));
222+
std::this_thread::sleep_for(std::chrono::seconds(5));
223223

224224
ASSERT_EQ(0, trashManager_->Size());
225225
ASSERT_EQ(inodeStorage_->Size(), 0);

0 commit comments

Comments
 (0)