-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat:slow log field #3196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
feat:slow log field #3196
Conversation
WalkthroughThe slowlog system is extended to track element counts for complex data types. A new Changes
Sequence DiagramsequenceDiagram
participant Client
participant PikaClientConn
participant DB as Storage
participant SlowlogCmd
Client->>PikaClientConn: Execute command
PikaClientConn->>PikaClientConn: Command exceeds slowlog threshold
PikaClientConn->>PikaClientConn: Inspect command type
alt Complex Type (hash, set, list, zset)
PikaClientConn->>DB: Query element count<br/>(HLen/SCard/LLen/ZCard)
DB-->>PikaClientConn: Return count
PikaClientConn->>PikaClientConn: element_count = count
else Other Type
PikaClientConn->>PikaClientConn: element_count = -1
end
PikaClientConn->>PikaClientConn: SlowlogPushEntry(argv, time, duration, element_count)
PikaClientConn->>SlowlogCmd: Store entry with metadata
SlowlogCmd->>SlowlogCmd: Serialize with element_count if ≥ 0
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
include/pika_define.h (1)
287-294: SlowlogEntry.element_count semantics look good; consider in-class defaults instead of ctorThe new
element_countfield with-1sentinel integrates cleanly with the slowlog code paths that treat< 0as “not applicable.” The explicit default constructor is fine, but it also turnsSlowlogEntryinto a non-aggregate, which can break any brace-initialization uses that may have existed.If you want to avoid that risk and keep the type an aggregate, you could instead rely on in-class default member initializers and drop the custom ctor, e.g.:
struct SlowlogEntry { - int64_t id; - int64_t start_time; - int64_t duration; + int64_t id = 0; + int64_t start_time = 0; + int64_t duration = 0; net::RedisCmdArgsType argv; - int64_t element_count; // 复杂数据类型的元素个数,-1表示不适用 - SlowlogEntry() : id(0), start_time(0), duration(0), element_count(-1) {} + int64_t element_count = -1; // element count for complex types, -1 means N/A };This preserves default values while keeping initialization flexible and consistent.
src/pika_client_conn.cc (1)
233-327: Slowlog element_count computation is correct; consider centralizing command-to-type mappingThe new
ProcessSlowloglogic correctly:
- Guards on the slowlog threshold before doing any extra work.
- Normalizes
cmd_nameto lowercase and only issues an HLEN/SCARD/LLEN/ZCARD when the command is one of the expected hash/set/list/zset operations.- Uses
element_count = -1as a “no data” sentinel, which aligns with the admin and server code, and passes it through toSlowlogPushEntry.- Extends the slowlog error log with an
element_countfragment only when the value is set, preserving the old log format otherwise.Functionally this looks solid. If you want to reduce duplication and make it easier to extend, you might factor the long
if/else ifcommand-name chain into a small helper that mapscmd_name→ container type (or directly to a lambda that performs the appropriate*Cardcall), so future commands don’t have to modify this function’s control flow.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
include/pika_define.h(1 hunks)include/pika_server.h(1 hunks)src/pika_admin.cc(1 hunks)src/pika_client_conn.cc(2 hunks)src/pika_server.cc(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
include/pika_server.h (1)
src/pika_server.cc (2)
SlowlogPushEntry(954-987)SlowlogPushEntry(954-954)
src/pika_client_conn.cc (4)
src/pika_command.cc (2)
argv(1057-1057)argv(1057-1057)src/pstd/src/pstd_string.cc (2)
StringToLower(638-641)StringToLower(638-638)src/storage/src/lists_data_key_format.h (1)
key(103-103)src/storage/src/zsets_data_key_format.h (1)
key(112-112)
src/pika_admin.cc (1)
src/net/src/redis_cli.cc (1)
arg(239-239)
⏰ 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). (4)
- GitHub Check: Analyze (go)
- GitHub Check: build_on_ubuntu
- GitHub Check: build_on_centos
- GitHub Check: build_on_macos
🔇 Additional comments (3)
src/pika_server.cc (1)
954-987: SlowlogPushEntry correctly propagates element_countThe extended signature and
entry.element_count = element_count;assignment integrate cleanly with the existing slowlog path; default-1from the header will maintain prior behavior when callers don’t supply a value. No concurrency or correctness issues here.src/pika_admin.cc (1)
3339-3355: Slowlog serialization cleanly extends to optional element_countThe logic to emit a 5-element array only when
slowlog.element_count >= 0and append the extra integer field after the argv list preserves backward compatibility (4 fields when not set) while exposing the new metric when available. This matches the-1sentinel semantics used inSlowlogEntry.include/pika_server.h (1)
240-246: SlowlogPushEntry API extension is backward compatibleThe updated declaration adding
int64_t element_count = -1keeps existing callers working via the default argument while allowing new call sites (likeProcessSlowlog) to pass a real count. The type remains compatible withPikaCmdArgsType, and the definition inpika_server.ccmatches the signature.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.