Skip to content

fix:ttl#3244

Open
chejinge wants to merge 1 commit intoOpenAtomFoundation:unstablefrom
chejinge:4.0_ttl
Open

fix:ttl#3244
chejinge wants to merge 1 commit intoOpenAtomFoundation:unstablefrom
chejinge:4.0_ttl

Conversation

@chejinge
Copy link
Copy Markdown
Collaborator

@chejinge chejinge commented Apr 17, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved timestamp parsing logic to explicitly detect whether timestamps are stored in milliseconds or seconds, replacing previous indirect comparison methods. This change enhances accuracy of time-based storage operations and ensures consistent timestamp handling.

@github-actions github-actions Bot added the ☢️ Bug Something isn't working label Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

The changes update timestamp parsing logic in two storage format headers. Instead of equality-based detection, the code now explicitly checks a high-bit flag (bit 63) to determine whether timestamps are stored in milliseconds or seconds before applying conversion.

Changes

Cohort / File(s) Summary
Timestamp parsing logic corrections
src/storage/src/base_meta_value_format.h, src/storage/src/strings_value_format.h
Updated timestamp decoding in both ParsedBaseMetaValue and ParsedStringsValue constructors to replace implicit equality-based detection with explicit high-bit checking ((ctime & (1ULL << 63)) == 0) before multiplying by 1000. Added clarifying inline comments describing the milliseconds/seconds flag semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

☢️ Bug

Suggested reviewers

  • Mixficsol

Poem

🐰 Timestamps tick and tock all day,
But bits were lost along the way,
A high-bit flag now shows the truth,
Milliseconds or seconds—proof!
The rabbit hops through storage code,
With cleaner logic down the road.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix:ttl' is vague and does not clearly convey what specific TTL issue was fixed or what the actual changes accomplish. Revise the title to be more specific and descriptive, such as 'Fix timestamp flag checking for TTL parsing in metadata and string value formats' to clarify the actual changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/storage/src/strings_value_format.h (1)

52-69: ⚠️ Potential issue | 🔴 Critical

HyperloglogValue::Encode does not set the milliseconds flag bit — timestamps will be corrupted when decoded.

StringsValue::Encode now ORs 1ULL << 63 into non-zero ctime_/etime_ before writing, and ParsedStringsValue treats any decoded timestamp with bit 63 == 0 as a legacy seconds value and multiplies it by 1000. However, HyperloglogValue::Encode writes raw ctime_/etime_ here (lines 65, 67) without the high-bit flag. Since HyperloglogValue shares DataType::kStrings and is decoded through ParsedStringsValue, any non-zero hyperloglog ctime/etime will be wrongly scaled by 1000 on read, producing bogus expirations. The two encoders must agree on the on-disk format.

🔧 Suggested fix
     memcpy(dst, reserve_, kSuffixReserveLength);
     dst += kSuffixReserveLength;
-    EncodeFixed64(dst, ctime_);
+    // Match StringsValue: high bit = 1 indicates a millisecond timestamp.
+    uint64_t ctime = ctime_ > 0 ? (ctime_ | (1ULL << 63)) : 0;
+    EncodeFixed64(dst, ctime);
     dst += kTimestampLength;
-    EncodeFixed64(dst, etime_);
+    uint64_t etime = etime_ > 0 ? (etime_ | (1ULL << 63)) : 0;
+    EncodeFixed64(dst, etime);
     return {start_, needed};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/storage/src/strings_value_format.h` around lines 52 - 69,
HyperloglogValue::Encode writes raw ctime_/etime_ but must set the
millisecond/high-bit flag before calling EncodeFixed64 so ParsedStringsValue
won't treat them as legacy-second timestamps; update HyperloglogValue::Encode to
OR each non-zero timestamp (ctime_ and etime_) with the high-bit mask (1ULL <<
63 or the project constant used by StringsValue) prior to the EncodeFixed64
calls for ctime_ and etime_, leaving reserve_[0] handling as-is.
🧹 Nitpick comments (3)
src/storage/src/base_meta_value_format.h (2)

82-90: Consider extracting the decode logic into a helper.

The same "mask bit 63; if bit was clear multiply by 1000" pattern is now duplicated four times across the two ParsedBaseMetaValue constructors and the two ParsedStringsValue constructors. A small inline helper (e.g. static inline uint64_t DecodeTimestamp(uint64_t raw) { return (raw & (1ULL << 63)) ? (raw & ~(1ULL << 63)) : raw * 1000; }) would remove the duplication, avoid the subtle two-step ctime_ = …; if (…) ctime_ *= 1000; sequence, and keep the seconds-vs-ms decoding rule in a single place alongside the encode-side | (1ULL << 63) logic.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/storage/src/base_meta_value_format.h` around lines 82 - 90, Extract the
repeated "mask bit 63; if bit clear multiply by 1000" logic into a single helper
(e.g. static inline uint64_t DecodeTimestamp(uint64_t raw)) and replace the
duplicated sequences in the ParsedBaseMetaValue constructors and
ParsedStringsValue constructors with calls to that helper; ensure the helper
returns (raw & ~(1ULL << 63)) when the top bit is set and returns raw*1000 when
the top bit is clear so the decoding rule is centralized and the current
two-step assign/then-multiply pattern is eliminated.

112-125: Replace Chinese inline comments with English for consistency.

The rest of this header (and the codebase file header) is in English; the newly added comments on lines 112-113, 116, 119, 122, 125 are in Chinese. Please translate them to English (the equivalent wording already exists in Encode() at lines 42-43). Also, the duplicated // 秒时间戳,转换为毫秒 inside both if branches is redundant given the outer comment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/storage/src/base_meta_value_format.h` around lines 112 - 125, Replace the
Chinese inline comments around the timestamp parsing logic in the function that
sets ctime_ and etime_ with English equivalents for consistency (match the
wording used in Encode()); specifically update the comments on the bit-strip and
check operations for ctime_ and etime_ (the lines manipulating ctime, etime,
(1ULL << 63), and assignments to ctime_ and etime_) to English and remove the
duplicate “// 秒时间戳,转换为毫秒” comment inside both if branches, keeping one clear
English comment that states: strip the MSB flag and if MSB==0 treat as seconds
and multiply by 1000 to convert to milliseconds (same wording as Encode()).
src/storage/src/strings_value_format.h (1)

115-127: Translate Chinese comments to English and drop the redundant inner comments.

Mirror comment in base_meta_value_format.h: please use English for consistency with the rest of this file, and the inner // 秒时间戳,转换为毫秒 duplicates the header comment — one comment above the two blocks is enough.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/storage/src/strings_value_format.h` around lines 115 - 127, Replace the
Chinese comments around the timestamp parsing in strings_value_format.h with a
single English comment and remove the redundant inner comments: update the
header comment above the two blocks that manipulate ctime_/etime_ (and use
ctime/etime and the high-bit check logic) to an English line like "Fix timestamp
parsing: treat value as milliseconds unless high bit is cleared indicating
seconds; strip high bit and convert seconds to milliseconds", then delete the
duplicated inner comments that currently read "秒时间戳,转换为毫秒" so only the new
English header comment remains; ensure the logic in the ctime_/etime_ blocks
(bit-strip and conditional multiply by 1000) is unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/storage/src/strings_value_format.h`:
- Around line 52-69: HyperloglogValue::Encode writes raw ctime_/etime_ but must
set the millisecond/high-bit flag before calling EncodeFixed64 so
ParsedStringsValue won't treat them as legacy-second timestamps; update
HyperloglogValue::Encode to OR each non-zero timestamp (ctime_ and etime_) with
the high-bit mask (1ULL << 63 or the project constant used by StringsValue)
prior to the EncodeFixed64 calls for ctime_ and etime_, leaving reserve_[0]
handling as-is.

---

Nitpick comments:
In `@src/storage/src/base_meta_value_format.h`:
- Around line 82-90: Extract the repeated "mask bit 63; if bit clear multiply by
1000" logic into a single helper (e.g. static inline uint64_t
DecodeTimestamp(uint64_t raw)) and replace the duplicated sequences in the
ParsedBaseMetaValue constructors and ParsedStringsValue constructors with calls
to that helper; ensure the helper returns (raw & ~(1ULL << 63)) when the top bit
is set and returns raw*1000 when the top bit is clear so the decoding rule is
centralized and the current two-step assign/then-multiply pattern is eliminated.
- Around line 112-125: Replace the Chinese inline comments around the timestamp
parsing logic in the function that sets ctime_ and etime_ with English
equivalents for consistency (match the wording used in Encode()); specifically
update the comments on the bit-strip and check operations for ctime_ and etime_
(the lines manipulating ctime, etime, (1ULL << 63), and assignments to ctime_
and etime_) to English and remove the duplicate “// 秒时间戳,转换为毫秒” comment inside
both if branches, keeping one clear English comment that states: strip the MSB
flag and if MSB==0 treat as seconds and multiply by 1000 to convert to
milliseconds (same wording as Encode()).

In `@src/storage/src/strings_value_format.h`:
- Around line 115-127: Replace the Chinese comments around the timestamp parsing
in strings_value_format.h with a single English comment and remove the redundant
inner comments: update the header comment above the two blocks that manipulate
ctime_/etime_ (and use ctime/etime and the high-bit check logic) to an English
line like "Fix timestamp parsing: treat value as milliseconds unless high bit is
cleared indicating seconds; strip high bit and convert seconds to milliseconds",
then delete the duplicated inner comments that currently read "秒时间戳,转换为毫秒" so
only the new English header comment remains; ensure the logic in the
ctime_/etime_ blocks (bit-strip and conditional multiply by 1000) is unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f58f1c1e-768e-4fd2-a424-a31cccbc78c0

📥 Commits

Reviewing files that changed from the base of the PR and between 651dae3 and c30ea4c.

📒 Files selected for processing (2)
  • src/storage/src/base_meta_value_format.h
  • src/storage/src/strings_value_format.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants