Repository navigation
Description
Background
Related to #24962.
The immediate hang in #24962 is not caused by IVF SQL semantics directly. The stack traces point to pipeline cleanup waiting indefinitely for terminal pipeline signals, for example Merge.Reset -> PipelineSignalReceiver.WaitingEnd, while the corresponding sender side may fail to send or the receiver may fail to consume the final end signal.
The current protocol is distributed across several implicit mechanisms:
nilbatch means end/error in some paths.WaitRegister.Ch2is used for both data notifications and terminal notifications.PipelineSpool.Close()waits for receivers to consume terminal messages.- cleanup ordering decides whether sender or receiver can make progress.
- some cleanup paths used unbounded sends or
context.TODO()waits.
This makes unhappy paths fragile: cancellation, remote CN failure, network jitter, channel backpressure, mismatched NilBatchCnt, or cleanup order can leave one side waiting for another side that is no longer guaranteed to make progress.
First principles
A pipeline edge should have an explicit lifecycle and these invariants:
- Terminal state is a protocol event, not an implicit
nildata batch. End,Error, andAbortare idempotent. Calling them multiple times must be safe.- Cleanup must not depend on the peer consuming one more channel message.
- Every send, receive, and terminal wait must be cancelable or bounded.
- Spool memory ownership must be independent from channel notification delivery. If receivers are late or gone, cleanup must avoid use-after-free even if it cannot reclaim all memory immediately.
- Normal long-running queries must not be affected by cleanup-only deadlines.
Proposed direction
Introduce an explicit pipeline edge abstraction, or evolve WaitRegister toward one, with typed events:
DataEndErrorAbort
The edge should provide APIs along these lines:
type PipelineEventType int
const (
EventData PipelineEventType = iota
EventEnd
EventError
EventAbort
)
type PipelineEvent struct {
Type PipelineEventType
Batch *batch.Batch
Err error
Spool *pSpool.PipelineSpool
Index int
}
type PipelineEdge struct {
// implementation detail: channel, done/abort signals, terminal state, once guards
}
func (e *PipelineEdge) Send(ctx context.Context, ev PipelineEvent) error
func (e *PipelineEdge) Recv(ctx context.Context) (PipelineEvent, error)
func (e *PipelineEdge) Close(err error)
func (e *PipelineEdge) Abort(err error)
func (e *PipelineEdge) Done() <-chan struct{}Connector, Dispatch, remote notify forwarding, and Merge should use this lifecycle instead of open-coded terminal sends and waits.
Suggested migration plan
- Add cancellation-aware terminal APIs behind the existing
WaitRegistersurface. - Replace cleanup-time naked sends to
WaitRegister.Ch2with the new APIs. - Add explicit
End/Error/Abortevent types toPipelineSignalor a replacement event type. - Remove or reduce reliance on
NilBatchCntfor terminal correctness. - Move
PipelineSpoolterminal/close behavior to an abortable lifecycle API, preserving safe memory ownership. - Convert normal data send paths such as local
Connector/Dispatchnotification sends to context-aware APIs where appropriate. - Add tests for sender exits first, receiver exits first, channel full, missing end, multi-CN remote receiver failure, network/cancel races, and slow-but-healthy long-running queries.
Acceptance criteria
- No pipeline cleanup path can wait forever on a peer channel, remote error channel, spool close, or terminal signal.
Merge.Resetand sender cleanup do not rely on cleanup ordering to avoid deadlock.- Terminal events are idempotent and observable in diagnostics.
- Normal query execution is not bounded by cleanup-only timeouts.
- Spool cleanup cannot free memory that a late receiver can still access.
- Existing CTE/recursive pipeline special cleanup semantics are preserved.
- Tests cover local, multi-CN, cancellation, backpressure, and receiver/sender mismatch unhappy paths.
Notes
A short-term mitigation can bound waits and add diagnostics, but the long-term fix should make the termination protocol explicit so correctness is enforced by the API rather than by cleanup order and implicit nil batch conventions.
Activity
fix: bound pipeline cleanup waits (#24972)
fix: bound pipeline cleanup waits (matrixorigin#24972)
fix: bound pipeline cleanup waits (matrixorigin#24972)
refactor: make pipeline termination protocol explicit and cancellatio…
fix(pipeline): preserve terminal errors across spool abort (#25620)
fix: bound pipeline cleanup waits (matrixorigin#24972)
refactor: make pipeline termination protocol explicit and cancellatio…
fix(pipeline): preserve terminal errors across spool abort (matrixori…
fix: bound pipeline cleanup waits (matrixorigin#24972)
refactor: make pipeline termination protocol explicit and cancellatio…
fix(pipeline): preserve terminal errors across spool abort (matrixori…
fix: bound pipeline cleanup waits (matrixorigin#24972)
refactor: make pipeline termination protocol explicit and cancellatio…
fix(pipeline): preserve terminal errors across spool abort (matrixori…