Skip to content

Commit

Permalink
curvefs/client: fix s3 object will not be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhongsong authored and Wine93 committed Jun 30, 2023
1 parent 057cac9 commit 6113dbe
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
16 changes: 15 additions & 1 deletion curvefs/src/metaserver/trash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ MetaStatusCode TrashImpl::DeleteInodeAndData(const TrashItem &item) {
clientAdaptorOption.objectPrefix = s3Info.objectprefix();
s3Adaptor_->Reinit(clientAdaptorOption, s3Info.ak(), s3Info.sk(),
s3Info.endpoint(), s3Info.bucketname());
ret = inodeStorage_->PaddingInodeS3ChunkInfo(item.fsId,
item.inodeId, inode.mutable_s3chunkinfomap());
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "GetInode chunklist fail, fsId = " << item.fsId
<< ", inodeId = " << item.inodeId
<< ", retCode = " << MetaStatusCode_Name(ret);
return ret;
}
if (inode.s3chunkinfomap().empty()) {
LOG(WARNING) << "GetInode chunklist empty, fsId = " << item.fsId
<< ", inodeId = " << item.inodeId;
return MetaStatusCode::NOT_FOUND;
}
VLOG(9) << "DeleteInodeAndData, inode: "
<< inode.ShortDebugString();
int retVal = s3Adaptor_->Delete(inode);
if (retVal != 0) {
LOG(ERROR) << "S3ClientAdaptor delete s3 data failed"
Expand All @@ -216,7 +231,6 @@ MetaStatusCode TrashImpl::DeleteInodeAndData(const TrashItem &item) {
return MetaStatusCode::S3_DELETE_ERR;
}
}

ret = inodeStorage_->Delete(Key4Inode(item.fsId, item.inodeId));
if (ret != MetaStatusCode::OK && ret != MetaStatusCode::NOT_FOUND) {
LOG(ERROR) << "Delete Inode fail, fsId = " << item.fsId
Expand Down
1 change: 0 additions & 1 deletion curvefs/test/metaserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ cc_test(
"mock_metaserver_s3.h",
"metaserver_s3_adaptor_test.h",
"metaserver_s3_adaptor_test.cpp",
"mock_metaserver_s3_adaptor.h",
"metaserver_s3_test.cpp",
"mock_s3compact_inode.h",
"s3compact_test.cpp",
Expand Down
63 changes: 55 additions & 8 deletions curvefs/test/metaserver/trash_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "curvefs/test/metaserver/storage/utils.h"
#include "src/fs/ext4_filesystem_impl.h"
#include "curvefs/test/client/rpcclient/mock_mds_client.h"
#include "curvefs/test/metaserver/mock_metaserver_s3_adaptor.h"

using ::testing::AtLeast;
using ::testing::StrEq;
Expand Down Expand Up @@ -105,7 +106,29 @@ class TestTrash : public ::testing::Test {
inode.set_gid(0);
inode.set_mode(0);
inode.set_nlink(0);
inode.set_type(FsFileType::TYPE_FILE);
inode.set_type(FsFileType::TYPE_S3);
return inode;
}

Inode GenInodeHasChunks(uint32_t fsId, uint64_t inodeId) {
Inode inode;
inode.set_fsid(fsId);
inode.set_inodeid(inodeId);
inode.set_length(4096);
inode.set_ctime(0);
inode.set_ctime_ns(0);
inode.set_mtime(0);
inode.set_mtime_ns(0);
inode.set_atime(0);
inode.set_atime_ns(0);
inode.set_uid(0);
inode.set_gid(0);
inode.set_mode(0);
inode.set_nlink(0);
inode.set_type(FsFileType::TYPE_S3);

S3ChunkInfoList s3ChunkInfoList;
inode.mutable_s3chunkinfomap()->insert({0, s3ChunkInfoList});
return inode;
}

Expand All @@ -121,18 +144,17 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
option.scanPeriodSec = 1;
option.expiredAfterSec = 1;
option.mdsClient = std::make_shared<MockMdsClient>();

option.s3Adaptor = std::make_shared<MockS3ClientAdaptor>();
trashManager_->Init(option);
trashManager_->Run();

auto trash1 = std::make_shared<TrashImpl>(inodeStorage_);
auto trash2 = std::make_shared<TrashImpl>(inodeStorage_);
trashManager_->Add(1, trash1);
trashManager_->Add(2, trash2);

inodeStorage_->Insert(GenInode(1, 1));
inodeStorage_->Insert(GenInode(1, 2));
inodeStorage_->Insert(GenInode(2, 1));
inodeStorage_->Insert(GenInodeHasChunks(1, 1));
inodeStorage_->Insert(GenInodeHasChunks(1, 2));
inodeStorage_->Insert(GenInodeHasChunks(2, 1));

ASSERT_EQ(inodeStorage_->Size(), 3);

Expand All @@ -141,17 +163,42 @@ TEST_F(TestTrash, testAdd3ItemAndDelete) {
trash2->Add(2, 1, 0);

std::this_thread::sleep_for(std::chrono::seconds(5));

std::list<TrashItem> list;

trashManager_->ListItems(&list);

ASSERT_EQ(0, list.size());

ASSERT_EQ(inodeStorage_->Size(), 0);

trashManager_->Fini();
}

TEST_F(TestTrash, testAdd3ItemAndNoDelete) {
TrashOption option;
option.scanPeriodSec = 1;
option.expiredAfterSec = 1;
option.mdsClient = std::make_shared<MockMdsClient>();
option.s3Adaptor = std::make_shared<MockS3ClientAdaptor>();
trashManager_->Init(option);
trashManager_->Run();

auto trash1 = std::make_shared<TrashImpl>(inodeStorage_);
trashManager_->Add(1, trash1);

inodeStorage_->Insert(GenInode(1, 1));
inodeStorage_->Insert(GenInode(1, 2));
inodeStorage_->Insert(GenInode(2, 1));
ASSERT_EQ(inodeStorage_->Size(), 3);
trash1->Add(1, 1, 0);
trash1->Add(1, 2, 0);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::list<TrashItem> list;

trashManager_->ListItems(&list);
ASSERT_EQ(0, list.size());
ASSERT_EQ(inodeStorage_->Size(), 3);
trashManager_->Fini();
}

} // namespace metaserver
} // namespace curvefs

0 comments on commit 6113dbe

Please sign in to comment.