Skip to content

Commit b1885ba

Browse files
authored
Merge pull request #774 from ydb-platform/tli
* Added `yd.IsTransactionLocksInvalidated(err)` helper for checks `TL…
2 parents 3958d05 + 708e0c1 commit b1885ba

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added `ydb.IsOperationErrorTransactionLocksInvalidated(err)` helper for checks `TLI` flag in err
2+
13
## v3.48.3
24
* Added `table/types.IsOptional()` helper
35

errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func IsOperationErrorSchemeError(err error) bool {
8282
return IsOperationError(err, Ydb.StatusIds_SCHEME_ERROR)
8383
}
8484

85+
// IsOperationErrorTransactionLocksInvalidated checks does err a TLI issue
86+
func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) {
87+
return xerrors.IsOperationErrorTransactionLocksInvalidated(err)
88+
}
89+
8590
// IsRatelimiterAcquireError checks whether given err is an ratelimiter acquire error
8691
func IsRatelimiterAcquireError(err error) bool {
8792
return ratelimiterErrors.IsAcquireError(err)

internal/xerrors/operation.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ func IsOperationError(err error, codes ...Ydb.StatusIds_StatusCode) bool {
118118
return false
119119
}
120120

121+
const issueCodeTransactionLocksInvalidated = 2001
122+
123+
func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) {
124+
if IsOperationError(err, Ydb.StatusIds_ABORTED) {
125+
IterateByIssues(err, func(_ string, code Ydb.StatusIds_StatusCode, severity uint32) {
126+
isTLI = isTLI || (code == issueCodeTransactionLocksInvalidated)
127+
})
128+
}
129+
return isTLI
130+
}
131+
121132
func (e *operationError) Type() Type {
122133
switch e.code {
123134
case

internal/xerrors/operation_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,53 @@ func TestIsOperationError(t *testing.T) {
2828
}
2929
}
3030

31+
func TestIsOperationErrorTransactionLocksInvalidated(t *testing.T) {
32+
for _, tt := range [...]struct {
33+
err error
34+
isTLI bool
35+
}{
36+
{
37+
err: Operation(
38+
WithStatusCode(Ydb.StatusIds_ABORTED),
39+
WithIssues([]*Ydb_Issue.IssueMessage{{
40+
IssueCode: issueCodeTransactionLocksInvalidated,
41+
}}),
42+
),
43+
isTLI: true,
44+
},
45+
{
46+
err: Operation(
47+
WithStatusCode(Ydb.StatusIds_OVERLOADED),
48+
WithIssues([]*Ydb_Issue.IssueMessage{{
49+
IssueCode: issueCodeTransactionLocksInvalidated,
50+
}}),
51+
),
52+
isTLI: false,
53+
},
54+
{
55+
err: Operation(
56+
WithStatusCode(Ydb.StatusIds_ABORTED),
57+
),
58+
isTLI: false,
59+
},
60+
{
61+
err: Operation(
62+
WithStatusCode(Ydb.StatusIds_ABORTED),
63+
WithIssues([]*Ydb_Issue.IssueMessage{{
64+
Issues: []*Ydb_Issue.IssueMessage{{
65+
IssueCode: issueCodeTransactionLocksInvalidated,
66+
}},
67+
}}),
68+
),
69+
isTLI: true,
70+
},
71+
} {
72+
t.Run("", func(t *testing.T) {
73+
require.Equal(t, tt.isTLI, IsOperationErrorTransactionLocksInvalidated(tt.err))
74+
})
75+
}
76+
}
77+
3178
func Test_operationError_Error(t *testing.T) {
3279
for _, tt := range []struct {
3380
err error

0 commit comments

Comments
 (0)