Repository navigation
fix(logservice): reuse pooled client for remote truncate - #25291
jiangxinmeng1 wants to merge 1 commit into
Conversation
PR Summary by QodoFix remote logservice truncate to reuse pooled client
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Truncate path deadlocks
|
| if client, err = d.clientPool.Get(); err != nil { | ||
| return | ||
| } | ||
| defer client.Putback() |
There was a problem hiding this comment.
1. Truncate path deadlocks 🐞 Bug ☼ Reliability
truncateFromRemote now borrows a pooled client and defers Putback; when Truncate returns ErrInvalidTruncateLsn it calls getTruncatedPSNFromBackend which borrows from the same pool again. With ClientMaxCount=1, the second Get waits forever because the only client is still held, hanging truncation.
Agent Prompt
### Issue description
`truncateFromRemote` now checks out a pooled client via `clientPool.Get()` and defers `client.Putback()`. If the backend responds with `ErrInvalidTruncateLsn`, the function calls `getTruncatedPSNFromBackend`, which itself calls `clientPool.Get()` again. When `ClientMaxCount == 1`, this re-entrant borrow blocks forever because the first client is still checked out.
### Issue Context
The invalid-truncate branch is reachable when the remote has already truncated past `psnIntent`.
### Fix Focus Areas
- pkg/vm/engine/tae/logstore/driver/logservicedriver/truncate.go[139-199]
- pkg/vm/engine/tae/logstore/driver/logservicedriver/truncate.go[203-228]
### Suggested fix
In the `ErrInvalidTruncateLsn` branch, do not call `getTruncatedPSNFromBackend` while holding a pooled client. Instead:
- reuse the already-borrowed `client` to call `client.wrapped.GetTruncatedLsn(loopCtx)` (or extract a helper that accepts a `*wrappedClient`), OR
- `client.Putback()` before calling `getTruncatedPSNFromBackend` and ensure you don’t double-putback.
Add a regression test with `ClientMaxCount=1` where the backend returns `ErrInvalidTruncateLsn` (e.g., pre-set truncated LSN higher than `psnIntent`) and assert `truncateFromRemote` returns without hanging and reports the remote truncated LSN.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
What type of PR is this?
Which issue(s) this PR fixes:
issue #25276
What this PR does / why we need it:
This PR changes truncateFromRemote to borrow an existing client from clientPool instead of creating a new on-the-fly logservice client for every truncate operation.
Previously, remote truncate used GetOnFly(), which created a fresh client each time. When logservice client creation was slow because of unreachable or stale replica addresses, truncate could repeatedly trigger
expensive connection attempts.
Changes: