Skip to content

storage: compare parsed timestamps for recovered chunk ordering - #12890

Open
dpavlov2024 wants to merge 2 commits into
fluent:masterfrom
dpavlov2024:recovered-chunk-ordering
Open

dpavlov2024 wants to merge 2 commits into
fluent:masterfrom
dpavlov2024:recovered-chunk-ordering

Conversation

@dpavlov2024

@dpavlov2024 dpavlov2024 commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

Fix sort_chunk_cmp() so recovered chunks are actually ordered by timestamp.

  • sort_chunk_cmp() marked a successful parse with -1, so if (ra != 0 || rb != 0) was true for two valid names and always fell through to strcmp(); the timestamp comparison was dead code.
  • Valid names now compare by second/nanosecond, invalid names sort after valid ones, and equal timestamps fall back to strcmp() for a deterministic order.
  • parse_stamp() now requires the whole filename to match, so legacy-1.0junk.flb is rejected as a timestamp.
  • New internal test: tests/internal/storage_sort.c (4 cases: numeric nsec, slot names, valid-vs-invalid/trailing junk, equal timestamps).

This is deliberately independent of the file-slot pool work. It does change recovered-chunk ordering for stock chunks (numeric timestamp instead of lexical name order), but that is the comparator's documented intent. For pooled chunks the ordering key is last-write mtime, while fallback chunk names carry creation time, so mixed pooled/fallback ordering is best-effort.

Base: Fluent Bit master at 984519cb.

Testing

These results are from earlier validation of the same patch. Patch application and commit prefixes were verified on the current base.

  • flb-it-storage_sort: 4/4.
  • Full Fluent Bit build (Debug, FLB_ALL=Off) with the test target: rc 0.

Notes

The timestamp branch was previously unreachable for valid pairs. The pool's slot-NNNNNN-<ts>.flb names benefit, but stock pid-<sec>.<nsec>.flb names are fixed too (variable-width nsec and mixed PIDs).

Summary by CodeRabbit

  • Bug Fixes
    • Storage chunks now sort consistently by timestamp, with deterministic ordering for matching timestamps and invalid names.
    • Names with trailing characters after the expected timestamp suffix are no longer treated as valid timestamped names.

Signed-off-by: Dmitri Pavlov <dpavlov@perforce.com>
Signed-off-by: Dmitri Pavlov <dpavlov@perforce.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T14:19:40.506373Z 0451c38 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The storage chunk comparator is now public. It accepts only names with a complete .flb timestamp suffix, orders valid names by timestamp, and uses lexical ordering for invalid names and timestamp ties. Internal tests cover the comparator behavior.

Changes: Storage chunk sorting

Layer / File(s) Summary
Comparator behavior and validation
include/fluent-bit/flb_storage.h, src/flb_storage.c, tests/internal/CMakeLists.txt, tests/internal/storage_sort.c
The public flb_storage_chunk_cmp comparator validates timestamp suffixes, orders valid names by seconds and nanoseconds, and resolves invalid names and timestamp ties lexically. flb_storage_create uses the comparator. Internal tests cover nanosecond ordering, pooled names, invalid names, and equal timestamps.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • fluent/fluent-bit#12572: Adds pooled chunk files and recovery behavior that uses the same recovered-chunk filename and ordering contract.
Merge Risk: Minimal · up to 0451c

This fixes the order in which recovered storage chunks are processed, so they follow timestamp order instead of lexical filename order. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "storage: compare parsed timestamps for recovered chunk ordering" matches the main change. The PR changes the chunk comparator (now flb_storage_chunk_cmp) so recovered chunks sort by parsed …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "storage: compare parsed timestamps for recovered chunk ordering" matches the main change. The PR changes the chunk comparator (now flb_storage_chunk_cmp) so recovered chunks sort by parsed seconds and nanoseconds instead of lexical filename order. It also tightens parse_stamp to reject trailing characters, and adds tests. The title does not mention the trailing-junk rejection or the tests, but the PR does not need to cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3238d3f3-46f6-44f0-b163-abe6cecab8c5
Commits

Reviewing files that changed from the base of the PR and between 984519c and 0451c38.

Files selected for processing: 4

  • include/fluent-bit/flb_storage.h
  • src/flb_storage.c
  • tests/internal/CMakeLists.txt
  • tests/internal/storage_sort.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
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.

1 participant