Skip to content

Commit bfd5acb

Browse files
committed
curvefs: fix trash will delete file data more than once
Signed-off-by: wanghai01 <[email protected]>
1 parent dd8ce61 commit bfd5acb

11 files changed

+268
-245
lines changed

curvefs/proto/metaserver.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ message Inode {
267267
optional uint64 rdev = 16;
268268
// field 17 is left for compatibility
269269
map<uint64, S3ChunkInfoList> s3ChunkInfoMap = 18; // TYPE_S3 only, first is chunk index
270-
optional uint32 dtime = 19;
270+
optional uint64 dtime = 19;
271271
optional uint32 openmpcount = 20; // openmpcount mount points had the file open
272272
map<string, bytes> xattr = 21;
273273
repeated uint64 parent = 22;

curvefs/src/metaserver/inode_manager.cpp

+17-33
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,31 @@ MetaStatusCode InodeManager::DeleteInode(uint32_t fsId, uint64_t inodeId,
283283
VLOG(6) << "DeleteInode, fsId = " << fsId << ", inodeId = " << inodeId;
284284
NameLockGuard lg(inodeLock_, GetInodeLockName(fsId, inodeId));
285285
InodeAttr attr;
286-
MetaStatusCode retGetAttr =
287-
inodeStorage_->GetAttr(Key4Inode(fsId, inodeId), &attr);
288-
if (retGetAttr != MetaStatusCode::OK) {
289-
VLOG(9) << "GetInodeAttr fail, fsId = " << fsId
290-
<< ", inodeId = " << inodeId
291-
<< ", ret = " << MetaStatusCode_Name(retGetAttr);
286+
auto ret = inodeStorage_->GetAttr(Key4Inode(fsId, inodeId), &attr);
287+
if (ret == MetaStatusCode::NOT_FOUND) {
288+
return MetaStatusCode::OK;
289+
} else if (ret != MetaStatusCode::OK) {
290+
LOG(ERROR) << "GetInodeAttr fail, fsId = " << fsId
291+
<< ", inodeId = " << inodeId
292+
<< ", ret = " << MetaStatusCode_Name(ret);
293+
return ret;
292294
}
293295

294-
MetaStatusCode ret =
295-
inodeStorage_->Delete(Key4Inode(fsId, inodeId), logIndex);
296+
ret = inodeStorage_->Delete(Key4Inode(fsId, inodeId), logIndex);
296297
if (ret != MetaStatusCode::OK) {
297298
LOG(ERROR) << "DeleteInode fail, fsId = " << fsId
298299
<< ", inodeId = " << inodeId
299300
<< ", ret = " << MetaStatusCode_Name(ret);
300301
return ret;
301302
}
302303

303-
if (retGetAttr == MetaStatusCode::OK) {
304+
// if nlink is 0 means this inode is already in trash
305+
if (attr.nlink() != 0) {
304306
// get attr success
305307
--(*type2InodeNum_)[attr.type()];
308+
} else {
309+
// delete trash item
310+
trash_->Remove(inodeId);
306311
}
307312
VLOG(6) << "DeleteInode success, fsId = " << fsId
308313
<< ", inodeId = " << inodeId;
@@ -353,8 +358,7 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
353358

354359
if (request.has_nlink()) {
355360
if (old.nlink() != 0 && request.nlink() == 0) {
356-
uint32_t now = TimeUtility::GetTimeofDaySec();
357-
old.set_dtime(now);
361+
old.set_dtime(TimeUtility::GetTimeofDaySec());
358362
needAddTrash = true;
359363
}
360364
VLOG(9) << "update inode nlink, from " << old.nlink() << " to "
@@ -373,7 +377,6 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
373377

374378
bool fileNeedDeallocate =
375379
(needAddTrash && (FsFileType::TYPE_FILE == old.type()));
376-
bool s3NeedTrash = (needAddTrash && (FsFileType::TYPE_S3 == old.type()));
377380

378381
std::shared_ptr<storage::StorageTransaction> txn;
379382
if (needUpdate) {
@@ -388,8 +391,8 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
388391
}
389392
}
390393

391-
if (s3NeedTrash) {
392-
trash_->Add(old.fsid(), old.inodeid(), old.dtime());
394+
if (needAddTrash) {
395+
trash_->Add(old.inodeid(), old.dtime());
393396
--(*type2InodeNum_)[old.type()];
394397
}
395398

@@ -610,25 +613,6 @@ MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(
610613
return MetaStatusCode::OK;
611614
}
612615

613-
MetaStatusCode InodeManager::InsertInode(const Inode& inode, int64_t logIndex) {
614-
CHECK_APPLIED();
615-
VLOG(6) << "InsertInode, " << inode.ShortDebugString();
616-
617-
// 2. insert inode
618-
MetaStatusCode ret = inodeStorage_->Insert(inode, logIndex);
619-
if (ret != MetaStatusCode::OK) {
620-
LOG(ERROR) << "InsertInode fail, " << inode.ShortDebugString()
621-
<< ", ret = " << MetaStatusCode_Name(ret);
622-
return ret;
623-
}
624-
625-
if (inode.nlink() == 0) {
626-
trash_->Add(inode.fsid(), inode.inodeid(), inode.dtime());
627-
}
628-
629-
return MetaStatusCode::OK;
630-
}
631-
632616
bool InodeManager::GetInodeIdList(std::list<uint64_t>* inodeIdList) {
633617
return inodeStorage_->GetAllInodeId(inodeIdList);
634618
}

curvefs/src/metaserver/inode_manager.h

-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class InodeManager {
108108
MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(
109109
const Dentry& dentry, const Time& tm, bool isCreate, int64_t logIndex);
110110

111-
MetaStatusCode InsertInode(const Inode& inode, int64_t logIndex);
112-
113111
bool GetInodeIdList(std::list<uint64_t>* inodeIdList);
114112

115113
// Update one or more volume extent slice

curvefs/src/metaserver/partition.cpp

+7-14
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ Partition::Partition(PartitionInfo partition,
6969
dentryStorage_ =
7070
std::make_shared<DentryStorage>(kvStorage_, nameGen_, nDentry);
7171

72-
auto trash = std::make_shared<TrashImpl>(inodeStorage_);
72+
auto trash = std::make_shared<TrashImpl>(inodeStorage_,
73+
partitionInfo_.fsid(), partitionInfo_.poolid(),
74+
partitionInfo_.copysetid(), partitionInfo_.partitionid());
7375
inodeManager_ = std::make_shared<InodeManager>(
7476
inodeStorage_, trash, partitionInfo_.mutable_filetype2inodenum());
7577
txManager_ = std::make_shared<TxManager>(dentryStorage_, partitionInfo_);
@@ -359,15 +361,6 @@ MetaStatusCode Partition::PaddingInodeS3ChunkInfo(int32_t fsId,
359361
return inodeManager_->PaddingInodeS3ChunkInfo(fsId, inodeId, m, limit);
360362
}
361363

362-
MetaStatusCode Partition::InsertInode(const Inode& inode, int64_t logIndex) {
363-
PRECHECK(inode.fsid(), inode.inodeid());
364-
auto ret = inodeManager_->InsertInode(inode, logIndex);
365-
if (ret == MetaStatusCode::IDEMPOTENCE_OK) {
366-
ret = MetaStatusCode::OK;
367-
}
368-
return ret;
369-
}
370-
371364
bool Partition::GetInodeIdList(std::list<uint64_t>* InodeIdList) {
372365
return inodeManager_->GetInodeIdList(InodeIdList);
373366
}
@@ -470,12 +463,12 @@ uint64_t Partition::GetNewInodeId() {
470463
return newInodeId;
471464
}
472465

473-
uint32_t Partition::GetInodeNum() {
474-
return static_cast<uint32_t>(inodeStorage_->Size());
466+
uint64_t Partition::GetInodeNum() {
467+
return inodeStorage_->Size();
475468
}
476469

477-
uint32_t Partition::GetDentryNum() {
478-
return static_cast<uint32_t>(dentryStorage_->Size());
470+
uint64_t Partition::GetDentryNum() {
471+
return dentryStorage_->Size();
479472
}
480473

481474
bool Partition::EmptyInodeStorage() { return inodeStorage_->Empty(); }

curvefs/src/metaserver/partition.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ class Partition {
138138
virtual MetaStatusCode GetAllBlockGroup(
139139
std::vector<DeallocatableBlockGroup>* deallocatableBlockGroupVec);
140140

141-
MetaStatusCode InsertInode(const Inode& inode, int64_t logIndex);
142-
143141
bool GetInodeIdList(std::list<uint64_t>* InodeIdList);
144142

145143
// if partition has no inode or no dentry, it is deletable
@@ -167,9 +165,9 @@ class Partition {
167165
// if no available inode id in this partiton ,return UINT64_MAX
168166
uint64_t GetNewInodeId();
169167

170-
uint32_t GetInodeNum();
168+
uint64_t GetInodeNum();
171169

172-
uint32_t GetDentryNum();
170+
uint64_t GetDentryNum();
173171

174172
bool EmptyInodeStorage();
175173

0 commit comments

Comments
 (0)