Skip to content

KVStore: reduce log#10813

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
CalvinNeo:reduce-kvstore
Apr 24, 2026
Merged

KVStore: reduce log#10813
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
CalvinNeo:reduce-kvstore

Conversation

@CalvinNeo
Copy link
Copy Markdown
Member

@CalvinNeo CalvinNeo commented Apr 24, 2026

What problem does this PR solve?

Issue Number: ref #10814

Problem Summary:

What is changed and how it works?


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Summary by CodeRabbit

  • Refactor
    • Storage persistence now accepts and forwards optional textual messages through flush paths.
    • Logging adjusted to include those messages only when present and to reduce noise by lowering some flush logs to debug.

a
Signed-off-by: Calvin Neo <calvinneo1995@gmail.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 24, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

The KVStore persistence APIs switch extra-message parameters from C-style const char* to std::string_view. Signatures for persistRegion and forceFlushRegionDataImpl are updated and logging code in persistence paths is refactored to build and forward explicit message strings.

Changes

Cohort / File(s) Summary
Header / API
dbms/src/Storages/KVStore/KVStore.h
Add #include <string_view>; change persistRegion(..., const char * extra_msg)persistRegion(..., std::string_view extra_msg) and forceFlushRegionDataImpl(..., UInt64 term)forceFlushRegionDataImpl(..., UInt64 term, std::string_view persist_extra_msg).
Persistence Implementation
dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp
Apply updated signatures; construct conditional flush_msg / force_persist_msg strings, log at LOG_DEBUG only when appropriate, and forward constructed std::string_view messages into forceFlushRegionDataImpl and persistRegion rather than passing empty C-strings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

release-note, lgtm

Suggested reviewers

  • JinheLin
  • JaySon-Huang

Poem

🐰 Old chars made way for views so fleet,
Messages trimmed and logging more neat,
Persistence hops with clarity bright,
Small changes, lighter bytes in flight!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. The Problem Summary section is empty, the commit-message block is blank, and no explanation of changes is provided despite significant API modifications to persistence methods. Complete the description by filling in Problem Summary (explain the logging reduction goal), detailing the changes (API parameter type conversions, conditional message appending, refactored logging), and checking relevant test/side-effect boxes.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 'KVStore: reduce log' is vague and does not clearly convey the specific changes made. While it hints at logging reduction, it doesn't specify which persistence APIs were modified or how. Revise title to be more specific, e.g., 'KVStore: refactor persistence logging with std::string_view' to clearly indicate the API changes and logging refactoring involved.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

✏️ 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.

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 24, 2026
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp (1)

38-47: Minor: simplify caller construction.

fmt::format("{}", PersistRegionReasonMap[reason_id]) is an unnecessary alloc+format step over a plain const char *. You can collapse it to a single conditional expression and avoid the intermediate string when extra_msg is empty.

♻️ Proposed refactor
     auto reason_id = magic_enum::enum_underlying(reason);
-    std::string caller = fmt::format("{}", PersistRegionReasonMap[reason_id]);
-    if (!extra_msg.empty())
-        caller = fmt::format("{} {}", caller, extra_msg);
+    const char * reason_name = PersistRegionReasonMap[reason_id];
+    std::string caller = extra_msg.empty()
+        ? std::string(reason_name)
+        : fmt::format("{} {}", reason_name, extra_msg);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp` around lines 38 - 47,
The current construction of caller does an unnecessary fmt::format of
PersistRegionReasonMap[reason_id] and then conditionally appends extra_msg;
instead, fetch the base C-string from PersistRegionReasonMap using reason_id and
build caller only when extra_msg is non-empty (e.g., const char* base =
PersistRegionReasonMap[reason_id]; if extra_msg.empty() caller = base; else
caller = fmt::format("{} {}", base, extra_msg)); update the code that logs the
message (LOG_INFO using region.getDebugString(), region.dataSize(), caller) to
use this simplified caller construction so we avoid the extra allocation/format
when extra_msg is empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp`:
- Line 31: The call in RaftCommandsKVS.cpp passes
raft_cmdpb::AdminCmdType_Name(cmd_type).c_str() into persistRegion which
converts to a std::string_view, creating a dangling pointer because
AdminCmdType_Name returns a temporary std::string; fix by passing the
std::string result directly or storing it in a local std::string variable before
calling persistRegion (e.g., auto extra =
raft_cmdpb::AdminCmdType_Name(cmd_type); then pass extra or pass extra as
std::string_view) so persistRegion receives a stable string lifetime; ensure
changes reference the persistRegion call and AdminCmdType_Name usage.

---

Nitpick comments:
In `@dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp`:
- Around line 38-47: The current construction of caller does an unnecessary
fmt::format of PersistRegionReasonMap[reason_id] and then conditionally appends
extra_msg; instead, fetch the base C-string from PersistRegionReasonMap using
reason_id and build caller only when extra_msg is non-empty (e.g., const char*
base = PersistRegionReasonMap[reason_id]; if extra_msg.empty() caller = base;
else caller = fmt::format("{} {}", base, extra_msg)); update the code that logs
the message (LOG_INFO using region.getDebugString(), region.dataSize(), caller)
to use this simplified caller construction so we avoid the extra
allocation/format when extra_msg is empty.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b2c35c4b-35c0-430e-8304-b59f5e1672e8

📥 Commits

Reviewing files that changed from the base of the PR and between c6a40dd and 8e26c69.

📒 Files selected for processing (2)
  • dbms/src/Storages/KVStore/KVStore.h
  • dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp

Comment thread dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp
Signed-off-by: Calvin Neo <calvinneo1995@gmail.com>
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.

🧹 Nitpick comments (1)
dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp (1)

39-41: Minor: collapse the caller-string construction into a single allocation.

fmt::format("{}", PersistRegionReasonMap[reason_id]) is an extra allocation for a no-op format, and the re-assignment on line 41 pays for another temporary. You can produce the final string in one step.

♻️ Proposed simplification
-    auto reason_id = magic_enum::enum_underlying(reason);
-    std::string caller = fmt::format("{}", PersistRegionReasonMap[reason_id]);
-    if (!extra_msg.empty())
-        caller = fmt::format("{} {}", caller, extra_msg);
+    auto reason_id = magic_enum::enum_underlying(reason);
+    const char * reason_str = PersistRegionReasonMap[reason_id];
+    std::string caller = extra_msg.empty()
+        ? std::string(reason_str)
+        : fmt::format("{} {}", reason_str, extra_msg);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp` around lines 39 - 41,
Collapse the two-step caller construction into a single allocation by calling
fmt::format once to produce the final string: use
PersistRegionReasonMap[reason_id] as the first component and append extra_msg
only when non-empty (inserting a preceding space only if extra_msg is present),
replacing the current two statements that set caller and then reassign it when
extra_msg is non-empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp`:
- Around line 39-41: Collapse the two-step caller construction into a single
allocation by calling fmt::format once to produce the final string: use
PersistRegionReasonMap[reason_id] as the first component and append extra_msg
only when non-empty (inserting a preceding space only if extra_msg is present),
replacing the current two statements that set caller and then reassign it when
extra_msg is non-empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5fe60d4d-7cf8-4cf9-bb26-6b2d831f4c88

📥 Commits

Reviewing files that changed from the base of the PR and between 8e26c69 and 41c3060.

📒 Files selected for processing (2)
  • dbms/src/Storages/KVStore/KVStore.h
  • dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp

Copy link
Copy Markdown
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,JinheLin]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 24, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 24, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-24 08:16:53.589110443 +0000 UTC m=+2326618.794470501: ☑️ agreed by JinheLin.
  • 2026-04-24 09:25:50.689260569 +0000 UTC m=+2330755.894620626: ☑️ agreed by JaySon-Huang.

@ti-chi-bot ti-chi-bot Bot merged commit 0dc254b into pingcap:master Apr 24, 2026
8 of 10 checks passed
@JaySon-Huang
Copy link
Copy Markdown
Contributor

/cherry-pick release-8.5

@ti-chi-bot
Copy link
Copy Markdown
Member

@JaySon-Huang: new pull request created to branch release-8.5: #10877.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-8.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot mentioned this pull request May 29, 2026
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants