Skip to content

[Enhancement] Add checksum protection for shared-data tablet metadata and txn log#74924

Merged
luohaha merged 1 commit into
StarRocks:mainfrom
luohaha:feat-lake-meta-crc
Jun 22, 2026
Merged

[Enhancement] Add checksum protection for shared-data tablet metadata and txn log#74924
luohaha merged 1 commit into
StarRocks:mainfrom
luohaha:feat-lake-meta-crc

Conversation

@luohaha

@luohaha luohaha commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

In the shared-data architecture, lake tablet metadata and txn log files are
serialized as plain protobuf with no header and no checksum. Silent corruption of these
files (truncation, bit-rot, partial writes on object storage) cannot be detected on read,
and a corrupted tablet meta / txn log can lead to hard-to-diagnose failures.

The shared-nothing engine already protects its metadata with ProtobufFileWithHeader,
which carries an Adler-32 checksum, but that path hardcodes OLAP_FIX_HEADER_MAGIC_NUMBER
(== 0, a poor magic) and rejects anything else, so it cannot be reused as-is for lake.

What I'm doing:

Add an opt-in checksummed on-disk format for shared-data tablet metadata and txn logs,
with full backward/forward read compatibility.

  • Introduce LAKE_META_HEADER_MAGIC_NUMBER, chosen so its little-endian first on-disk
    byte is 0xFE. A serialized TabletMetadataPB / TxnLogPB starts with the field-1
    varint tag (0x08) and protobuf can never produce a leading 0xFE byte, so a reader
    can distinguish the new checksummed format from legacy headerless protobuf with
    effectively zero false-positive risk.
  • Parameterize ProtobufFileWithHeader with magic and allow_plain_protobuf_fallback
    (both defaulted), so existing shared-nothing callers are byte-for-byte unchanged. When
    fallback is enabled, load() parses legacy headerless protobuf when the magic is absent.
  • Add BE config lake_enable_protobuf_file_checksum (default false). It only controls the
    write format; readers always auto-detect and verify the checksum when present,
    regardless of the flag.
  • Route lake tablet meta, txn log / slog / vlog, and combined txn log through the new
    save/load helpers in TabletManager, and fix vacuum.cpp's own metadata reader to use
    the same auto-detecting load path.
  • For bundle tablet metadata, protect both layers: a per-tablet page checksum
    (map<int64,uint32> tablet_meta_page_checksum in BundleTabletMetadataPB, same key as
    tablet_meta_pages) plus a footer crc32 over the shared bundle header (schemas, mappings,
    page pointers, and the page-checksum map itself). When the flag is on the footer becomes
    [bundle_meta][crc32][size | high-bit flag]; readers detect the layout via the high bit of
    the size field (collision-free, since a legacy bundle size is always well below 2^63) and
    fall back to the legacy [bundle_meta][size] when it is absent.
  • Adapt meta_tool (print_lake_metadata / print_lake_txn_log /
    print_lake_combined_txn_log) to load via the header-aware path so it parses both formats;
    print_lake_bundle_metadata already goes through the updated parse_bundle_tablet_metadata.

Compatibility note: the read path is always backward compatible (a new BE reads legacy
headerless files via fallback; the checksummed format is auto-detected). The flag defaults to
false to stay safe during rolling upgrades and downgrades: while versions are mixed, an older
BE/CN uses the legacy reader and cannot parse newly-written checksummed files. Enable it only
after the whole cluster has been upgraded to a version that understands the format.

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5

@github-actions

Copy link
Copy Markdown
Contributor

No new undocumented parameters detected by the param-drift check.

@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@luohaha luohaha force-pushed the feat-lake-meta-crc branch from 7c73cad to 8a87c13 Compare June 17, 2026 03:09
@github-actions github-actions Bot requested review from meegoo and xiangguangyxg June 17, 2026 03:10
@luohaha luohaha force-pushed the feat-lake-meta-crc branch from 8a87c13 to e013a6c Compare June 17, 2026 03:12
@github-actions github-actions Bot added the documentation Documentation changes label Jun 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c73cad15a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread be/src/common/config.h Outdated
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

🌎 Translation Required?

All translation files are up to date.
Great job! No translation actions are required for this PR.

🕒 Last updated: Sat, 20 Jun 2026 08:26:18 GMT

… and txn log

Lake tablet metadata and txn logs were stored as plain protobuf with no
checksum, so silent corruption could not be detected on read.

- Add an opt-in checksummed format gated by BE config
  lake_enable_protobuf_file_checksum (default false; enable only after the
  whole cluster understands the format, to stay safe across rolling
  upgrade/downgrade). Readers always auto-detect and verify the checksum when
  present, regardless of the flag.
- Single files (tablet meta, txn log/slog/vlog, combined txn log) use
  ProtobufFileWithHeader with a new LAKE_META_HEADER_MAGIC_NUMBER whose first
  on-disk byte is 0xFE, which no serialized protobuf can start with (wire type
  6), so legacy headerless files are distinguished with zero false positives.
- Bundle tablet metadata: per-tablet page checksum plus a footer crc32 over the
  shared header; the checksummed footer is marked by the high bit of the
  trailing size field (collision-free, since a legacy bundle size is well below
  2^63), falling back to the legacy [bundle_meta][size] layout otherwise.
- Route TabletManager and vacuum reads/writes through the new helpers, and adapt
  meta_tool (print_lake_metadata / print_lake_txn_log /
  print_lake_combined_txn_log) to parse both formats.
- Add BE UTs for the single-file and bundle formats, legacy fallback, and
  corruption detection; update en/zh/ja BE config docs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: luohaha <18810541851@163.com>
@luohaha luohaha force-pushed the feat-lake-meta-crc branch from 5e173b5 to 15bd9d4 Compare June 20, 2026 08:18
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

if (data.size() < header.protobuf_length) {
return Status::Corruption(fmt::format("mismatched message size of protobuf data. real={} expect={}",
data.size(), (int64_t)header.protobuf_length));
}

P2 Badge Reject trailing bytes in checksummed protobuf files

