Skip to content

Commit d3a526e

Browse files
committed
simplify check err is IsRetryable
1 parent a8fdd47 commit d3a526e

1 file changed

Lines changed: 13 additions & 110 deletions

File tree

pkg/util/xorm/dialect_ydb.go

Lines changed: 13 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ type inArgMap struct {
392392
}
393393

394394
type inArgSegment struct {
395-
singleIdx int // if listCount == 0: use args[singleIdx]
396-
listStart int // if listCount > 0: use args[listStart:listStart+listCount] as one list arg
397-
listCount int
395+
singleIdx int // if listCount == 0: use args[singleIdx]
396+
listStart int // if listCount > 0: use args[listStart:listStart+listCount] as one list arg
397+
listCount int
398398
}
399399

400400
const inClauseCollapseThreshold = 50 // collapse IN (?,...,?) into IN ? (single list param) when param count >= this
@@ -426,11 +426,15 @@ func rewriteQueryInClausesNumeric(query string) (newQuery string, argMap *inArgM
426426
i := 0
427427
for i < len(query) {
428428
j := i
429-
for j < len(query) && isSpace(query[j]) { j++ }
429+
for j < len(query) && isSpace(query[j]) {
430+
j++
431+
}
430432
// Match "IN" (word boundary) then optional whitespace then "(" (so " IN (", " IN\n(", "IN(")
431433
if j+2 <= len(query) && (j == 0 || !isWordChar(query[j-1])) && strings.EqualFold(query[j:j+2], "in") {
432434
k := j + 2
433-
for k < len(query) && isSpace(query[k]) { k++ }
435+
for k < len(query) && isSpace(query[k]) {
436+
k++
437+
}
434438
if k < len(query) && query[k] == '(' {
435439
parenStart := k
436440
parenEnd := findMatchingParen(query, parenStart)
@@ -573,7 +577,9 @@ func rewriteQueryInClausesQuestion(query string) (newQuery string, argMap *inArg
573577
for i < len(query) {
574578
if (i == 0 || !isWordChar(query[i-1])) && i+4 <= len(query) {
575579
j := i
576-
for j < len(query) && isSpace(query[j]) { j++ }
580+
for j < len(query) && isSpace(query[j]) {
581+
j++
582+
}
577583
if j+4 <= len(query) && strings.EqualFold(query[j:j+4], "in (") {
578584
parenStart := j + 3
579585
parenEnd := findMatchingParen(query, parenStart)
@@ -1834,111 +1840,8 @@ func (db *ydbDialect) Filters() []core.Filter {
18341840
return []core.Filter{&core.IdFilter{}, &core.SeqFilter{Prefix: "$", Start: 1}}
18351841
}
18361842

1837-
const (
1838-
ydb_grpc_Canceled uint32 = 1
1839-
ydb_grpc_Unknown uint32 = 2
1840-
ydb_grpc_InvalidArgument uint32 = 3
1841-
ydb_grpc_DeadlineExceeded uint32 = 4
1842-
ydb_grpc_NotFound uint32 = 5
1843-
ydb_grpc_AlreadyExists uint32 = 6
1844-
ydb_grpc_PermissionDenied uint32 = 7
1845-
ydb_grpc_ResourceExhausted uint32 = 8
1846-
ydb_grpc_FailedPrecondition uint32 = 9
1847-
ydb_grpc_Aborted uint32 = 10
1848-
ydb_grpc_OutOfRange uint32 = 11
1849-
ydb_grpc_Unimplemented uint32 = 12
1850-
ydb_grpc_Internal uint32 = 13
1851-
ydb_grpc_Unavailable uint32 = 14
1852-
ydb_grpc_DataLoss uint32 = 15
1853-
ydb_grpc_Unauthenticated uint32 = 16
1854-
)
1855-
1856-
const (
1857-
ydb_STATUS_CODE_UNSPECIFIED int32 = 0
1858-
ydb_SUCCESS int32 = 400000
1859-
ydb_BAD_REQUEST int32 = 400010
1860-
ydb_UNAUTHORIZED int32 = 400020
1861-
ydb_INTERNAL_ERROR int32 = 400030
1862-
ydb_ABORTED int32 = 400040
1863-
ydb_UNAVAILABLE int32 = 400050
1864-
ydb_OVERLOADED int32 = 400060
1865-
ydb_SCHEME_ERROR int32 = 400070
1866-
ydb_GENERIC_ERROR int32 = 400080
1867-
ydb_TIMEOUT int32 = 400090
1868-
ydb_BAD_SESSION int32 = 400100
1869-
ydb_PRECONDITION_FAILED int32 = 400120
1870-
ydb_ALREADY_EXISTS int32 = 400130
1871-
ydb_NOT_FOUND int32 = 400140
1872-
ydb_SESSION_EXPIRED int32 = 400150
1873-
ydb_CANCELLED int32 = 400160
1874-
ydb_UNDETERMINED int32 = 400170
1875-
ydb_UNSUPPORTED int32 = 400180
1876-
ydb_SESSION_BUSY int32 = 400190
1877-
)
1878-
1879-
// https://github.com/ydb-platform/ydb-go-sdk/blob/ca13feb3ca560ac7385e79d4365ffe0cd8c23e21/errors.go#L27
18801843
func (db *ydbDialect) IsRetryable(err error) bool {
1881-
var target interface {
1882-
error
1883-
Code() int32
1884-
Name() string
1885-
}
1886-
if errors.Is(err, fmt.Errorf("unknown error")) ||
1887-
errors.Is(err, context.DeadlineExceeded) ||
1888-
errors.Is(err, context.Canceled) {
1889-
return false
1890-
}
1891-
if !errors.As(err, &target) {
1892-
return false
1893-
}
1894-
1895-
switch target.Code() {
1896-
case
1897-
int32(ydb_grpc_Unknown),
1898-
int32(ydb_grpc_InvalidArgument),
1899-
int32(ydb_grpc_DeadlineExceeded),
1900-
int32(ydb_grpc_NotFound),
1901-
int32(ydb_grpc_AlreadyExists),
1902-
int32(ydb_grpc_PermissionDenied),
1903-
int32(ydb_grpc_FailedPrecondition),
1904-
int32(ydb_grpc_OutOfRange),
1905-
int32(ydb_grpc_Unimplemented),
1906-
int32(ydb_grpc_DataLoss),
1907-
int32(ydb_grpc_Unauthenticated):
1908-
return false
1909-
case
1910-
int32(ydb_grpc_Canceled),
1911-
int32(ydb_grpc_ResourceExhausted),
1912-
int32(ydb_grpc_Aborted),
1913-
int32(ydb_grpc_Internal),
1914-
int32(ydb_grpc_Unavailable):
1915-
return true
1916-
case
1917-
ydb_STATUS_CODE_UNSPECIFIED,
1918-
ydb_BAD_REQUEST,
1919-
ydb_UNAUTHORIZED,
1920-
ydb_INTERNAL_ERROR,
1921-
ydb_SCHEME_ERROR,
1922-
ydb_GENERIC_ERROR,
1923-
ydb_TIMEOUT,
1924-
ydb_PRECONDITION_FAILED,
1925-
ydb_ALREADY_EXISTS,
1926-
ydb_NOT_FOUND,
1927-
ydb_SESSION_EXPIRED,
1928-
ydb_CANCELLED,
1929-
ydb_UNSUPPORTED:
1930-
return false
1931-
case
1932-
ydb_ABORTED,
1933-
ydb_UNAVAILABLE,
1934-
ydb_OVERLOADED,
1935-
ydb_BAD_SESSION,
1936-
ydb_UNDETERMINED,
1937-
ydb_SESSION_BUSY:
1938-
return true
1939-
default:
1940-
return false
1941-
}
1844+
return retry.Check(err).MustRetry(false)
19421845
}
19431846

19441847
type ydbDriver struct {

0 commit comments

Comments
 (0)