Skip to content

Commit

Permalink
Fix DBConfig used in builder (#177)
Browse files Browse the repository at this point in the history
* Fix DBConfig used in builder

* Fix unit test

* Fix for backward compatibility

---------

Co-authored-by: Zexi Liu <[email protected]>
  • Loading branch information
ZexiLiu and Zexi Liu authored Oct 9, 2024
1 parent 136ad3d commit 5473c1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/libjungle/jungle_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Builder {
*/
std::string path;

/**
* DBConfig for the DB instance to be created.
*/
DBConfig dbConfig;

/**
* Detailed table info.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/jungle_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ Status Builder::buildFromTableFiles(const BuildParams& params) {
Status s;

std::unique_ptr<FileOpsPosix> f_ops(new FileOpsPosix());
DBConfig db_config;

TableMgrOptions t_mgr_opt;
t_mgr_opt.path = params.path;
t_mgr_opt.fOps = f_ops.get();
t_mgr_opt.dbConfig = &db_config;
t_mgr_opt.dbConfig = &params.dbConfig;

MutableTableMgr t_mgr(nullptr);
t_mgr.setOpt(t_mgr_opt);
Expand Down Expand Up @@ -82,7 +81,7 @@ Status Builder::buildFromTableFiles(const BuildParams& params) {
}

// Create and add empty L0 tables.
for (size_t ii = 0; ii < db_config.numL0Partitions; ++ii) {
for (size_t ii = 0; ii < params.dbConfig.numL0Partitions; ++ii) {
TableFile* t_file = new TableFile(&t_mgr);
uint64_t table_number = ++max_table_num;
std::string t_filename =
Expand All @@ -103,7 +102,7 @@ Status Builder::buildFromTableFiles(const BuildParams& params) {
LogMgrOptions l_opt;
l_opt.path = params.path;
l_opt.fOps = f_ops.get();
l_opt.dbConfig = &db_config;
l_opt.dbConfig = &params.dbConfig;
l_opt.startSeqnum = max_seqnum + 1;
l_mgr.init(l_opt);
l_mgr.sync(false);
Expand All @@ -122,6 +121,7 @@ Status Builder::init(const std::string& path,
dbConfig = db_config;
fOps = new FileOpsPosix();
buildParams.path = path;
buildParams.dbConfig = dbConfig;

if (!fOps->exist(dstPath)) {
// Create the directory.
Expand Down
4 changes: 3 additions & 1 deletion tests/jungle/builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int build_from_table_files_test() {
// Build from table files.
jungle::builder::Builder::BuildParams params;
params.path = path;
params.dbConfig = d_conf;
for (size_t ii = 0; ii < 4; ++ii) {
jungle::builder::Builder::BuildParams::TableData td;
td.tableNumber = ii;
Expand Down Expand Up @@ -194,6 +195,8 @@ int build_an_empty_db_test() {

fdb_set_log_callback_ex_global(dummy_fdb_log_cb, nullptr);

jungle::DBConfig d_conf;

// Build from table files.
jungle::builder::Builder::BuildParams params;
params.path = path;
Expand All @@ -203,7 +206,6 @@ int build_an_empty_db_test() {
jungle::DB* db;
jungle::Status s;

jungle::DBConfig d_conf;
CHK_Z( jungle::DB::open(&db, path, d_conf) );

// Put a few key-value pairs.
Expand Down

0 comments on commit 5473c1b

Please sign in to comment.