forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changefeedccl: switch high-level retry marker from whitelist to black…
…list In the roachtests for crdb-chaos and sink-chaos we're seeing changefeeds fail with surprising errors: [NotLeaseHolderError] r681: replica (n1,s1):1 not lease holder; replica (n2,s2):2 is descriptor not found We'd like to avoid failing a changefeed unnecessarily, so when an error bubbles up to the top level, we'd like to retry the distributed flow if possible. We initially tried to whitelist which errors should cause the changefeed to retry, but this turns out to be brittle, so this commit switches to a blacklist. Any error that is expected to be permanent is now marked with `MarkTerminalError` by the time it comes out of `distChangefeedFlow`. Everything else should be logged loudly and retried. Touches cockroachdb#35974 Touches cockroachdb#36019 Release note: None
- Loading branch information
Showing
10 changed files
with
170 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package changefeedccl | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" | ||
) | ||
|
||
const terminalErrorString = "terminal changefeed error" | ||
|
||
type terminalError struct { | ||
wrapped error | ||
} | ||
|
||
// MarkTerminalError wraps the given error, marking it as non-retryable to | ||
// changefeeds. | ||
func MarkTerminalError(e error) error { | ||
return &terminalError{wrapped: e} | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e *terminalError) Error() string { | ||
return fmt.Sprintf("%s: %s", terminalErrorString, e.wrapped.Error()) | ||
} | ||
|
||
// Unwrap implements the github.com/golang/xerrors.Wrapper interface, which is | ||
// planned to be moved to the stdlib in go 1.13. | ||
func (e *terminalError) Unwrap() error { return e.wrapped } | ||
|
||
// IsTerminalError returns true if the supplied error, or any of its parent | ||
// causes, is a IsTerminalError. | ||
func IsTerminalError(err error) bool { | ||
for { | ||
if err == nil { | ||
return false | ||
} | ||
if _, ok := err.(*terminalError); ok { | ||
return true | ||
} | ||
if _, ok := err.(*pgerror.Error); ok { | ||
return strings.Contains(err.Error(), terminalErrorString) | ||
} | ||
if e, ok := err.(interface{ Unwrap() error }); ok { | ||
err = e.Unwrap() | ||
continue | ||
} | ||
return false | ||
} | ||
} | ||
|
||
// MaybeStripTerminalErrorMarker performs some minimal attempt to clean the | ||
// TerminalError marker out. This won't do anything if the TerminalError itself | ||
// has been wrapped, but that's okay, we'll just have an uglier string. | ||
func MaybeStripTerminalErrorMarker(err error) error { | ||
if e, ok := err.(*terminalError); ok { | ||
err = e.wrapped | ||
} | ||
return err | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.