Skip to content

Commit

Permalink
Merge pull request #269 from WaberZhuang/main
Browse files Browse the repository at this point in the history
[bugfix] turboOCI commit with uuid
  • Loading branch information
BigVan authored Sep 27, 2023
2 parents 2f60bdc + 8e4726c commit 970dbb3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/overlaybd/lsmt/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,11 @@ class LSMTWarpFile : public LSMTFile {
CompactOptions opts(&m_files, mapping.get(), m_index->size(), m_vsize, &args);
LayerInfo info;
info.virtual_size = m_vsize;
info.uuid.clear();
if (UUID::String::is_valid((args.uuid).c_str())) {
LOG_INFO("set UUID: `", args.uuid.data);
info.uuid.parse(args.uuid);
}
if (UUID::String::is_valid((args.parent_uuid).c_str())) {
LOG_INFO("set parent UUID: `", args.parent_uuid.data);
info.parent_uuid.parse(args.parent_uuid);
Expand Down
5 changes: 3 additions & 2 deletions src/overlaybd/lsmt/test/lsmt-filetest.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ class FileTest2 : public FileTest {
data_name.clear();
idx_name.clear();
layer_name.clear();
parent_uuid = "";
}
};

Expand Down Expand Up @@ -571,6 +572,6 @@ class WarpFileTest : public FileTest3 {
public:
void randwrite_warpfile(IFile *file, size_t nwrites);
IFileRW *create_warpfile_rw(int io_engine = 0);
IFileRO *create_commit_warpfile(int io_engine = 0);
IFileRO *create_commit_warpfile(IFileRW* warpfile);
IFileRO *create_commit_warpfile(int io_engine = 0, bool keepUUID = false);
IFileRO *create_commit_warpfile(IFileRW* warpfile, bool keepUUID = false);
};
42 changes: 39 additions & 3 deletions src/overlaybd/lsmt/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,19 @@ IFileRW *WarpFileTest::create_warpfile_rw(int io_engine) {
return file;
}

IFileRO *WarpFileTest::create_commit_warpfile(IFileRW* warpfile) {
IFileRO *WarpFileTest::create_commit_warpfile(IFileRW* warpfile, bool keepUUID) {
LOG_INFO("commit warpfile as `", layer_name.back().c_str());
auto fcommit = lfs->open(layer_name.back().c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
UUID uu;
uu.parse(parent_uuid.c_str(), parent_uuid.size());
CommitArgs c(fcommit);
c.parent_uuid = uu;

// commit will clear layer's uuid if CommitArgs.uuid is not specify
if (keepUUID) {
warpfile->get_uuid(uu);
c.uuid = uu;
}
((IFileRW *)warpfile)->commit(c);
delete warpfile;
fcommit->close();
Expand All @@ -802,10 +808,10 @@ IFileRO *WarpFileTest::create_commit_warpfile(IFileRW* warpfile) {
return ret;
}

IFileRO *WarpFileTest::create_commit_warpfile(int io_engine) {
IFileRO *WarpFileTest::create_commit_warpfile(int io_engine, bool keepUUID) {
auto warpfile = create_warpfile_rw(io_engine);
randwrite_warpfile(warpfile, FLAGS_nwrites);
return create_commit_warpfile(warpfile);
return create_commit_warpfile(warpfile, keepUUID);
}

TEST_F(WarpFileTest, randwrite) {
Expand Down Expand Up @@ -920,6 +926,36 @@ TEST_F(WarpFileTest, stack_files) {
fcheck = nullptr;
}

TEST_F(WarpFileTest, commit_without_uuid) {
CleanUp();
UUID uu;
auto frw = create_warpfile_rw(ut_io_engine);
frw->get_uuid(uu);
LOG_INFO("uuid before commit is `", uu);
EXPECT_FALSE(uu.is_null());

auto fcommit = create_commit_warpfile(frw);
fcommit->get_uuid(uu);
LOG_INFO("uuid after commit is `", uu);
EXPECT_TRUE(uu.is_null());
}

TEST_F(WarpFileTest, commit_with_uuid) {
CleanUp();
UUID uu;
auto frw = create_warpfile_rw(ut_io_engine);
frw->get_uuid(uu);
LOG_INFO("uuid before commit is `", uu);
EXPECT_FALSE(uu.is_null());

UUID uu_commit;
auto fcommit = create_commit_warpfile(frw, true);
fcommit->get_uuid(uu_commit);
LOG_INFO("uuid after commit is `", uu);
EXPECT_FALSE(uu_commit.is_null());
EXPECT_EQ(uu, uu_commit);
}

int main(int argc, char **argv) {

auto seed = 154574045;
Expand Down

0 comments on commit 970dbb3

Please sign in to comment.