-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat:add big_key #3210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:add big_key #3210
Changes from 5 commits
ed4f523
5488d60
10b8a9a
23668f3
be1e4bd
fdc4e5d
33ef7e2
5d29308
71a65d6
fee8036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| set(WARNING_FLAGS "-W -Wextra -Wall -Wsign-compare \ | ||
| -Wno-unused-parameter -Wno-redundant-decls -Wwrite-strings \ | ||
| -Wpointer-arith -Wreorder -Wswitch -Wsign-promo \ | ||
| -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers") | ||
|
|
||
| set(CXXFLAGS "${WARNING_FLAGS} -std=c++17 -g") | ||
|
|
||
| set(SRC_DIR .) | ||
| aux_source_directory(${SRC_DIR} BASE_OBJS) | ||
|
|
||
| add_executable(bigkey_analyzer ${BASE_OBJS}) | ||
|
|
||
| target_include_directories(bigkey_analyzer | ||
| PRIVATE | ||
| ${PROJECT_SOURCE_DIR} | ||
| ${PROJECT_SOURCE_DIR}/src | ||
| ${PROJECT_SOURCE_DIR}/src/storage/include | ||
| ) | ||
|
|
||
| target_link_libraries(bigkey_analyzer | ||
| storage | ||
| pthread | ||
| ) | ||
|
|
||
| set_target_properties(bigkey_analyzer PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} | ||
| CMAKE_COMPILER_IS_GNUCXX TRUE | ||
| COMPILE_FLAGS ${CXXFLAGS} | ||
| ) | ||
|
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Replace deprecated Two issues:
🔎 Recommended fix+target_compile_options(bigkey_analyzer PRIVATE ${WARNING_FLAGS})
+target_compile_features(bigkey_analyzer PRIVATE cxx_std_17)
+
set_target_properties(bigkey_analyzer PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
- CMAKE_COMPILER_IS_GNUCXX TRUE
- COMPILE_FLAGS ${CXXFLAGS}
)Also remove or simplify the
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,120 @@ | ||||||||||||||||||||||||
| # Big Key Analyzer | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 大key分析工具,用于分析PikiwiDB实例中的大key情况。本工具适用于unstable分支新的存储结构,支持单实例和多DB实例(db/0, db/1, db/2...)。 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 功能特点 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - 支持分析各种数据类型(strings, hashes, lists, sets, zsets)的大key | ||||||||||||||||||||||||
| - 可以按大小过滤key | ||||||||||||||||||||||||
| - 可以限制输出结果数量(top N) | ||||||||||||||||||||||||
| - 支持按key前缀统计 | ||||||||||||||||||||||||
| - 输出结果包含key类型、大小和过期时间(TTL) | ||||||||||||||||||||||||
| - 可以将结果输出到文件 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 编译 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 在PikiwiDB根目录下执行: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| mkdir -p build | ||||||||||||||||||||||||
| cd build | ||||||||||||||||||||||||
| cmake .. | ||||||||||||||||||||||||
| make bigkey_analyzer | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 编译完成后,可执行文件会生成在build目录下。 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 使用方法 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| Usage: bigkey_analyzer [OPTIONS] <db_path> | ||||||||||||||||||||||||
| Options: | ||||||||||||||||||||||||
| --min-size=SIZE Only show keys larger than SIZE bytes | ||||||||||||||||||||||||
| --top=N Only show top N largest keys | ||||||||||||||||||||||||
| --prefix-stat Show statistics by key prefix | ||||||||||||||||||||||||
| --prefix-delimiter=C Character used to delimit prefix (default: ':') | ||||||||||||||||||||||||
| --type=TYPE Only analyze specific type (strings|hashes|lists|sets|zsets|all) | ||||||||||||||||||||||||
| --output=FILE Write output to file instead of stdout | ||||||||||||||||||||||||
| --help Display this help message | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
Comment on lines
+33
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add language identifier to fenced code block. The usage text block should specify a language identifier for proper syntax highlighting and better readability. 🔎 Proposed fix-```
+```text
Usage: bigkey_analyzer [OPTIONS] <db_path>
Options:📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.18.1)29-29: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 示例 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 1. 分析所有大key: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| # 单实例 | ||||||||||||||||||||||||
| ./bigkey_analyzer /path/to/pikiwidb/data | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # 多DB实例(db/0, db/1, db/2...) | ||||||||||||||||||||||||
| ./bigkey_analyzer /path/to/pikiwidb | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 2. 只分析大于1MB的key: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| ./bigkey_analyzer --min-size=1048576 /path/to/pikiwidb/data | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 3. 只显示前10个最大的key: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| ./bigkey_analyzer --top=10 /path/to/pikiwidb/data | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 4. 只分析hash类型的key: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| ./bigkey_analyzer --type=hashes /path/to/pikiwidb/data | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 5. 分析并按前缀统计: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| ./bigkey_analyzer --prefix-stat /path/to/pikiwidb/data | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 6. 输出结果到文件: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| ./bigkey_analyzer --output=result.txt /path/to/pikiwidb/data | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 输出格式 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 工具输出包括三部分: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 1. 大key列表 - 按大小降序排列 | ||||||||||||||||||||||||
| 2. 按前缀统计(如果使用--prefix-stat选项) | ||||||||||||||||||||||||
| 3. 总结统计信息 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 示例输出: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| ===== Big Key Analysis ===== | ||||||||||||||||||||||||
| Type Size Key TTL | ||||||||||||||||||||||||
| hash 1048576 user:profile:1001 -1 | ||||||||||||||||||||||||
| zset 524288 ranking:global 3600 | ||||||||||||||||||||||||
| string 262144 config:settings -1 | ||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ===== Key Prefix Statistics ===== | ||||||||||||||||||||||||
| Prefix Count Total Size Avg Size | ||||||||||||||||||||||||
| user 100 10485760 104857.6 | ||||||||||||||||||||||||
| ranking 50 2621440 52428.8 | ||||||||||||||||||||||||
| config 10 524288 52428.8 | ||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ===== Summary ===== | ||||||||||||||||||||||||
| Total keys analyzed: 160 | ||||||||||||||||||||||||
| Keys by type: | ||||||||||||||||||||||||
| hash: 50 keys, 25.0 MB total, 524288.0 bytes avg | ||||||||||||||||||||||||
| zset: 30 keys, 15.0 MB total, 524288.0 bytes avg | ||||||||||||||||||||||||
| string: 80 keys, 10.0 MB total, 131072.0 bytes avg | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
Comment on lines
+97
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add language identifier to fenced code block. The example output block should specify a language identifier for proper syntax highlighting and better readability. 🔎 Proposed fix-```
+```text
===== Big Key Analysis =====
Type Size Key TTL🧰 Tools🪛 markdownlint-cli2 (0.18.1)93-93: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## 注意事项 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - 工具只读取数据库,不会进行任何写操作 | ||||||||||||||||||||||||
| - 大key的大小包括key和value的总大小 | ||||||||||||||||||||||||
| - 已过期的key不会被包含在分析结果中 | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OpenAtomFoundation/pikiwidb
Length of output: 10408
Add explicit ${ROCKSDB_LIBRARY} link for consistency with other tools.
Although
storageprovides${ROCKSDB_LIBRARY}as a PUBLIC dependency, all similar tools in the project—includingtxt_to_pika,pika_to_txt,benchmark_client, andpika_port—explicitly link${ROCKSDB_LIBRARY}alongsidestorage. Update to:🤖 Prompt for AI Agents