Skip to content

Commit

Permalink
style(fs): fix style
Browse files Browse the repository at this point in the history
Signed-off-by: NaturalSelect <2145973003@qq.com>
  • Loading branch information
NaturalSelect committed Aug 17, 2023
1 parent 5203854 commit 8694473
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 62 deletions.
12 changes: 6 additions & 6 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request,

std::shared_ptr<storage::StorageTransaction> txn;
if (needUpdate) {
ret = inodeStorage_->Update(txn, old, logIndex, fileNeedDeallocate);
ret = inodeStorage_->Update(&txn, old, logIndex, fileNeedDeallocate);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "UpdateInode fail, " << request.ShortDebugString()
<< ", ret: " << MetaStatusCode_Name(ret);
Expand All @@ -398,7 +398,7 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request,
uint64_t chunkIndex = item.first;
list2add = &item.second;
MetaStatusCode rc = inodeStorage_->ModifyInodeS3ChunkInfoList(
txn, old.fsid(), old.inodeid(), chunkIndex, list2add, nullptr,
&txn, old.fsid(), old.inodeid(), chunkIndex, list2add, nullptr,
logIndex);
if (rc != MetaStatusCode::OK) {
LOG(ERROR) << "Modify inode s3chunkinfo list failed, fsId="
Expand All @@ -416,7 +416,7 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request,
const auto fsId = old.fsid();
const auto inodeId = old.inodeid();
for (const auto &slice : request.volumeextents().slices()) {
auto rc = UpdateVolumeExtentSliceLocked(txn, fsId, inodeId, slice,
auto rc = UpdateVolumeExtentSliceLocked(&txn, fsId, inodeId, slice,
logIndex);
if (rc != MetaStatusCode::OK) {
LOG(ERROR) << "UpdateVolumeExtent failed, err: "
Expand Down Expand Up @@ -474,7 +474,7 @@ MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo(
}

auto rc = inodeStorage_->ModifyInodeS3ChunkInfoList(
txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
&txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
if (rc != MetaStatusCode::OK) {
LOG(ERROR) << "Modify inode s3chunkinfo list failed, fsId=" << fsId
<< ", inodeId=" << inodeId << ", retCode=" << rc;
Expand All @@ -495,7 +495,7 @@ MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo(
list2add = nullptr;
list2del = &item.second;
auto rc = inodeStorage_->ModifyInodeS3ChunkInfoList(
txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
&txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
if (rc != MetaStatusCode::OK) {
LOG(ERROR) << "Modify inode s3chunkinfo list failed, fsId=" << fsId
<< ", inodeId=" << inodeId << ", retCode=" << rc;
Expand Down Expand Up @@ -627,7 +627,7 @@ InodeManager::UpdateVolumeExtentSliceLocked(uint32_t fsId, uint64_t inodeId,
}

MetaStatusCode InodeManager::UpdateVolumeExtentSliceLocked(
std::shared_ptr<storage::StorageTransaction> &txn, uint32_t fsId,
std::shared_ptr<storage::StorageTransaction> *txn, uint32_t fsId,
uint64_t inodeId, const VolumeExtentSlice &slice, std::int64_t logIndex) {
return inodeStorage_->UpdateVolumeExtentSlice(txn, fsId, inodeId, slice,
logIndex);
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/metaserver/inode_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class InodeManager {
std::int64_t logIndex);

MetaStatusCode UpdateVolumeExtentSliceLocked(
std::shared_ptr<storage::StorageTransaction> &txn, uint32_t fsId,
std::shared_ptr<storage::StorageTransaction> *txn, uint32_t fsId,
uint64_t inodeId, const VolumeExtentSlice &slice,
std::int64_t logIndex);

Expand Down
51 changes: 25 additions & 26 deletions curvefs/src/metaserver/inode_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Author: chenwei
*/

#include <cstddef>
#include <google/protobuf/empty.pb.h>

#include <limits>
Expand Down Expand Up @@ -365,12 +364,12 @@ MetaStatusCode InodeStorage::Delete(const Key4Inode &key,
}

MetaStatusCode
InodeStorage::Update(std::shared_ptr<storage::StorageTransaction> &txn,
InodeStorage::Update(std::shared_ptr<storage::StorageTransaction> *txn,
const Inode &inode, std::int64_t logIndex,
bool inodeDeallocate) {
if (txn == nullptr) {
txn = kvStorage_->BeginTransaction();
if (txn == nullptr) {
if (*txn == nullptr) {
*txn = kvStorage_->BeginTransaction();
if (*txn == nullptr) {
LOG(ERROR) << "Begin transaction failed";
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
Expand All @@ -379,24 +378,24 @@ InodeStorage::Update(std::shared_ptr<storage::StorageTransaction> &txn,
Key4Inode key(inode.fsid(), inode.inodeid());
std::string skey = conv_.SerializeToString(key);
storage::Status s;
s = SetAppliedIndex(txn.get(), logIndex);
s = SetAppliedIndex(txn->get(), logIndex);
if (!s.ok()) {
LOG(ERROR) << "Insert applied index to transaction failed, status = "
<< s.ToString();
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
if (!inodeDeallocate) {
s = txn->HSet(table4Inode_, skey, inode);
s = (*txn)->HSet(table4Inode_, skey, inode);
if (s.ok()) {
return MetaStatusCode::OK;
}
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
google::protobuf::Empty value;
std::string step = "update inode " + key.SerializeToString();
s = txn->HSet(table4Inode_, skey, inode);
s = (*txn)->HSet(table4Inode_, skey, inode);
if (s.ok()) {
s = txn->HSet(table4DeallocatableInode_, skey, value);
s = (*txn)->HSet(table4DeallocatableInode_, skey, value);
step = "add inode " + key.SerializeToString() +
" to inode deallocatable list";
}
Expand All @@ -410,7 +409,7 @@ InodeStorage::Update(std::shared_ptr<storage::StorageTransaction> &txn,
MetaStatusCode InodeStorage::Update(const Inode &inode, std::int64_t logIndex,
bool inodeDeallocate) {
std::shared_ptr<storage::StorageTransaction> txn;
if (Update(txn, inode, logIndex, inodeDeallocate) == MetaStatusCode::OK) {
if (Update(&txn, inode, logIndex, inodeDeallocate) == MetaStatusCode::OK) {
storage::Status s = txn->Commit();
if (!s.ok()) {
LOG(ERROR) << "Commit update inode transaction failed, status = "
Expand Down Expand Up @@ -679,22 +678,22 @@ InodeStorage::DelS3ChunkInfoList(Transaction txn, uint32_t fsId,
}

MetaStatusCode InodeStorage::ModifyInodeS3ChunkInfoList(
std::shared_ptr<StorageTransaction> &txn, uint32_t fsId, uint64_t inodeId,
std::shared_ptr<StorageTransaction> *txn, uint32_t fsId, uint64_t inodeId,
uint64_t chunkIndex, const S3ChunkInfoList *list2add,
const S3ChunkInfoList *list2del, std::int64_t logIndex) {
if (txn == nullptr) {
txn = kvStorage_->BeginTransaction();
if (txn == nullptr) {
if (*txn == nullptr) {
*txn = kvStorage_->BeginTransaction();
if (*txn == nullptr) {
LOG(ERROR) << "Begin transaction failed";
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
}
WriteLockGuard lg(rwLock_);
std::string step;
auto rc = DelS3ChunkInfoList(txn, fsId, inodeId, chunkIndex, list2del);
auto rc = DelS3ChunkInfoList(*txn, fsId, inodeId, chunkIndex, list2del);
step = "del s3 chunkinfo list ";
if (rc == MetaStatusCode::OK) {
rc = AddS3ChunkInfoList(txn, fsId, inodeId, chunkIndex, list2add);
rc = AddS3ChunkInfoList(*txn, fsId, inodeId, chunkIndex, list2add);
step = "add s3 chunkInfo list ";
}

Expand All @@ -705,11 +704,11 @@ MetaStatusCode InodeStorage::ModifyInodeS3ChunkInfoList(
(nullptr == list2del) ? 0 : list2del->s3chunks_size();
// TODO(huyao): I don't think this place is idempotent. If the timeout
// is retried, the size will increase.
rc = UpdateInodeS3MetaSize(txn, fsId, inodeId, size4add, size4del);
rc = UpdateInodeS3MetaSize(*txn, fsId, inodeId, size4add, size4del);
step = "update inode s3 meta size ";
}
if (rc == MetaStatusCode::OK) {
if (!SetAppliedIndex(txn.get(), logIndex).ok()) {
if (!SetAppliedIndex(txn->get(), logIndex).ok()) {
step = "Insert applied index";
rc = MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
Expand All @@ -726,7 +725,7 @@ MetaStatusCode InodeStorage::ModifyInodeS3ChunkInfoList(
std::int64_t logIndex) {
std::shared_ptr<storage::StorageTransaction> txn;
MetaStatusCode rc = ModifyInodeS3ChunkInfoList(
txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
&txn, fsId, inodeId, chunkIndex, list2add, list2del, logIndex);
if (rc != MetaStatusCode::OK) {
if (!txn->Rollback().ok()) {
LOG(ERROR) << "Rollback transaction failed";
Expand Down Expand Up @@ -804,26 +803,26 @@ std::shared_ptr<Iterator> InodeStorage::GetAllVolumeExtentList() {
}

MetaStatusCode InodeStorage::UpdateVolumeExtentSlice(
std::shared_ptr<storage::StorageTransaction> &txn, uint32_t fsId,
std::shared_ptr<storage::StorageTransaction> *txn, uint32_t fsId,
uint64_t inodeId, const VolumeExtentSlice &slice, std::int64_t logIndex) {
WriteLockGuard guard(rwLock_);
if (txn == nullptr) {
txn = kvStorage_->BeginTransaction();
if (txn == nullptr) {
if (*txn == nullptr) {
*txn = kvStorage_->BeginTransaction();
if (*txn == nullptr) {
LOG(ERROR) << "Begin transaction failed";
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
}
auto key = conv_.SerializeToString(
Key4VolumeExtentSlice{fsId, inodeId, slice.offset()});
auto st = txn->SSet(table4VolumeExtent_, key, slice);
auto st = (*txn)->SSet(table4VolumeExtent_, key, slice);
if (!st.ok()) {
LOG(ERROR)
<< "Update volume extent slice to transaction failed, status = "
<< st.ToString();
return MetaStatusCode::STORAGE_INTERNAL_ERROR;
}
st = SetAppliedIndex(txn.get(), logIndex);
st = SetAppliedIndex(txn->get(), logIndex);
if (!st.ok()) {
LOG(ERROR) << "Insert applied index to transaction failed, status = "
<< st.ToString();
Expand All @@ -837,7 +836,7 @@ InodeStorage::UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId,
const VolumeExtentSlice &slice,
std::int64_t logIndex) {
std::shared_ptr<storage::StorageTransaction> txn;
auto rc = UpdateVolumeExtentSlice(txn, fsId, inodeId, slice, logIndex);
auto rc = UpdateVolumeExtentSlice(&txn, fsId, inodeId, slice, logIndex);
if (rc != MetaStatusCode::OK) {
if (txn != nullptr && !txn->Rollback().ok()) {
LOG(ERROR) << "Rollback transaction failed";
Expand Down
6 changes: 3 additions & 3 deletions curvefs/src/metaserver/inode_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class InodeStorage {
MetaStatusCode Update(const Inode &inode, std::int64_t logIndex,
bool inodeDeallocate = false);

MetaStatusCode Update(std::shared_ptr<storage::StorageTransaction> &txn,
MetaStatusCode Update(std::shared_ptr<storage::StorageTransaction> *txn,
const Inode &inode, std::int64_t logIndex,
bool inodeDeallocate = false);

Expand All @@ -141,7 +141,7 @@ class InodeStorage {
std::int64_t logIndex);

MetaStatusCode ModifyInodeS3ChunkInfoList(
std::shared_ptr<StorageTransaction> &txn, uint32_t fsId,
std::shared_ptr<StorageTransaction> *txn, uint32_t fsId,
uint64_t inodeId, uint64_t chunkIndex, const S3ChunkInfoList *list2add,
const S3ChunkInfoList *list2del, std::int64_t logIndex);

Expand All @@ -162,7 +162,7 @@ class InodeStorage {
std::int64_t logIndex);

MetaStatusCode
UpdateVolumeExtentSlice(std::shared_ptr<storage::StorageTransaction> &txn,
UpdateVolumeExtentSlice(std::shared_ptr<storage::StorageTransaction> *txn,
uint32_t fsId, uint64_t inodeId,
const VolumeExtentSlice &slice,
std::int64_t logIndex);
Expand Down
4 changes: 2 additions & 2 deletions curvefs/src/metaserver/metastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ using ::curvefs::metaserver::storage::StorageOptions;
// (table1 table2 table3)
// | | |
// dentry s3chunkinfo volumnextent

// NOTE: we need to add a `logIndex` argument to
//
// NOTE: we need to add a `logIndex` argument to
// each function, than we can filter the log entry
// already applied during `on_snapshot_save`
class MetaStore {
Expand Down
3 changes: 0 additions & 3 deletions curvefs/src/metaserver/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

#include "curvefs/src/metaserver/dentry_storage.h"
#include "curvefs/src/metaserver/transaction.h"
#include <memory>
#include <string>
#include <utility>

namespace curvefs {
namespace metaserver {
Expand Down
1 change: 1 addition & 0 deletions curvefs/src/metaserver/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <memory>
#include <unordered_map>
#include <string>
#include <utility>

#include "src/common/concurrent/rw_lock.h"
#include "curvefs/src/metaserver/dentry_storage.h"
Expand Down
2 changes: 1 addition & 1 deletion curvefs/test/metaserver/dentry_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DentryStorageTest : public ::testing::Test {
void SetUp() override {
nameGenerator_ = std::make_shared<NameGenerator>(1);
dataDir_ = RandomStoragePath();
;

StorageOptions options;
options.dataDir = dataDir_;
options.localFileSystem = localfs.get();
Expand Down
2 changes: 1 addition & 1 deletion curvefs/test/metaserver/partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PartitionTest : public ::testing::Test {
param_.rdev = 0;

dataDir_ = RandomStoragePath();
;

StorageOptions options;
options.dataDir = dataDir_;
options.localFileSystem = localfs.get();
Expand Down
Loading

0 comments on commit 8694473

Please sign in to comment.