satellite/dbx: add cockroach retries for other QueryContext operations

Change-Id: Ia30fbba55c926892702fa96fb9dd01b75347d351
This commit is contained in:
JT Olio 2020-11-29 13:53:09 -07:00
parent ea2f39ca7f
commit bd23d12bb9
7 changed files with 2303 additions and 1279 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,11 @@ All_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
for {
rows, err = func() (rows {{ sliceof .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
defer __rows.Close()
@ -27,12 +29,21 @@ All_{{ .Suffix }}({{ ctxarg .Args }})
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
rows = append(rows, {{ arg .Row }})
}
if err := __rows.Err(); err != nil {
return nil, err
}
return rows, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
return nil, obj.makeErr(err)
}
return rows, nil
}
{{ end -}}

View File

@ -17,15 +17,17 @@ First_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
for {
{{ arg .Row }}, err := func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return nil, nil
}
@ -33,8 +35,17 @@ First_{{ .Suffix }}({{ ctxarg .Args }})
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return {{ arg .Row }}, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
return nil, obj.makeErr(err)
}
return {{ arg .Row }}, nil
}
{{ end -}}

View File

@ -20,9 +20,11 @@ Limited_{{ .Suffix }}({{ ctxarg .Args }}, limit, offset)
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
for {
rows, err := func() (rows {{ sliceof .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
defer __rows.Close()
@ -30,12 +32,22 @@ Limited_{{ .Suffix }}({{ ctxarg .Args }}, limit, offset)
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
rows = append(rows, {{ arg .Row }})
}
if err := __rows.Err(); err != nil {
err = __rows.Err()
if err != nil {
return nil, err
}
return rows, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
return nil, obj.makeErr(err)
}
return rows, nil
}
{{ end -}}

View File

@ -17,32 +17,46 @@ Get_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
for {
{{ arg .Row }}, err = func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return nil, makeErr(sql.ErrNoRows)
return nil, sql.ErrNoRows
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
if __rows.Next() {
return nil, tooManyRows({{ printf "%q" .Suffix }})
return nil, errTooManyRows
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return {{ arg .Row }}, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
if err == errTooManyRows {
return nil, tooManyRows({{ printf "%q" .Suffix }})
}
return nil, obj.makeErr(err)
}
return {{ arg .Row }}, nil
}
{{ end -}}

View File

@ -26,9 +26,11 @@ Paged_{{ .Suffix }}({{ ctxarg .Args }}, limit, start)
}
obj.logStmt(__stmt, __values...)
for {
rows, next, err = func() (rows {{ sliceof .Row }}, next *{{ .Continuation.Type }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, nil, obj.makeErr(err)
return nil, nil, err
}
defer __rows.Close()
@ -39,14 +41,24 @@ Paged_{{ .Suffix }}({{ ctxarg .Args }}, limit, start)
{{ initnew .Row }}
err = __rows.Scan({{ .Row | flatten | addrof | comma }}{{ .Continuation | flatten | slice 0 -1 | addrof }})
if err != nil {
return nil, nil, obj.makeErr(err)
return nil, nil, err
}
rows = append(rows, {{ arg .Row }})
next = {{ addrof .Continuation }}
}
if err := __rows.Err(); err != nil {
return nil, nil, obj.makeErr(err)
return nil, nil, err
}
return rows, next, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
return nil, nil, obj.makeErr(err)
}
return rows, next, nil
}
{{ end -}}

View File

@ -17,15 +17,17 @@ Find_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
for {
{{ arg .Row }}, err = func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return nil, nil
}
@ -33,16 +35,28 @@ Find_{{ .Suffix }}({{ ctxarg .Args }})
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
return nil, err
}
if __rows.Next() {
return nil, tooManyRows({{ printf "%q" .Suffix }})
return nil, errTooManyRows
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
return nil, err
}
return {{ arg .Row }}, nil
}()
if err != nil {
if obj.shouldRetry(err) {
continue
}
if err == errTooManyRows {
return nil, tooManyRows({{ printf "%q" .Suffix }})
}
return nil, obj.makeErr(err)
}
return {{ arg .Row }}, nil
}
{{ end -}}