Skip to content

Add debug helpers for cached region/store info#1962

Open
gengliqi wants to merge 1 commit into
tikv:masterfrom
gengliqi:add-cached-store-region
Open

Add debug helpers for cached region/store info#1962
gengliqi wants to merge 1 commit into
tikv:masterfrom
gengliqi:add-cached-store-region

Conversation

@gengliqi
Copy link
Copy Markdown
Member

@gengliqi gengliqi commented May 11, 2026

This PR adds two debug helper functions, GetCachedRegionDebugInfoByID and GetCachedStoreDebugInfoByID, to get cached region/store information by ID.

Summary by CodeRabbit

  • New Features

    • Introduced debug inspection APIs for querying cached region and store information directly without external lookups.
    • Added method to retrieve store status addresses.
  • Tests

    • Added test cases validating cache debug information retrieval functionality.

Review Change Stack

u
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 11, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdfe7e9b-fe9d-4d45-89bf-22124148dea9

📥 Commits

Reviewing files that changed from the base of the PR and between fb7ee09 and e9c8fb9.

📒 Files selected for processing (4)
  • internal/locate/region_cache.go
  • internal/locate/region_cache_test.go
  • internal/locate/store_cache.go
  • tikv/region.go

📝 Walkthrough

Walkthrough

This PR adds debug introspection APIs to the region and store caches, enabling inspection of cached metadata including TTL, validity, sync flags, and health scores without triggering PD lookups. New types expose region peer-store diagnostics, and wrapper functions in the public API delegate to cache methods for safe, locked access to internal state.

Changes

Cache Debug Introspection APIs

Layer / File(s) Summary
Debug Data Types
internal/locate/region_cache.go
Three new exported structs: CachedRegionPeerStoreDebugInfo for peer-store pairs, CachedRegionDebugInfo for region state (TTL, validity, sync flags, metadata), and CachedStoreDebugInfo for store state (address, resolve/liveness, health scores, labels).
Store Status Accessor
internal/locate/store_cache.go
Store.GetStatusAddr() method returns the store's status address under read lock.
Cache Debug Info Methods
internal/locate/region_cache.go
GetCachedRegionDebugInfoByID fetches and enriches region cache state with peer store info and health details; GetCachedStoreDebugInfoByID returns store cache state; syncFlagNames helper translates flag bitmasks to names.
Public API Wrappers
tikv/region.go
Type aliases for debug info types and wrapper functions GetCachedRegionDebugInfoByID and GetCachedStoreDebugInfoByID that delegate to cache methods.
Tests
internal/locate/region_cache_test.go
TestGetCachedRegionDebugInfoByID validates region identifiers/versions/validity/sync flags; TestGetCachedStoreDebugInfoByID validates store addresses/resolve state; both verify ok == false for invalid IDs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • tikv/client-go#1826: Modifies the same RegionCache and Store cache codepaths; the debug APIs rely on store/region accessor patterns introduced there.

Suggested labels

lgtm, approved, size/XL

Suggested reviewers

  • ekexium

Poem

🐰 Cache secrets now exposed,
No lookups need apply,
Debug flags and health scores shown,
State read safely, locked and dry!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add debug helpers for cached region/store info' accurately describes the main change: introducing debug helper functions and APIs for inspecting cached region and store data.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 12, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zyguan

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:

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
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-12 02:20:51.070813701 +0000 UTC m=+145819.603593010: ☑️ agreed by zyguan.

@ti-chi-bot ti-chi-bot Bot added the approved label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants