Skip to content

Commit 65f005a

Browse files
committed
support lsmt seal and commit sealed
Signed-off-by: Haoqi Miao <miaohaoqi.mhq@alibaba-inc.com>
1 parent 35b60ad commit 65f005a

5 files changed

Lines changed: 37 additions & 10 deletions

File tree

src/bk_download.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sys/stat.h>
3030
#include <unistd.h>
3131
#include "switch_file.h"
32+
#include "image_file.h"
3233

3334
using namespace photon::fs;
3435

src/bk_download.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class ISwitchFile;
2424
namespace BKDL {
2525

2626
static std::string DOWNLOAD_TMP_NAME = ".download";
27-
static std::string COMMIT_FILE_NAME = "overlaybd.commit";
2827

2928
bool check_downloaded(const std::string &dir);
3029

src/image_file.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,18 @@ int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
258258
} else {
259259
// open downloaded blob or remote blob
260260
if (BKDL::check_downloaded(layer.dir())) {
261-
opened = layer.dir() + "/" + BKDL::COMMIT_FILE_NAME;
261+
opened = layer.dir() + "/" + COMMIT_FILE_NAME;
262262
file = __open_ro_file(opened);
263263
} else {
264-
opened = layer.digest();
265-
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
264+
auto sealed = layer.dir() + "/" + SEALED_FILE_NAME;
265+
if (::access(sealed.c_str(), 0) == 0) {
266+
// open sealed blob
267+
opened = sealed;
268+
file = __open_ro_file(opened);
269+
} else {
270+
opened = layer.digest();
271+
file = __open_ro_remote(layer.dir(), layer.digest(), layer.size(), index);
272+
}
266273
}
267274
}
268275

src/image_file.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include <photon/thread/thread11.h>
3737
#include "overlaybd/lsmt/file.h"
3838

39+
static std::string COMMIT_FILE_NAME = "overlaybd.commit";
40+
static std::string SEALED_FILE_NAME = "overlaybd.sealed";
41+
3942
class ImageFile : public photon::fs::ForwardFile {
4043
public:
4144
ImageFile(ImageConfigNS::ImageConfig &_conf, ImageService &is)

src/tools/overlaybd-commit.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int main(int argc, char **argv) {
5555
std::string data_file_path, index_file_path, commit_file_path, remote_mapping_file;
5656
bool compress_zfile = false;
5757
bool build_fastoci = false;
58-
bool tar = false, rm_old = false;
58+
bool tar = false, rm_old = false, seal = false, commit_sealed = false;
5959

6060
CLI::App app{"this is overlaybd-commit"};
6161
app.add_option("-m", commit_msg, "add some custom message if needed");
@@ -70,24 +70,41 @@ int main(int argc, char **argv) {
7070
"The size of a data block in KB. Must be a power of two between 4K~64K [4/8/16/32/64](default 4)");
7171
app.add_flag("--fastoci", build_fastoci, "commit using fastoci format")->default_val(false);
7272
app.add_option("data_file", data_file_path, "data file path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
73-
app.add_option("index_file", index_file_path, "index file path")->type_name("FILEPATH")->check(CLI::ExistingFile)->required();
74-
app.add_option("commit_file", commit_file_path, "commit file path")->type_name("FILEPATH")->required();
73+
app.add_option("index_file", index_file_path, "index file path")->type_name("FILEPATH");
74+
app.add_option("commit_file", commit_file_path, "commit file path")->type_name("FILEPATH");
75+
app.add_flag("--seal", seal, "seal only, data_file is output itself")->default_val(false);
76+
app.add_flag("--commit_sealed", commit_sealed, "commit sealed, index_file is output")->default_val(false);
7577
CLI11_PARSE(app, argc, argv);
7678

7779
set_log_output_level(1);
7880
photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_DEFAULT);
7981

8082
IFileSystem *lfs = new_localfs_adaptor();
81-
IFile* fdata = open_file(lfs, data_file_path.c_str(), O_RDONLY, 0);
82-
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);
83+
84+
IFile* fdata = open_file(lfs, data_file_path.c_str(), O_RDWR, 0);
8385
IFileRW* fin = nullptr;
8486
if (build_fastoci) {
85-
LOG_INFO("commit LSMTWarpFile with args: {index_file: `, fsmeta: `",
87+
LOG_INFO("commit LSMTWarpFile with args: {index_file: `, fsmeta: `}",
8688
index_file_path, data_file_path);
89+
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);
8790
fin = open_warpfile_rw(findex, fdata, nullptr, true);
91+
} if (commit_sealed) {
92+
fin = (IFileRW*)open_file_ro(fdata, true);
93+
commit_file_path = index_file_path; // the second param is for commit path
8894
} else {
95+
IFile* findex = open_file(lfs, index_file_path.c_str(), O_RDONLY, 0);
8996
fin = open_file_rw(fdata, findex, true);
9097
}
98+
99+
if (seal) {
100+
if (fin->close_seal() < 0) {
101+
fprintf(stderr, "failed to perform seal, %d: %s\n", errno, strerror(errno));
102+
return -1;
103+
}
104+
delete fin;
105+
return 0;
106+
}
107+
91108
if (rm_old) {
92109
lfs->unlink(commit_file_path.c_str());
93110
}

0 commit comments

Comments
 (0)