@@ -283,26 +283,31 @@ MetaStatusCode InodeManager::DeleteInode(uint32_t fsId, uint64_t inodeId,
283
283
VLOG (6 ) << " DeleteInode, fsId = " << fsId << " , inodeId = " << inodeId;
284
284
NameLockGuard lg (inodeLock_, GetInodeLockName (fsId, inodeId));
285
285
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;
292
294
}
293
295
294
- MetaStatusCode ret =
295
- inodeStorage_->Delete (Key4Inode (fsId, inodeId), logIndex);
296
+ ret = inodeStorage_->Delete (Key4Inode (fsId, inodeId), logIndex);
296
297
if (ret != MetaStatusCode::OK) {
297
298
LOG (ERROR) << " DeleteInode fail, fsId = " << fsId
298
299
<< " , inodeId = " << inodeId
299
300
<< " , ret = " << MetaStatusCode_Name (ret);
300
301
return ret;
301
302
}
302
303
303
- if (retGetAttr == MetaStatusCode::OK) {
304
+ // if nlink is 0 means this inode is already in trash
305
+ if (attr.nlink () != 0 ) {
304
306
// get attr success
305
307
--(*type2InodeNum_)[attr.type ()];
308
+ } else {
309
+ // delete trash item
310
+ trash_->Remove (inodeId);
306
311
}
307
312
VLOG (6 ) << " DeleteInode success, fsId = " << fsId
308
313
<< " , inodeId = " << inodeId;
@@ -353,8 +358,7 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
353
358
354
359
if (request.has_nlink ()) {
355
360
if (old.nlink () != 0 && request.nlink () == 0 ) {
356
- uint32_t now = TimeUtility::GetTimeofDaySec ();
357
- old.set_dtime (now);
361
+ old.set_dtime (TimeUtility::GetTimeofDaySec ());
358
362
needAddTrash = true ;
359
363
}
360
364
VLOG (9 ) << " update inode nlink, from " << old.nlink () << " to "
@@ -373,7 +377,6 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
373
377
374
378
bool fileNeedDeallocate =
375
379
(needAddTrash && (FsFileType::TYPE_FILE == old.type ()));
376
- bool s3NeedTrash = (needAddTrash && (FsFileType::TYPE_S3 == old.type ()));
377
380
378
381
std::shared_ptr<storage::StorageTransaction> txn;
379
382
if (needUpdate) {
@@ -388,8 +391,8 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request,
388
391
}
389
392
}
390
393
391
- if (s3NeedTrash ) {
392
- trash_->Add (old.fsid (), old. inodeid (), old.dtime ());
394
+ if (needAddTrash ) {
395
+ trash_->Add (old.inodeid (), old.dtime ());
393
396
--(*type2InodeNum_)[old.type ()];
394
397
}
395
398
@@ -610,25 +613,6 @@ MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(
610
613
return MetaStatusCode::OK;
611
614
}
612
615
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
-
632
616
bool InodeManager::GetInodeIdList (std::list<uint64_t >* inodeIdList) {
633
617
return inodeStorage_->GetAllInodeId (inodeIdList);
634
618
}
0 commit comments