diff --git a/src/overlaybd/lsmt/file.cpp b/src/overlaybd/lsmt/file.cpp index 12ec4e16..f76004d4 100644 --- a/src/overlaybd/lsmt/file.cpp +++ b/src/overlaybd/lsmt/file.cpp @@ -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); diff --git a/src/overlaybd/lsmt/test/lsmt-filetest.h b/src/overlaybd/lsmt/test/lsmt-filetest.h index 053c5f83..384b9b5b 100644 --- a/src/overlaybd/lsmt/test/lsmt-filetest.h +++ b/src/overlaybd/lsmt/test/lsmt-filetest.h @@ -408,6 +408,7 @@ class FileTest2 : public FileTest { data_name.clear(); idx_name.clear(); layer_name.clear(); + parent_uuid = ""; } }; @@ -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); }; diff --git a/src/overlaybd/lsmt/test/test.cpp b/src/overlaybd/lsmt/test/test.cpp index 6a730b2d..c69bfb35 100644 --- a/src/overlaybd/lsmt/test/test.cpp +++ b/src/overlaybd/lsmt/test/test.cpp @@ -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(); @@ -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) { @@ -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;