Skip to content

Commit

Permalink
curvefs/metaserver: skip find dentry when loading from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-hanqing committed May 25, 2022
1 parent 9922978 commit f79f1d7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions curvefs/src/metaserver/dentry_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ void DentryManager::Log4Code(const std::string& request, MetaStatusCode rc) {
}
}

MetaStatusCode DentryManager::CreateDentry(const Dentry& dentry) {
MetaStatusCode DentryManager::CreateDentry(const Dentry& dentry,
bool isLoadding) {
Log4Dentry("CreateDentry", dentry);
MetaStatusCode rc;
// invoke only from snapshot loading
if (dentry.flag() & DentryFlag::TRANSACTION_PREPARE_FLAG) {
rc = dentryStorage_->HandleTx(DentryStorage::TX_OP_TYPE::PREPARE,
dentry);
} else {
rc = dentryStorage_->Insert(dentry);
rc = dentryStorage_->Insert(dentry, isLoadding);
}
Log4Code("CreateDentry", rc);
return rc;
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/metaserver/dentry_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DentryManager {
DentryManager(std::shared_ptr<DentryStorage> dentryStorage,
std::shared_ptr<TxManager> txManger);

MetaStatusCode CreateDentry(const Dentry& dentry);
MetaStatusCode CreateDentry(const Dentry& dentry, bool isLoadding = false);

MetaStatusCode DeleteDentry(const Dentry& dentry);

Expand Down
20 changes: 11 additions & 9 deletions curvefs/src/metaserver/dentry_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,20 @@ MetaStatusCode DentryStorage::Find(const Dentry& in,
return rc;
}

MetaStatusCode DentryStorage::Insert(const Dentry& dentry) {
MetaStatusCode DentryStorage::Insert(const Dentry& dentry, bool isLoadding) {
WriteLockGuard w(rwLock_);

Dentry out;
MetaStatusCode rc = Find(dentry, &out, true);
if (rc == MetaStatusCode::OK) {
if (IsSameDentry(out, dentry)) {
return MetaStatusCode::IDEMPOTENCE_OK;
if (!isLoadding) {
Dentry out;
MetaStatusCode rc = Find(dentry, &out, true);
if (rc == MetaStatusCode::OK) {
if (IsSameDentry(out, dentry)) {
return MetaStatusCode::IDEMPOTENCE_OK;
}
return MetaStatusCode::DENTRY_EXIST;
} else if (rc != MetaStatusCode::NOT_FOUND) {
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
return MetaStatusCode::DENTRY_EXIST;
} else if (rc != MetaStatusCode::NOT_FOUND) {
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}

// MetaStatusCode::NOT_FOUND
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/metaserver/dentry_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DentryStorage {
DentryStorage(std::shared_ptr<KVStorage> kvStorage,
const std::string& tablename);

MetaStatusCode Insert(const Dentry& dentry);
MetaStatusCode Insert(const Dentry& dentry, bool isLoadding = false);

MetaStatusCode Delete(const Dentry& dentry);

Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, bool isLoadding) {
if (GetStatus() == PartitionStatus::DELETING) {
return MetaStatusCode::PARTITION_DELETING;
}
MetaStatusCode ret = dentryManager_->CreateDentry(dentry);
MetaStatusCode ret = dentryManager_->CreateDentry(dentry, isLoadding);
if (MetaStatusCode::OK == ret) {
if (!isLoadding) {
return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
Expand Down

0 comments on commit f79f1d7

Please sign in to comment.