Skip to content

为 TDengine 完善逻辑备份和恢复功能(基于 research/3.3.6-experimental 变基)#33395

Merged
zyyang90 merged 2 commits intotaosdata:research/3.3.6-experimentalfrom
ZhangZui123:backup/pitr-rebased-3.3.6-exp
Oct 29, 2025
Merged

为 TDengine 完善逻辑备份和恢复功能(基于 research/3.3.6-experimental 变基)#33395
zyyang90 merged 2 commits intotaosdata:research/3.3.6-experimentalfrom
ZhangZui123:backup/pitr-rebased-3.3.6-exp

Conversation

@ZhangZui123
Copy link
Copy Markdown

Description

本 PR 在不改变功能的前提下,将原工作变基到 taosdata/TDengine:research/3.3.6-experimental,在 plugins/incremental_bitmap 实现并验证以“逻辑快照 + 增量(WAL/脏块)”为核心的时间点恢复(PITR)链路,聚焦兼容性、高性能、可靠性与可扩展性的落地与可复现校验。原 PR 链接

兼容性

  • 通过备份协调器提供按 WAL 偏移与按时间范围的增量块查询与规模估算接口:backup_coordinator_get_dirty_blocks、backup_coordinator_get_dirty_blocks_by_time、backup_coordinator_estimate_backup_size(src/backup_coordinator.c / include/backup_coordinator.h)。
  • 事件拦截与位图联动:EVENT_BLOCK_CREATE/UPDATE/FLUSH/DELETE 触发位图状态更新(src/event_interceptor.c 调用 bitmap_engine_*),为“快照 + 增量”恢复提供脏块定位能力。
  • 提供真实环境用例与闭环比对:test/test_e2e_tdengine_real.c 调用同目录二进制 ./test_taosdump_comparison,将结果写入 /tmp/test_taosdump_comparison_inline.log 并计入总判定;test/test_taosdump_comparison.c 负责建数、调用 taosdump 导出与比对。

高性能

  • 位图核心引擎与压缩实现:src/bitmap_engine.c、src/roaring_bitmap.c,支持按 WAL/时间的双通道脏块获取与批量查询。
  • 单测覆盖:test/test_bitmap_engine_core.c、test/test_roaring_bitmap_specific.c 验证脏块查询与位图行为。

高可靠

端到端测试严格化

  • test/test_pitr_e2e.c 统一 PITR_DEFAULT_CONFIG,移除宽松判断;
  • 乱序/删除采用计数与一致性硬断言;
  • generate_detailed_test_report(total,passed,failed) 生成 /tmp/pitr_detailed_report.txt。

真实环境脚本校验:run_real_tests.sh

  • 每个测试输出至 logs/.log;
  • 对 test_taosdump_comparison 强制匹配成功关键词(含中英文);
  • 在 test_e2e_tdengine_real 后校验产物目录与报告文件存在且非零,并在 /tmp/pitr_detailed_report.txt 校验关键字段(Total/Passed/Success Rate)。

非真实环境脚本:run_tests.sh

  • 固定可执行测试集、避免“假绿”;
  • 可选 Valgrind 覆盖 test_bitmap_engine_core、test_backup_coordinator、test_skiplist、test_ring_buffer,输出至 valgrind_logs/*.log。

可扩展

  • 接口化设计:存储引擎抽象、事件拦截器、位图引擎与备份协调器分层实现(include/.h、src/.c),方便与上层备份工具对接。
  • CI/workflow:plugins/incremental_bitmap/.github/workflows/ci.yml 提供参数化开关、步骤化准备与超时设置;如运行受限,可用本地脚本复现闭环与产物校验。

复现入口

  • Mock/单元与集成:plugins/incremental_bitmap/run_tests.sh
  • 真实环境与闭环:plugins/incremental_bitmap/run_real_tests.sh

Checklist

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@ZhangZui123 ZhangZui123 requested a review from a team as a code owner October 28, 2025 09:23
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ZhangZui123, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过引入增量位图插件技术,显著增强TDengine的逻辑备份和恢复功能。它解决了现有TMQ增量备份方案中初始备份性能不佳的问题,并提供了一个高性能、高可靠、高兼容且可扩展的解决方案。通过精细的事件拦截、高效的位图引擎和全面的测试策略,确保了新功能在各种场景下的稳定性和效率。

Highlights

  • 功能变基与增量备份核心实现: 本PR将现有工作变基到research/3.3.6-experimental分支,并实现了以“逻辑快照 + 增量(WAL/脏块)”为核心的时间点恢复(PITR)链路,旨在提供高性能的逻辑备份和恢复功能。
  • 兼容性与性能提升: 通过备份协调器提供按WAL偏移与按时间范围的增量块查询接口,并利用事件拦截与位图联动机制,为增量恢复提供脏块定位能力。核心位图引擎与压缩实现(基于RoaringBitmap)支持双通道脏块获取与批量查询,显著提升性能。
  • 高可靠性与可扩展性: 引入了严格的端到端测试(PITR E2E)、真实环境脚本校验、Valgrind内存检查以及接口化分层设计,确保系统的高可靠性、可维护性与可扩展性。同时,还新增了taosX插件接口以支持更广泛的集成。
  • 全面的测试覆盖与CI/CD: 新增了详细的CI工作流,涵盖了构建、测试(包括模拟和真实环境)、静态分析、代码覆盖率、安全扫描、文档检查和性能基准测试,确保代码质量和功能稳定性。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次PR为TDengine引入了基于增量位图的逻辑备份和恢复功能,这是一个重要的功能增强。代码结构清晰,包含了实现、测试、CI工作流和详细的文档,整体工作非常全面。然而,在代码审查中发现了一些严重问题,包括多个严重等级为“critical”的安全漏洞(如缓冲区溢出)、可能导致死锁的并发问题、以及严重影响可移植性和可维护性的硬编码路径。CI配置也存在缺陷,可能会掩盖内存错误。建议在合并前优先解决这些严重问题,以确保代码的稳定性、安全性和质量。

Comment thread plugins/incremental_bitmap/quick_test.sh
Comment thread plugins/incremental_bitmap/src/tdengine_storage_engine.c
Comment thread plugins/incremental_bitmap/src/roaring_bitmap.c
Comment thread plugins/incremental_bitmap/setup_tdengine_test.sh
Comment thread plugins/incremental_bitmap/src/bitmap_engine.c
Comment thread plugins/incremental_bitmap/run_real_tests.sh
Comment thread plugins/incremental_bitmap/src/bitmap_engine.c
Comment thread plugins/incremental_bitmap/.github/workflows/ci.yml
Comment thread plugins/incremental_bitmap/CMakeLists.txt
@zyyang90 zyyang90 merged commit a29e1a1 into taosdata:research/3.3.6-experimental Oct 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants