Skip to content

Commit e6c9d70

Browse files
[feat] Implement multi-server database opening logic
1 parent 2d0268b commit e6c9d70

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/fdb5/parallax/parallax_handle.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
std::unordered_map<std::string, par_handle> par_handles;
44

5+
int current_index = 0;
6+
57
par_handle par_get_db(const std::string &db_name)
68
{
7-
// std::cout << "File: " << __FILE__ << ", Line: " << __LINE__ << ", Function: " << __func__ << std::endl;
8-
99
// Check if the database is already opened
1010
auto it = par_handles.find(db_name);
1111
if (it != par_handles.end()) {
1212
return it->second; // Return the existing handle
1313
}
1414

1515
// Database is not opened yet, proceed to open it
16-
const char *volume_name = getenv(PARALLAX_VOLUME_ENV_VAR);
16+
17+
std::string volume_path = "/tmp/root/parallax/default" + std::to_string(current_index);
18+
const char *volume_name = volume_path.c_str();
1719

1820
par_db_options db_options = { .volume_name = (char *)volume_name,
1921
.db_name = db_name.c_str(),
@@ -43,8 +45,12 @@ par_handle par_get_db(const std::string &db_name)
4345

4446
void par_init_db_handles()
4547
{
48+
int num_of_servers = par_get_num_of_servers();
4649
for (int i = 0; i < PARALLAX_DB_COUNT; ++i) {
47-
std::string db_name = PARALLAX_GLOBAL_DB + std::to_string(i + 1);
48-
par_get_db(db_name);
50+
current_index = i;
51+
for (int j = 0; j < num_of_servers; j++) {
52+
std::string db_name = PARALLAX_GLOBAL_DB + std::to_string(i * num_of_servers + j);
53+
par_get_db(db_name);
54+
}
4955
}
5056
}

0 commit comments

Comments
 (0)