When lake_enable_protobuf_file_checksum is enabled, lake metadata/txn-log reads go through this buffer loader with legacy fallback enabled. A file containing a valid checksummed header/body plus extra trailing bytes now passes this < size check, so those bytes are neither covered by the Adler-32 nor rejected; the non-fallback streaming path previously detects the same condition by reading protobuf_length + 1 and failing on an oversized file. This masks append/trailing-byte corruption in the new checksummed format, so the reader should require the remaining size or header.file_length to match exactly before parsing.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 98 / 114 (85.96%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/tools/meta_tool.cpp 0 15 00.00% [1887, 1890, 1892, 1893, 1894, 1975, 1978, 1980, 1981, 1982, 1995, 1998, 2000, 2001, 2002]
🔵 be/src/storage/protobuf_file.cpp 28 29 96.55% [145]
🔵 be/src/storage/tablet_meta.cpp 1 1 100.00% []
🔵 be/src/storage/lake/replication_txn_manager.cpp 1 1 100.00% []
🔵 be/src/storage/lake/vacuum.cpp 2 2 100.00% []
🔵 be/src/storage/lake/tablet_manager.cpp 59 59 100.00% []
🔵 be/src/storage/protobuf_file.h 7 7 100.00% []

@luohaha luohaha enabled auto-merge (squash) June 22, 2026 02:19
@luohaha luohaha merged commit 77a3cd6 into StarRocks:main Jun 22, 2026
70 of 71 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.1

@github-actions github-actions Bot removed the 4.1 label Jun 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.0

@github-actions github-actions Bot removed the 4.0 label Jun 22, 2026
@mergify

mergify Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.1

✅ Backports have been created

Details

Cherry-pick of 77a3cd6 has failed:

On branch mergify/bp/branch-4.1/pr-74924
Your branch is up to date with 'origin/branch-4.1'.

You are currently cherry-picking commit 77a3cd65e5.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   be/src/common/config.h
	modified:   be/src/common/config_fwd_headers_manifest.json
	modified:   be/src/storage/lake/replication_txn_manager.cpp
	modified:   be/src/storage/lake/vacuum.cpp
	modified:   be/src/storage/olap_define.h
	modified:   be/src/storage/protobuf_file.cpp
	modified:   be/src/storage/tablet_meta.cpp
	modified:   be/test/storage/lake/partial_update_test.cpp
	modified:   docs/en/administration/management/BE_parameters/shared_lake_other.md
	modified:   docs/ja/administration/management/BE_parameters/shared_lake_other.md
	modified:   docs/zh/administration/management/BE_parameters/shared_lake_other.md
	modified:   gensrc/proto/lake_types.proto

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   be/src/common/config_lake_fwd.h
	both modified:   be/src/storage/lake/tablet_manager.cpp
	both modified:   be/src/storage/protobuf_file.h
	both modified:   be/src/tools/meta_tool.cpp
	both modified:   be/test/storage/lake/tablet_manager_test.cpp
	both modified:   be/test/storage/protobuf_file_test.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify

mergify Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.0

✅ Backports have been created

Details

Cherry-pick of 77a3cd6 has failed:

On branch mergify/bp/branch-4.0/pr-74924
Your branch is up to date with 'origin/branch-4.0'.

You are currently cherry-picking commit 77a3cd65e5.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   be/src/common/config.h
	modified:   be/src/storage/lake/vacuum.cpp
	modified:   be/src/storage/olap_define.h
	modified:   be/src/storage/protobuf_file.cpp
	modified:   be/src/storage/tablet_meta.cpp
	modified:   be/test/storage/lake/partial_update_test.cpp
	modified:   docs/en/administration/management/BE_parameters/shared_lake_other.md
	modified:   docs/ja/administration/management/BE_parameters/shared_lake_other.md
	modified:   docs/zh/administration/management/BE_parameters/shared_lake_other.md
	modified:   gensrc/proto/lake_types.proto

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   be/src/common/config_fwd_headers_manifest.json
	deleted by us:   be/src/common/config_lake_fwd.h
	both modified:   be/src/storage/lake/replication_txn_manager.cpp
	both modified:   be/src/storage/lake/tablet_manager.cpp
	both modified:   be/src/storage/protobuf_file.h
	both modified:   be/src/tools/meta_tool.cpp
	both modified:   be/test/storage/lake/tablet_manager_test.cpp
	both modified:   be/test/storage/protobuf_file_test.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

luohaha added a commit that referenced this pull request Jun 22, 2026
… and txn log (#74924)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 77a3cd6)
Signed-off-by: luohaha <18810541851@163.com>
luohaha added a commit that referenced this pull request Jun 22, 2026
… and txn log (#74924)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 77a3cd6)
Signed-off-by: luohaha <18810541851@163.com>
wanpengfei-git pushed a commit that referenced this pull request Jun 22, 2026
… and txn log (backport #74924) (#75102)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Yixin Luo <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
huailiu1122 pushed a commit that referenced this pull request Jun 23, 2026
… and txn log (#74924)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 77a3cd6)
Signed-off-by: luohaha <18810541851@163.com>
luohaha added a commit that referenced this pull request Jun 23, 2026
… and txn log (#74924)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 77a3cd6)
Signed-off-by: luohaha <18810541851@163.com>
wanpengfei-git pushed a commit that referenced this pull request Jun 24, 2026
… and txn log (backport #74924) (#75103)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
OliLay pushed a commit to OliLay/starrocks that referenced this pull request Jun 30, 2026
… and txn log (StarRocks#74924)

Signed-off-by: luohaha <18810541851@163.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Oliver Layer <o.layer@celonis.com>
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.

8 participants