Skip to content

Commit 5d29308

Browse files
committed
feat:add big_key
1 parent 33ef7e2 commit 5d29308

1 file changed

Lines changed: 65 additions & 20 deletions

File tree

tools/bigkey_analyzer/bigkey_analyzer.cc

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -723,29 +723,74 @@ int main(int argc, char *argv[]){
723723
db_paths.push_back(std::make_tuple(test_path, "", ""));
724724
std::cout << "Detected single database instance" << std::endl;
725725
} else {
726-
// 尝试检测dbN/M/格式 (如 db0/1, db0/2, db1/0 等)
727-
bool found_dbn_format = false;
728-
for (int db_index = 0; db_index < 1000; db_index++) {
729-
std::string db_name = "db" + std::to_string(db_index);
730-
std::string db_dir = config.db_path + "/" + db_name;
726+
// 处理几种常见的情况:
727+
728+
// 1. 如果输入路径本身是dbN格式,直接检测其子目录(无需额外的dbN前缀)
729+
std::string db_name_input = "";
730+
bool is_db_dir = false;
731+
std::string db_dir = config.db_path;
732+
733+
// 检查输入路径的末尾目录名是否匹配dbN模式
734+
size_t last_slash = config.db_path.find_last_of("/\\");
735+
if (last_slash != std::string::npos) {
736+
std::string dir_name = config.db_path.substr(last_slash + 1);
737+
if (dir_name.size() > 2 && dir_name.substr(0, 2) == "db" &&
738+
std::all_of(dir_name.begin() + 2, dir_name.end(), ::isdigit)) {
739+
db_name_input = dir_name;
740+
is_db_dir = true;
741+
}
742+
}
743+
744+
// 如果是dbN格式目录,直接检查其下的子目录
745+
if (is_db_dir) {
746+
// 检查这个db下的所有分区子目录
747+
bool found_partitions = false;
748+
for (int partition = 0; partition < 1000; partition++) {
749+
std::string partition_path = db_dir + "/" + std::to_string(partition);
750+
if (DirectoryExists(partition_path) && DirectoryExists(partition_path + "/CURRENT")) {
751+
db_paths.push_back(std::make_tuple(partition_path, db_name_input, std::to_string(partition)));
752+
found_partitions = true;
753+
} else if (partition > 0 && !DirectoryExists(partition_path) && found_partitions) {
754+
// 当前partition不存在且已找到至少一个partition,认为已到达该db的末尾
755+
break;
756+
}
757+
}
731758

732-
if (DirectoryExists(db_dir)) {
733-
// 检查这个db下的所有分区子目录
734-
bool found_partitions = false;
735-
for (int partition = 0; partition < 1000; partition++) {
736-
std::string partition_path = db_dir + "/" + std::to_string(partition);
737-
if (DirectoryExists(partition_path) && DirectoryExists(partition_path + "/CURRENT")) {
738-
db_paths.push_back(std::make_tuple(partition_path, db_name, std::to_string(partition)));
739-
found_partitions = true;
740-
found_dbn_format = true;
741-
} else if (partition > 0 && !DirectoryExists(partition_path) && found_partitions) {
742-
// 当前partition不存在且已找到至少一个partition,认为已到达该db的末尾
743-
break;
759+
// 如果在dbN目录下找到了有效的子目录,就不需要继续搜索其他格式了
760+
if (!db_paths.empty()) {
761+
std::cout << "Detected " << db_paths.size() << " database partitions in " << db_name_input << std::endl;
762+
}
763+
}
764+
765+
// 2. 如果上面的检测未能找到数据库,尝试标准的dbN/M格式
766+
if (db_paths.empty()) {
767+
bool found_dbn_format = false;
768+
for (int db_index = 0; db_index < 1000; db_index++) {
769+
std::string db_name = "db" + std::to_string(db_index);
770+
std::string db_dir = config.db_path + "/" + db_name;
771+
772+
if (DirectoryExists(db_dir)) {
773+
// 检查这个db下的所有分区子目录
774+
bool found_partitions = false;
775+
for (int partition = 0; partition < 1000; partition++) {
776+
std::string partition_path = db_dir + "/" + std::to_string(partition);
777+
if (DirectoryExists(partition_path) && DirectoryExists(partition_path + "/CURRENT")) {
778+
db_paths.push_back(std::make_tuple(partition_path, db_name, std::to_string(partition)));
779+
found_partitions = true;
780+
found_dbn_format = true;
781+
} else if (partition > 0 && !DirectoryExists(partition_path) && found_partitions) {
782+
// 当前partition不存在且已找到至少一个partition,认为已到达该db的末尾
783+
break;
784+
}
744785
}
786+
} else if (db_index > 0 && found_dbn_format) {
787+
// 当前db不存在且已找到至少一个db,认为已到达末尾
788+
break;
745789
}
746-
} else if (db_index > 0 && found_dbn_format) {
747-
// 当前db不存在且已找到至少一个db,认为已到达末尾
748-
break;
790+
}
791+
792+
if (found_dbn_format) {
793+
std::cout << "Detected " << db_paths.size() << " database partitions in dbN/M format" << std::endl;
749794
}
750795
}
751796

0 commit comments

Comments
 (0)