@@ -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