Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv,storage: add support for child transactions #56588

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
roachpb: add AncestorAbortedError
Adds an error to deal with the case where a child detects that an ancestor
is aborted. We can then turn this into a restart error for the appropriate
ancestor and abort all of the other relevant descendents of that ancestor.

Release note: None
  • Loading branch information
ajwerner committed Mar 27, 2023
commit 4ffdd7eb4b25a78c21d1549f61e1a38c2768428f
4 changes: 4 additions & 0 deletions pkg/kv/kvpb/batch_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkg/kv/kvpb/errordetailtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion pkg/kv/kvpb/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ const (
MinTimestampBoundUnsatisfiableErrType ErrorDetailType = 42
RefreshFailedErrType ErrorDetailType = 43
MVCCHistoryMutationErrType ErrorDetailType = 44
AncestorAbortedErrType ErrorDetailType = 45
// When adding new error types, don't forget to update NumErrors below.

// CommunicationErrType indicates a gRPC error; this is not an ErrorDetail.
Expand All @@ -304,7 +305,7 @@ const (
// detail. The value 25 is chosen because it's reserved in the errors proto.
InternalErrType ErrorDetailType = 25

NumErrors int = 45
NumErrors int = 46
)

// Register the migration of all errors that used to be in the roachpb package
Expand Down Expand Up @@ -1536,6 +1537,19 @@ func NewNotLeaseHolderErrorWithSpeculativeLease(
return NewNotLeaseHolderError(speculativeLease, proposerStoreID, rangeDesc, msg)
}

func (e *AncestorAbortedError) Type() ErrorDetailType {
return AncestorAbortedErrType
}

func (e *AncestorAbortedError) Error() string {
return redact.Sprint(e).StripMarkers()
}

func (e *AncestorAbortedError) SafeFormatError(p errors.Printer) (next error) {
p.Printf("ancestor transaction %v aborted", e.AncestorTxn)
return nil
}

var _ errors.SafeFormatter = &NotLeaseHolderError{}
var _ errors.SafeFormatter = &RangeNotFoundError{}
var _ errors.SafeFormatter = &RangeKeyMismatchError{}
Expand Down Expand Up @@ -1570,3 +1584,4 @@ var _ errors.SafeFormatter = &MinTimestampBoundUnsatisfiableError{}
var _ errors.SafeFormatter = &RefreshFailedError{}
var _ errors.SafeFormatter = &MVCCHistoryMutationError{}
var _ errors.SafeFormatter = &UnhandledRetryableError{}
var _ errors.SafeFormatter = &AncestorAbortedError{}
11 changes: 11 additions & 0 deletions pkg/kv/kvpb/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@ message RefreshFailedError {
optional util.hlc.Timestamp timestamp = 3 [(gogoproto.nullable) = false];
}

// AncestorAbortedError indicates that the parent transaction of a child has been
// aborted while the child is waiting to push another transaction. There is no
// reason for the child to proceed if the parent is already aborted. We cannot
// just use a TransactionAbortedError as the TxnCoordSender would translate
// that into a TransactionRetryWithProtoRefreshError which is not the desired
// behavior.
message AncestorAbortedError {
optional roachpb.Transaction ancestor_txn = 1 [(gogoproto.nullable) = false];
}

// ErrorDetail is a union type containing all available errors.
message ErrorDetail {
reserved 15, 19, 20, 21, 22, 23, 24, 25, 29, 30, 33;
Expand Down Expand Up @@ -661,6 +671,7 @@ message ErrorDetail {
RefreshFailedError refresh_failed_error = 43;
MVCCHistoryMutationError mvcc_history_mutation = 44
[(gogoproto.customname) = "MVCCHistoryMutation"];
AncestorAbortedError ancestor_aborted = 45;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ts/catalog/chart_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ var charts = []sectionDescription{
Title: "Errors",
Metrics: []string{
"distsender.rpc.err.ambiguousresulterrtype",
"distsender.rpc.err.ancestorabortederrtype",
"distsender.rpc.err.batchtimestampbeforegcerrtype",
"distsender.rpc.err.communicationerrtype",
"distsender.rpc.err.conditionfailederrtype",
Expand Down Expand Up @@ -479,7 +480,6 @@ var charts = []sectionDescription{
"distsender.rpc.err.unsupportedrequesterrtype",
"distsender.rpc.err.writeintenterrtype",
"distsender.rpc.err.writetooolderrtype",
"distsender.rpc.err.ancestorabortederrtype",
},
},
},
Expand Down