fix:SETEX replication does not work#3133
fix:SETEX replication does not work#3133Mixficsol merged 1 commit intoOpenAtomFoundation:unstablefrom
Conversation
WalkthroughThe changes update how expiration timestamps are calculated and stored in key-value commands, shifting to explicit 64-bit integer arithmetic to prevent overflow and improve precision. These modifications affect the internal handling of TTL and expiration times within methods for setting keys with expiration. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Command (Setex/Psetex/SetexAt)
participant TimeUtil
participant Storage
Client->>Command: Set key with TTL
Command->>TimeUtil: Get current time (sec/ms)
TimeUtil-->>Command: Return 64-bit timestamp
Command->>Command: Calculate expire_at using 64-bit arithmetic
Command->>Storage: Store key with expire_at
Storage-->>Command: Acknowledge
Command-->>Client: Respond
Estimated code review effort1 (~2 minutes) Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧠 Learnings (1)src/pika_kv.cc (2)Learnt from: hahahashen Learnt from: hahahashen 🧰 Additional context used🧠 Learnings (1)src/pika_kv.cc (2)Learnt from: hahahashen Learnt from: hahahashen ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
🔇 Additional comments (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
| void PKSetexAtCmd::Do() { | ||
| s_ = db_->storage()->PKSetexAt(key_, value_, static_cast<int32_t>(time_stamp_sec_ * 1000)); | ||
| // Use int64_t to avoid overflow | ||
| int64_t time_stamp_ms = static_cast<int64_t>(time_stamp_sec_) * 1000; |
There was a problem hiding this comment.
这里的 time_stamp_sec 已经是 int64_t 了,为啥还需要转一下
There was a problem hiding this comment.
是的已经是int64_t了,保留static_cast<int64_t>是为了和源代码对齐
修复了pika4.0中setex在主从上不同步的bug #3117
修改的代码部分
1.过期时间计算错误:
此次修改将 SETEX/PSETEX 写入 binlog 时统一转换为接受绝对秒级时间戳的 pksetexat 指令,先在主库把 “当前时间 + TTL” 换算成过期时间点后落库,保证从库收到后与主库在同一时刻过期;同时把 PKSetexAtCmd::Do() 中时间戳乘 1000 的结果改用 int64_t 传递,避免 32 位溢溢出导致过期时间为负数,键立即失效,从而彻底解决主从过期不一致的问题。
修改后的运行截图
Summary by CodeRabbit