You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deferred the marshaling of the log entry until the async group commits.
Clean some code.
overview:
---------------------------------------------
| txn op --> pre wal --> on wal --> post wal |
---------------------------------------------
details:
[------ on wal --------------]
pre wal ==> parallel marshal ==> flush wal \\
==> apply ==> done apply(commit/rollback) ==> push logtail
==> collect logtail //
(wait marshal) [---------- post wal (wait flush) --------------------]
PR Type
Enhancement
Description
Deferred marshaling of log entries until async group commits
Added ApproxSize() interface to estimate payload sizes
Refactored transaction processing pipeline with parallel WAL operations
Improved logtail collection with concurrent processing
Diagram Walkthrough
flowchart LR
A["Transaction Op"] --> B["Pre WAL"]
B --> C["Parallel Marshal"]
B --> D["Collect Logtail"]
C --> E["Flush WAL"]
D --> F["Wait Marshal"]
E --> G["Apply"]
F --> G
G --> H["Done Apply"]
H --> I["Push Logtail"]
qodo-code-reviewBot
changed the title
improve: deferred the marshaling of the log entry until the async group commits and cleaned some code.
improve: deferred the marshaling of the log entry until the async group commits and cleaned some code.
Sep 5, 2025
In onTxnLogTails, the closure captures loop variable 'i' and assigns mgr.orderedList[i] inside a goroutine. Although i is used as an index for each item, ensure that 'i' is not modified before goroutine execution and that orderedList is sized appropriately to avoid index races or nil gaps when fewer items than capacity are processed.
Finish now returns (LogEntry, error) and executes pre-WAL callbacks per entry. Callers like group_committer.Commit and tests were updated, but verify all other call sites handle errors, and that RegisterGroupWalPreCallbacks failures propagate and abort commit cleanly without leaving inconsistent state.
ApplyTxnRecord defers marshaling via a pre-WAL callback and signals DoneEvent(WalPreparing) inside that callback. Ensure event ordering with TailCollecting and WAL flush is correct and that DoneEvent executes even if MarshalBinary fails, to avoid deadlocks waiting on events.
In logtail.Manager.onTxnLogTails, the goroutines close over the loop variables i and txn, which are reused across iterations, causing incorrect indexing and mixing of transactions under concurrency. Capture per-iteration copies (e.g., idx := i; t := txn) and use those inside the submitted function to avoid racey behavior and mis-ordered logtail generation. This fix is critical to ensure tails are collected and applied for the intended transaction in the correct order.
Why: This suggestion correctly identifies a critical bug where loop variables i and txn are captured by a goroutine, which will lead to data races and incorrect logtail processing.
High
Possible issue
Fix goroutine variable capture issue
The goroutine captures the loop variable i which could lead to race conditions or incorrect indexing when the goroutine executes after the loop iteration changes.
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 9
__
Why: This suggestion correctly identifies a critical bug where the loop variable i is captured by a goroutine, which would lead to a race condition and incorrect behavior.
High
Fix silent error handling in prepareRecord
The function returns 0 when ExecuteGroupWalPreCallbacks fails but doesn't propagate the error. This silent failure could lead to data corruption or unexpected behavior.
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that an error from ExecuteGroupWalPreCallbacks is silently ignored, which could lead to data corruption; propagating the error is the correct fix.
Medium
Fix inconsistent error handling patterns
The function panics on WriteTo error but returns an error for ExecuteGroupWalPreCallbacks. This inconsistent error handling could lead to unexpected crashes instead of proper error propagation.
func (w *LogEntryWriter) Finish() (LogEntry, error) {
for _, e := range w.entries {
if err := e.Entry.ExecuteGroupWalPreCallbacks(); err != nil {
return nil, err
}
w.buf.Reset()
if _, err := e.WriteTo(&w.buf); err != nil {
- panic(err)+ return nil, err
}
eBuf := w.buf.Bytes()
w.Append(eBuf)
}
w.Entry.SetFooter(w.Footer)
return w.Entry, nil
}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out inconsistent error handling where one error is returned and another causes a panic, improving code robustness by handling the error gracefully.
Medium
General
✅ Replace hardcoded magic number with constantSuggestion Impact:The commit replaced the hardcoded 50 with a configurable field (d.config.ClientMaxEntryCount), making the threshold configurable as suggested.
code diff:
- if len(d.committer.writer.entries) >= 50 {+ if len(d.committer.writer.entries) >= d.config.ClientMaxEntryCount {
d.flushCurrentCommitter()
The hardcoded value of 50 entries should be configurable or derived from a constant. This magic number makes the code less maintainable and could impact performance tuning.
Why: The suggestion correctly identifies a magic number and proposes replacing it with a constant, which improves code readability and maintainability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue ##15166
What this PR does / why we need it:
PR Type
Enhancement
Description
Deferred marshaling of log entries until async group commits
Added
ApproxSize()interface to estimate payload sizesRefactored transaction processing pipeline with parallel WAL operations
Improved logtail collection with concurrent processing
Diagram Walkthrough
File Walkthrough
25 files
Add ApproxSize method to BaseNode interfaceImplement ApproxSize for EntryCommandAdd ApproxSize implementations for DB nodesImplement ApproxSize for metadata nodesAdd ApproxSize method to Schema and ColDefImplement ApproxSize for table MVCC nodesAdd ApproxSize method to TxnCmd interfaceUpdate trace constants for new pipelineAdd ApproxSize method to TxnMemoUpdate transaction interfaces for new pipelineExecute group WAL pre-callbacks before prepareUse ApproxSize and add entry count limitDefer marshaling with pre-callbacks and ApproxSizeAdd pre-callback system and ApproxSize supportAdd callback and size estimation interfacesRefactor with concurrent logtail collectionImplement ApproxSize for Tree structuresAdd ApproxSize and remove cmd buffer limitsAdd event management methods to NoopTxnStoreRename methods for new async patternAdd ApproxSize method to TxnCtxRefactor transaction pipeline with parallel processingImplement ApproxSize for AppendCmdDefer marshaling with callback systemReplace wait groups with event management1 files
Increase default client buffer size11 files