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
{{ message }}
Repository navigation
(fix): Prevent Silent Data Loss in Multi-CN Dispatch - #22751
When a remote CN becomes unavailable (ReceiverDone=true), data destined for that CN was silently dropped without error in SendToAll/Shuffle scenarios, leading to incomplete query results.
Solution
Introduce receiverFailureMode to distinguish between scenarios:
FailureModeStrict (SendToAll/Shuffle): Return error on receiver failure
FailureModeTolerant (SendToAny): Allow failover to other receivers
PR Type
Bug fix, Tests
Description
Prevent silent data loss when remote CN becomes unavailable in SendToAll/Shuffle scenarios
Introduce receiverFailureMode to distinguish strict vs tolerant failure handling
Add comprehensive integration tests documenting the data loss bug and fix
Return explicit errors in strict mode when receiver is done, protecting data integrity
Diagram Walkthrough
flowchart LR
A["Remote CN Unavailable<br/>ReceiverDone=true"] --> B{"Failure Mode?"}
B -->|FailureModeStrict| C["SendToAll/Shuffle<br/>Return Error"]
B -->|FailureModeTolerant| D["SendToAny<br/>Failover to Other"]
C --> E["Query Fails<br/>Data Protected"]
D --> F["Try Next Receiver<br/>Graceful Degradation"]
Below is a summary of compliance checks for this PR:
Security Compliance
🟢
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
⚪
🎫 No ticket provided
Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Status: Passed
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Passed
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Passed
⚪
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: No audit logs: New strict/tolerant failure handling and receiver removal paths do not emit any audit logs for critical events (e.g., receiver failure, data-loss prevention error), which may be acceptable for low-level components but warrants verification.
Referred Code
returnfalse, errEncode
}
// SendToAny can tolerate individual receiver failures// We can try other receivers if one failsmaxRetries:=len(ap.ctr.remoteReceivers)
retriesLeft:=maxRetriesforretriesLeft>0 {
ifap.ctr.remoteRegsCnt==0 {
returnfalse, moerr.NewInternalError(proc.Ctx,
"sendToAny failed: all remote receivers are unavailable")
}
regIdx:=ap.ctr.sendCnt%ap.ctr.remoteRegsCntreg:=ap.ctr.remoteReceivers[regIdx]
receiverID:=fmt.Sprintf("%s(Idx=%d)", reg.Uid.String(), regIdx)
// SendToAny uses tolerant mode - can failover to other receiversremove, err:=sendBatchToClientSession(proc.Ctx, encodeData, reg, FailureModeTolerant, receiverID)
iferr!=nil {
... (clipped21lines)
Compliance status legend
🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
⚪
🎫 No ticket provided
Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Status: Passed
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Passed
⚪
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: No auditing: The new logic and tests introduce error paths and receiver removal but do not add or reference audit logging for these critical actions.
Referred Code
{ // send to remote regsencodeData, errEncode:=bat.MarshalBinaryWithBuffer(&ap.ctr.marshalBuf)
iferrEncode!=nil {
returnfalse, errEncode
}
fori:=0; i<len(ap.ctr.remoteReceivers); i++ {
receiver:=ap.ctr.remoteReceivers[i]
receiverID:=fmt.Sprintf("%s(MsgId=%d)", receiver.Uid.String(), receiver.MsgId)
// SendToAll requires strict failure checking// If any receiver fails, we must report error to prevent data lossremove, err:=sendBatchToClientSession(proc.Ctx, encodeData, receiver, FailureModeStrict, receiverID)
iferr!=nil {
returnfalse, err
}
ifremove {
ap.ctr.removeIdxReceiver(i)
ifap.ctr.remoteRegsCnt==0 {
... (clipped76lines)
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Error detail scope: Errors include internal receiver identifiers like UIDs (e.g., "receiver %s(MsgId=%d)"), which may be sensitive if surfaced to end-users; confirm these remain internal-only.
Referred Code
{ // send to remote regsencodeData, errEncode:=bat.MarshalBinaryWithBuffer(&ap.ctr.marshalBuf)
iferrEncode!=nil {
returnfalse, errEncode
}
fori:=0; i<len(ap.ctr.remoteReceivers); i++ {
receiver:=ap.ctr.remoteReceivers[i]
receiverID:=fmt.Sprintf("%s(MsgId=%d)", receiver.Uid.String(), receiver.MsgId)
// SendToAll requires strict failure checking// If any receiver fails, we must report error to prevent data lossremove, err:=sendBatchToClientSession(proc.Ctx, encodeData, receiver, FailureModeStrict, receiverID)
iferr!=nil {
returnfalse, err
}
ifremove {
ap.ctr.removeIdxReceiver(i)
ifap.ctr.remoteRegsCnt==0 {
... (clipped76lines)
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Input validation: The new paths send encoded batch data over RPC without explicit validation or sanitization in the shown diff; verification is needed that upstream validation and size limits are sufficient.
// SendToAny can tolerate individual receiver failures
// We can try other receivers if one fails
+if ap.ctr.remoteRegsCnt == 0 {+ return false, moerr.NewInternalError(proc.Ctx,+ "sendToAny failed: all remote receivers are unavailable")+}+
maxRetries := len(ap.ctr.remoteReceivers)
retriesLeft := maxRetries
for retriesLeft > 0 {
- if ap.ctr.remoteRegsCnt == 0 {- return false, moerr.NewInternalError(proc.Ctx,- "sendToAny failed: all remote receivers are unavailable")- }
Apply / Chat
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a potential panic due to a division-by-zero error if all remote receivers are removed during the loop's execution. Moving the check for ap.ctr.remoteRegsCnt == 0 before the loop is a critical fix to prevent a crash.
High
General
Remove unreachable error handling code
Remove an unreachable if remove block in sendBatToIndex, as the condition it checks is already handled by a preceding error check.
-if remove {- // In shuffle scenario, if target receiver is removed, it's a critical error- err = moerr.NewInternalError(proc.Ctx, fmt.Sprintf(- "shuffle target receiver %s was removed, data loss may occur", receiverID))- break-}+// This block is unreachable with FailureModeStrict and can be removed.+// The `if errSend != nil` check above handles this case.
Apply / Chat
Suggestion importance[1-10]: 4
__
Why: The suggestion correctly identifies that the if remove block is unreachable because sendBatchToClientSession in FailureModeStrict returns an error when remove is true, which is caught by the preceding if errSend != nil check. Removing this dead code improves code clarity 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 #22750 #22727
What this PR does / why we need it:
Problem
When a remote CN becomes unavailable (
ReceiverDone=true), data destined for that CN was silently dropped without error in SendToAll/Shuffle scenarios, leading to incomplete query results.Solution
Introduce
receiverFailureModeto distinguish between scenarios:PR Type
Bug fix, Tests
Description
Prevent silent data loss when remote CN becomes unavailable in SendToAll/Shuffle scenarios
Introduce
receiverFailureModeto distinguish strict vs tolerant failure handlingAdd comprehensive integration tests documenting the data loss bug and fix
Return explicit errors in strict mode when receiver is done, protecting data integrity
Diagram Walkthrough
flowchart LR A["Remote CN Unavailable<br/>ReceiverDone=true"] --> B{"Failure Mode?"} B -->|FailureModeStrict| C["SendToAll/Shuffle<br/>Return Error"] B -->|FailureModeTolerant| D["SendToAny<br/>Failover to Other"] C --> E["Query Fails<br/>Data Protected"] D --> F["Try Next Receiver<br/>Graceful Degradation"]File Walkthrough
data_loss_integration_test.go
Integration tests for silent data loss preventionpkg/sql/colexec/dispatch/data_loss_integration_test.go
loss bug
scan, shuffle join, GROUP BY aggregation)
integrity protection
fix effectiveness
dispatch_test.go
Unit tests for failure mode handling and data loss preventionpkg/sql/colexec/dispatch/dispatch_test.go
TestReceiverDonetoTestReceiverDone_OldBehaviorfor clarityreceiver is done
sendBatchToClientSessionwith both strict andtolerant modes
receiver failures
and after fix
sendfunc.go
Implement failure mode handling and data loss prevention logicpkg/sql/colexec/dispatch/sendfunc.go
receiverFailureModeenum withFailureModeStrictandFailureModeTolerantconstantssendBatchToClientSessionsignature to acceptfailureModeandreceiverIDparametersReceiverDone=true, return error instrict mode to prevent silent data loss
sendToAllRemoteFuncto useFailureModeStrictfor datacompleteness
sendBatToIndexandsendBatToMultiMatchedRegto useFailureModeStrictfor shuffle scenariossendToAnyRemoteFuncto useFailureModeTolerantallowingfailover to other receivers
identifiers