Skip to content

Comments

planner: ensure that the path of the plan replayer file generated by the old and new versions of TiDB is the same#66348

Open
zeminzhou wants to merge 2 commits intopingcap:masterfrom
zeminzhou:fix-compatibility
Open

planner: ensure that the path of the plan replayer file generated by the old and new versions of TiDB is the same#66348
zeminzhou wants to merge 2 commits intopingcap:masterfrom
zeminzhou:fix-compatibility

Conversation

@zeminzhou
Copy link
Contributor

@zeminzhou zeminzhou commented Feb 24, 2026

What problem does this PR solve?

Issue Number: close #66347

Problem Summary:

What changed and how does it work?

Root cause

getLocalPathDirName() in pkg/planner/extstore/extstore.go decides the local storage root for plan replayer when no cloud storage URI is set. Plan replayer then writes objects under GetPlanReplayerDirName() (i.e. the "replayer" segment) relative to that root. So the effective path is <getLocalPathDirName()>/replayer/. For backward compatibility, this must match the old layout: <log_dir>/replayer/, i.e. the storage root must be the log directory, not a path that already includes replayer.

Fix

Ensure getLocalPathDirName() returns the log directory (filepath.Dir(config.GetGlobalConfig().Log.File.Filename)), same as the old behavior, so the storage root is unchanged.
Keep writability checks so we only use this log dir when we can actually write there (or when we can write under the replayer subdir, depending on the chosen check).
No change to how plan replayer builds object keys: it still uses replayer/, so the final path remains <log_dir>/replayer/ and matches old TiDB.

Result

Old and new TiDB versions use the same plan replayer file location for local storage, so upgrades and path-dependent tooling remain compatible.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

… by the old and new versions of TiDB is the same

Signed-off-by: zeminzhou <zhouzemin@pingcap.com>
@pantheon-ai
Copy link

pantheon-ai bot commented Feb 24, 2026

Posted PR review with inline comments: #66348 (review)

Note: pkg/planner/extstore/extstore.go:112 is outside the PR diff, so the inline comment for Issue 3 is anchored at pkg/planner/extstore/extstore.go:138 instead.

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 24, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign elsa0520 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@tiprow
Copy link

tiprow bot commented Feb 24, 2026

Hi @zeminzhou. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

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 kubernetes-sigs/prow repository.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.4829%. Comparing base (45621f6) to head (4134caa).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #66348        +/-   ##
================================================
- Coverage   77.6822%   77.4829%   -0.1994%     
================================================
  Files          2006       1928        -78     
  Lines        548533     536949     -11584     
================================================
- Hits         426113     416044     -10069     
- Misses       120759     120899       +140     
+ Partials       1661          6      -1655     
Flag Coverage Δ
integration 41.4012% <75.0000%> (-6.7842%) ⬇️
unit 76.6430% <100.0000%> (+0.3228%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 48.7997% <ø> (-12.0645%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

timeStr := now.Format("20060102150405")
filename := fmt.Sprintf("test_%s.txt", timeStr)
path = filepath.Join(path, filename)
dir = filepath.Join(dir, "replayer")
Copy link

Choose a reason for hiding this comment

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

P2: Storage root can change across upgrades causing 404s

The local root selection depends on whether <logDir>/replayer/ exists. If this directory is not pre-created (even when <logDir> is writable), extstore falls back to TempDir. This means:

  • After upgrade, the storage root can change from <logDir> to TempDir (or vice versa)
  • Previously generated diagnostic artifacts (extract, optimizer trace, plan replayer files) will appear missing
  • Download endpoints will return 404 for existing files stored under the old root

Recommendation: Consider auto-creating <logDir>/replayer during initialization, or implement fallback logic to check multiple root locations during file lookups.

tidbLogDir := filepath.Dir(config.GetGlobalConfig().Log.File.Filename)
tidbLogDir = filepath.Clean(tidbLogDir)
if canWriteToFile(fs, tidbLogDir) {
if canWriteToReplayerDirFile(fs, tidbLogDir) {
Copy link

Choose a reason for hiding this comment

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

P2: Non-writable log base can cause diagnostic feature failures

The writability check tests <logDir>/replayer/ but returns <logDir> as the storage root. Other extstore consumers (extract, optimizer_trace) need to create their own top-level subdirectories under <logDir>.

In permission layouts where:

  • <logDir> is not writable
  • <logDir>/replayer IS writable (pre-created/mounted/symlinked)

These operations will fail with permission errors when trying to create <logDir>/extract/ or <logDir>/optimizer_trace/.

Recommendation: Either check writability of <logDir> itself, or have canWriteToReplayerDirFile return <logDir>/replayer instead of <logDir>.

tidbLogDir := filepath.Dir(config.GetGlobalConfig().Log.File.Filename)
tidbLogDir = filepath.Clean(tidbLogDir)
if canWriteToFile(fs, tidbLogDir) {
if canWriteToReplayerDirFile(fs, tidbLogDir) {
Copy link

Choose a reason for hiding this comment

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

P2: Keyspace/namespace directory path not validated

NewExtStorage appends keyspaceName to the local base path, creating <logDir>/<keyspace> as the actual storage root. However, canWriteToReplayerDirFile only validates <logDir>/replayer/, not <logDir>/<keyspace>/.

If <logDir>/replayer is writable but <logDir> does not have permissions to create new sibling directories, the extstore initialization will fail when trying to mkdirAll(<logDir>/<keyspace>).

Impact: Breaks plan-replayer, trace, and extract features in keyspace-enabled deployments with restrictive directory permissions.

Recommendation: The writability probe should test the actual target path including the keyspace namespace.

@zeminzhou
Copy link
Contributor Author

/check-issue-triage-complete

@zeminzhou
Copy link
Contributor Author

/run-check-issue-triage-complete

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

Labels

release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The file generated by Plan Replayer has changed its storage path.

1 participant