Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: curvefs: merge two rpc into one when delete #2744

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ message DeleteDentryRequest {
required uint64 parentInodeId = 6;
required string name = 7;
optional FsFileType type = 8;
optional Time create = 9;
}

message DeleteDentryResponse {
Expand Down
38 changes: 0 additions & 38 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,35 +368,6 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req,
return HandleOpenFlags(req, ino, fi, fileOut);
}

CURVEFS_ERROR FuseClient::UpdateParentMCTimeAndNlink(
fuse_ino_t parent, FsFileType type, NlinkChange nlink) {

std::shared_ptr<InodeWrapper> parentInodeWrapper;
auto ret = inodeManager_->GetInode(parent, parentInodeWrapper);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "inodeManager get inode fail, ret = " << ret
<< ", inodeid = " << parent;
return ret;
}

{
curve::common::UniqueLock lk = parentInodeWrapper->GetUniqueLock();
parentInodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);

if (FsFileType::TYPE_DIRECTORY == type) {
parentInodeWrapper->UpdateNlinkLocked(nlink);
}

if (option_.fileSystemOption.deferSyncOption.deferDirMtime) {
inodeManager_->ShipToFlush(parentInodeWrapper);
} else {
return parentInodeWrapper->SyncAttr();
}
}

return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR FuseClient::MakeNode(
fuse_req_t req,
fuse_ino_t parent,
Expand Down Expand Up @@ -535,15 +506,6 @@ CURVEFS_ERROR FuseClient::DeleteNode(uint64_t ino, fuse_ino_t parent,
return ret;
}

ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kSubOne);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << type;
return ret;
}

std::shared_ptr<InodeWrapper> inodeWrapper;
ret = inodeManager_->GetInode(ino, inodeWrapper);
if (ret != CURVEFS_ERROR::OK) {
Expand Down
3 changes: 0 additions & 3 deletions curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ class FuseClient {
private:
virtual void FlushData() = 0;

CURVEFS_ERROR UpdateParentMCTimeAndNlink(
fuse_ino_t parent, FsFileType type, NlinkChange nlink);

std::string GenerateNewRecycleName(fuse_ino_t ino,
fuse_ino_t parent, const char* name) {
std::string newName(name);
Expand Down
17 changes: 3 additions & 14 deletions curvefs/src/client/rpcclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <brpc/closure_guard.h>
#include <butil/iobuf.h>
#include <glog/logging.h>
#include <time.h>

#include <cstddef>
#include <memory>
Expand Down Expand Up @@ -255,12 +254,7 @@ MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
d->set_txid(txId);
d->set_type(dentry.type());
request.set_allocated_dentry(d);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
Time *tm = new Time();
tm->set_sec(now.tv_sec);
tm->set_nsec(now.tv_nsec);
request.set_allocated_create(tm);
SetCreateTime(request.mutable_create());
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateDentry(cntl, &request, &response, nullptr);

Expand Down Expand Up @@ -321,7 +315,7 @@ MetaStatusCode MetaServerClientImpl::DeleteDentry(uint32_t fsId,
request.set_name(name);
request.set_txid(txId);
request.set_type(type);

SetCreateTime(request.mutable_create());
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.DeleteDentry(cntl, &request, &response, nullptr);

Expand Down Expand Up @@ -1147,12 +1141,7 @@ MetaStatusCode MetaServerClientImpl::CreateInode(const InodeParam &param,
request.set_rdev(param.rdev);
request.set_symlink(param.symlink);
request.set_parent(param.parent);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
Time *tm = new Time();
tm->set_sec(now.tv_sec);
tm->set_nsec(now.tv_nsec);
request.set_allocated_create(tm);
SetCreateTime(request.mutable_create());
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateInode(cntl, &request, &response, nullptr);

Expand Down
9 changes: 9 additions & 0 deletions curvefs/src/client/rpcclient/metaserver_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef CURVEFS_SRC_CLIENT_RPCCLIENT_METASERVER_CLIENT_H_
#define CURVEFS_SRC_CLIENT_RPCCLIENT_METASERVER_CLIENT_H_

#include <time.h>

#include <list>
#include <memory>
#include <string>
Expand Down Expand Up @@ -70,6 +72,13 @@ struct DataIndices {
absl::optional<VolumeExtentSliceList> volumeExtents;
};

inline void SetCreateTime(Time* tm) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
tm->set_sec(now.tv_sec);
tm->set_nsec(now.tv_nsec);
}

class MetaServerClient {
public:
virtual ~MetaServerClient() = default;
Expand Down
5 changes: 3 additions & 2 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,11 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId,
}

MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(
const Dentry& dentry, uint64_t now, uint32_t now_ns, bool isCreate,
int64_t logIndex) {
const Dentry& dentry, const Time& tm, bool isCreate, int64_t logIndex) {
uint64_t fsId = dentry.fsid();
uint64_t parentInodeId = dentry.parentinodeid();
uint64_t now = tm.sec();
uint32_t now_ns = tm.nsec();
FsFileType type = dentry.type();
MetaStatusCode ret = MetaStatusCode::OK;

Expand Down
7 changes: 2 additions & 5 deletions curvefs/src/metaserver/inode_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ class InodeManager {
S3ChunkInfoMap* m,
uint64_t limit = 0);

MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(const Dentry& dentry,
uint64_t now,
uint32_t now_ns,
bool isCreate,
int64_t logIndex);
MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(
const Dentry& dentry, const Time& tm, bool isCreate, int64_t logIndex);

MetaStatusCode InsertInode(const Inode& inode, int64_t logIndex);

Expand Down
22 changes: 13 additions & 9 deletions curvefs/src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ std::shared_ptr<StreamServer> MetaStoreImpl::GetStreamServer() {
return status; \
}

#define GET_TIME_FROM_REQUEST(TIME) \
uint64_t now = 0; \
uint32_t now_ns = 0; \
if (request->has_create()) { \
now = request->create().sec(); \
now_ns = request->create().nsec(); \
} \
TIME.set_sec(now); \
TIME.set_nsec(now_ns);

// dentry
MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest* request,
Expand All @@ -366,15 +375,8 @@ MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest* request,
ReadLockGuard readLockGuard(rwLock_);
std::shared_ptr<Partition> partition;
GET_PARTITION_OR_RETURN(partition);
uint64_t now = 0;
uint32_t now_ns = 0;
if (request->has_create()) {
now = request->create().sec();
now_ns = request->create().nsec();
}
Time tm;
tm.set_sec(now);
tm.set_nsec(now_ns);
GET_TIME_FROM_REQUEST(tm);
MetaStatusCode status =
partition->CreateDentry(request->dentry(), tm, logIndex);
response->set_statuscode(status);
Expand Down Expand Up @@ -428,7 +430,9 @@ MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest* request,
dentry.set_txid(txId);
dentry.set_type(request->type());

auto rc = partition->DeleteDentry(dentry, logIndex);
Time tm;
GET_TIME_FROM_REQUEST(tm);
auto rc = partition->DeleteDentry(dentry, tm, logIndex);
response->set_statuscode(rc);
return rc;
}
Expand Down
11 changes: 6 additions & 5 deletions curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, const Time& tm,
if (MetaStatusCode::OK == ret) {
if (dentry.has_type()) {
return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry, tm.sec(), tm.nsec(), true, logIndex);
dentry, tm, true, logIndex);
} else {
LOG(ERROR) << "CreateDentry does not have type, "
<< dentry.ShortDebugString();
Expand All @@ -128,7 +128,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, const Time& tm,
// NOTE: we enter here means that
// this log maybe is "half apply"
ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry, tm.sec(), tm.nsec(), true, logIndex);
dentry, tm, true, logIndex);
if (ret == MetaStatusCode::IDEMPOTENCE_OK) {
ret = MetaStatusCode::OK;
}
Expand All @@ -155,14 +155,15 @@ MetaStatusCode Partition::LoadDentry(const DentryVec& vec, bool merge,
return rc;
}

MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, int64_t logIndex) {
MetaStatusCode Partition::DeleteDentry(
const Dentry& dentry, const Time& tm, int64_t logIndex) {
PRECHECK(dentry.fsid(), dentry.parentinodeid());

MetaStatusCode ret = dentryManager_->DeleteDentry(dentry, logIndex);
if (MetaStatusCode::OK == ret) {
if (dentry.has_type()) {
return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry, 0, 0, false, logIndex);
dentry, tm, false, logIndex);
} else {
LOG(ERROR) << "DeleteDentry does not have type, "
<< dentry.ShortDebugString();
Expand All @@ -173,7 +174,7 @@ MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, int64_t logIndex) {
// NOTE: we enter here means that
// this log maybe is "half apply"
ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry, 0, 0, false, logIndex);
dentry, tm, false, logIndex);
}
if (ret == MetaStatusCode::IDEMPOTENCE_OK) {
ret = MetaStatusCode::OK;
Expand Down
11 changes: 6 additions & 5 deletions curvefs/src/metaserver/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class Partition {
Partition() = default;

// dentry
MetaStatusCode CreateDentry(const Dentry& dentry, const Time& tm,
int64_t logIndex);
MetaStatusCode CreateDentry(
const Dentry& dentry, const Time& tm, int64_t logIndex);

MetaStatusCode LoadDentry(const DentryVec& vec, bool merge,
int64_t logIndex);
MetaStatusCode LoadDentry(
const DentryVec& vec, bool merge, int64_t logIndex);

MetaStatusCode DeleteDentry(const Dentry& dentry, int64_t logIndex);
MetaStatusCode DeleteDentry(
const Dentry& dentry, const Time& tm, int64_t logIndex);

MetaStatusCode GetDentry(Dentry* dentry);

Expand Down
6 changes: 0 additions & 6 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3941,8 +3941,6 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) {
EXPECT_CALL(*inodeManager_, GetInode(_, _))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
SetArgReferee<1>(parentInodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
Expand All @@ -3952,12 +3950,8 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) {
EXPECT_CALL(*metaClient_, UpdateInodeAttr(_, _, _))
.WillRepeatedly(Return(MetaStatusCode::OK));

EXPECT_CALL(*inodeManager_, ShipToFlush(_)).Times(1);

CURVEFS_ERROR ret = client_->FuseOpUnlink(req, parent, name.c_str());
ASSERT_EQ(CURVEFS_ERROR::OK, ret);
Inode inode2 = inodeWrapper->GetInode();
ASSERT_EQ(nlink - 1, inode2.nlink());

auto p = parentInodeWrapper->GetInode();
ASSERT_EQ(3, p.nlink());
Expand Down
8 changes: 0 additions & 8 deletions curvefs/test/client/test_fuse_volume_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,6 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlink) {
EXPECT_CALL(*inodeManager_, GetInode(_, _))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
SetArgReferee<1>(parentInodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)));
EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _))
Expand Down Expand Up @@ -634,8 +632,6 @@ TEST_F(TestFuseVolumeClient, FuseOpRmDir) {
EXPECT_CALL(*inodeManager_, GetInode(_, _))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
SetArgReferee<1>(parentInodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)));
EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _))
Expand Down Expand Up @@ -701,13 +697,9 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlinkFailed) {
EXPECT_CALL(*inodeManager_, GetInode(_, _))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
SetArgReferee<1>(parentInodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(Return(CURVEFS_ERROR::INTERNAL))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(DoAll(
SetArgReferee<1>(parentInodeWrapper), Return(CURVEFS_ERROR::OK)))
.WillOnce(
DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK)));
EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _))
Expand Down
15 changes: 8 additions & 7 deletions curvefs/test/metaserver/partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,12 @@ TEST_F(PartitionTest, dentrynum) {
Time tm;
tm.set_sec(0);
tm.set_nsec(0);
ASSERT_EQ(partition1.CreateDentry(dentry, tm, logIndex_++),
MetaStatusCode::OK);
ASSERT_EQ(
partition1.CreateDentry(dentry, tm, logIndex_++), MetaStatusCode::OK);
ASSERT_EQ(partition1.GetDentryNum(), 1);

ASSERT_EQ(partition1.DeleteDentry(dentry, logIndex_++), MetaStatusCode::OK);
ASSERT_EQ(
partition1.DeleteDentry(dentry, tm, logIndex_++), MetaStatusCode::OK);
ASSERT_EQ(partition1.GetDentryNum(), 0);
}

Expand Down Expand Up @@ -331,10 +332,10 @@ TEST_F(PartitionTest, PARTITION_ID_MISSMATCH_ERROR) {
MetaStatusCode::PARTITION_ID_MISSMATCH);

// test DeleteDentry
ASSERT_EQ(partition1.DeleteDentry(dentry1, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);
ASSERT_EQ(partition1.DeleteDentry(dentry2, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);
ASSERT_EQ(partition1.DeleteDentry(dentry1, tm, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);
ASSERT_EQ(partition1.DeleteDentry(dentry2, tm, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);

// test GetDentry
ASSERT_EQ(partition1.GetDentry(&dentry1),
Expand Down