@@ -57,6 +57,7 @@ using ::curvefs::metaserver::storage::Prefix4ChunkIndexS3ChunkInfoList;
5757using ::curvefs::metaserver::storage::Prefix4InodeS3ChunkInfoList;
5858using ::curvefs::metaserver::storage::Prefix4InodeVolumeExtent;
5959using ::curvefs::metaserver::storage::Status;
60+ using curvefs::metaserver::Time;
6061
6162const char * InodeStorage::kInodeCountKey (" count" );
6263
@@ -67,6 +68,7 @@ InodeStorage::InodeStorage(std::shared_ptr<KVStorage> kvStorage,
6768 uint64_t nInode)
6869 : kvStorage_(std::move(kvStorage)),
6970 table4Inode_ (nameGenerator->GetInodeTableName ()),
71+ table4DelInode_(nameGenerator->GetDelInodeTableName ()),
7072 table4S3ChunkInfo_(nameGenerator->GetS3ChunkInfoTableName ()),
7173 table4VolumeExtent_(nameGenerator->GetVolumeExtentTableName ()),
7274 table4InodeAuxInfo_(nameGenerator->GetInodeAuxInfoTableName ()),
@@ -185,9 +187,78 @@ MetaStatusCode InodeStorage::Insert(const Inode& inode, int64_t logIndex) {
185187 return MetaStatusCode::STORAGE_INTERNAL_ERROR;
186188}
187189
190+ MetaStatusCode InodeStorage::AddDeletedInode (
191+ const Key4Inode& keyInode, uint64_t dtime) {
192+ WriteLockGuard lg (rwLock_);
193+ std::string skey = conv_.SerializeToString (keyInode);
194+ VLOG (9 ) << " update deleting key, " << keyInode.inodeId << " , " << dtime;
195+ const char * step = " Begin transaction" ;
196+ std::shared_ptr<storage::StorageTransaction> txn;
197+ txn = kvStorage_->BeginTransaction ();
198+ if (txn == nullptr ) {
199+ LOG (ERROR) << " Begin transaction failed" ;
200+ return MetaStatusCode::STORAGE_INTERNAL_ERROR;
201+ }
202+ Time dtimeInfo;
203+ dtimeInfo.set_sec (dtime);
204+ dtimeInfo.set_nsec (0 );
205+ auto rc = txn->HSet (table4DelInode_, skey, dtimeInfo);
206+ step = " insert inode " ;
207+ if (rc.ok ()) {
208+ rc = txn->Commit ();
209+ step = " commit" ;
210+ }
211+ if (rc.ok ()) {
212+ VLOG (9 ) << " set deleting key ok" ;
213+ return MetaStatusCode::OK;
214+ }
215+ LOG (ERROR) << step << " failed, status = " << rc.ToString ();
216+ if (!txn->Rollback ().ok ()) {
217+ LOG (ERROR) << " Rollback delete inode transaction failed, status = "
218+ << rc.ToString ();
219+ }
220+ return MetaStatusCode::STORAGE_INTERNAL_ERROR;
221+ }
222+
223+ MetaStatusCode InodeStorage::RemoveDeletedInode (const Key4Inode& key) {
224+ WriteLockGuard lg (rwLock_);
225+ std::string skey = conv_.SerializeToString (key);
226+ VLOG (9 ) << " clear deleting key start, " << skey;
227+ std::shared_ptr<storage::StorageTransaction> txn = nullptr ;
228+ const char * step = " Begin transaction" ;
229+ txn = kvStorage_->BeginTransaction ();
230+ if (txn == nullptr ) {
231+ LOG (ERROR) << " Begin transaction failed" ;
232+ return MetaStatusCode::STORAGE_INTERNAL_ERROR;
233+ }
234+ step = " Delete inode from transaction" ;
235+ auto s = txn->HDel (table4DelInode_, skey);
236+ if (s.ok ()) {
237+ step = " Delete inode" ;
238+ s = txn->Commit ();
239+ }
240+ if (s.ok ()) {
241+ VLOG (9 ) << " clear deleting key ok, " << skey;
242+ return MetaStatusCode::OK;
243+ }
244+ LOG (ERROR) << step << " failed, status = " << s.ToString ();
245+ if (!txn->Rollback ().ok ()) {
246+ LOG (ERROR) << " Rollback delete inode transaction failed, status = "
247+ << s.ToString ();
248+ }
249+ return MetaStatusCode::STORAGE_INTERNAL_ERROR;
250+ }
251+
252+ void InodeStorage::LoadDeletedInodes (std::map<std::string, uint64_t > * inodes) {
253+ VLOG (6 ) << " load deleted key start with: " << table4DelInode_;
254+ kvStorage_->GetPrefix (inodes, table4DelInode_);
255+ VLOG (6 ) << " load deleted over" ;
256+ }
257+
188258MetaStatusCode InodeStorage::Get (const Key4Inode& key, Inode* inode) {
189259 ReadLockGuard lg (rwLock_);
190260 std::string skey = conv_.SerializeToString (key);
261+
191262 Status s = kvStorage_->HGet (table4Inode_, skey, inode);
192263 if (s.ok ()) {
193264 return MetaStatusCode::OK;
@@ -471,7 +542,6 @@ MetaStatusCode InodeStorage::Clear() {
471542 // because if we fail stop, we will replay
472543 // raft logs and clear it again
473544 WriteLockGuard lg (rwLock_);
474-
475545 Status s = kvStorage_->HClear (table4Inode_);
476546 if (!s.ok ()) {
477547 LOG (ERROR) << " InodeStorage clear inode table failed, status = "
@@ -492,7 +562,6 @@ MetaStatusCode InodeStorage::Clear() {
492562 << s.ToString ();
493563 return MetaStatusCode::STORAGE_INTERNAL_ERROR;
494564 }
495-
496565 s = kvStorage_->HClear (table4InodeAuxInfo_);
497566 if (!s.ok ()) {
498567 LOG (ERROR)
0 commit comments