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 17, 2022
1 parent 7e03daa commit 2327c38
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 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 isLoading = 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 @@ -67,7 +67,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
14 changes: 3 additions & 11 deletions curvefs/src/metaserver/storage/rocksdb_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,14 @@ class RocksDBStorageComparator : public rocksdb::Comparator {
// if slice1 == slice2, return 0
int Compare(const rocksdb::Slice& slice1,
const rocksdb::Slice& slice2) const override {
std::string key1 = std::string(slice1.data(), slice1.size());
std::string key2 = std::string(slice2.data(), slice2.size());
size_t num1 = BinrayString2Number(key1);
size_t num2 = BinrayString2Number(key2);
size_t num1 = BinrayString2Number(slice1);
size_t num2 = BinrayString2Number(slice2);
if (num1 < num2) {
return -1;
} else if (num1 > num2) {
return 1;
}
// n1 == n2
if (key1 < key2) {
return -1;
} else if (key1 > key2) {
return 1;
}
return 0;
return slice1.compare(slice2);
}

// Ignore the following methods for now
Expand Down
9 changes: 9 additions & 0 deletions curvefs/src/metaserver/storage/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ size_t BinrayString2Number(const std::string& str) {
return *reinterpret_cast<const size_t*>(str.c_str());
}

size_t BinrayString2Number(const rocksdb::Slice& value) {
if (value.size() < sizeof(size_t)) {
LOG(ERROR) << "The length of binray string must equal or greater than "
<< sizeof(size_t) << ", but now is " << value.size();
return 0;
}
return *reinterpret_cast<const size_t*>(value.data());
}

bool GetFileSystemSpaces(const std::string& path,
uint64_t* total,
uint64_t* available) {
Expand Down
3 changes: 3 additions & 0 deletions curvefs/src/metaserver/storage/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "absl/container/btree_set.h"
#include "src/common/concurrent/rw_lock.h"
#include "rocksdb/slice.h"

namespace curvefs {
namespace metaserver {
Expand All @@ -42,6 +43,8 @@ std::string Number2BinaryString(size_t num);

size_t BinrayString2Number(const std::string& value);

size_t BinrayString2Number(const rocksdb::Slice& value);

bool GetFileSystemSpaces(const std::string& path,
uint64_t* capacity,
uint64_t* available);
Expand Down

0 comments on commit 2327c38

Please sign in to comment.