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,22 +17,33 @@ All_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for {
rows, err = func() (rows {{ sliceof .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, err
}
defer __rows.Close()
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
}
rows = append(rows, {{ arg .Row }})
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return rows, nil
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
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,24 +17,35 @@ First_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for {
{{ arg .Row }}, err := func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return nil, nil
}
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, err
}
return nil, nil
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, err
}
return {{ arg .Row }}, nil
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,22 +20,34 @@ Limited_{{ .Suffix }}({{ ctxarg .Args }}, limit, offset)
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for {
rows, err := func() (rows {{ sliceof .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, err
}
defer __rows.Close()
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
}
rows = append(rows, {{ arg .Row }})
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return rows, nil
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, err
}
rows = append(rows, {{ arg .Row }})
}
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...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for {
{{ arg .Row }}, err = func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return nil, makeErr(sql.ErrNoRows)
}
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, err
}
return nil, sql.ErrNoRows
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, err
}
if __rows.Next() {
return nil, tooManyRows({{ printf "%q" .Suffix }})
}
if __rows.Next() {
return nil, errTooManyRows
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
if err := __rows.Err(); err != nil {
return nil, err
}
return {{ arg .Row }}, nil
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,27 +26,39 @@ Paged_{{ .Suffix }}({{ ctxarg .Args }}, limit, start)
}
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, nil, obj.makeErr(err)
}
defer __rows.Close()
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, err
}
defer __rows.Close()
{{ declare .Continuation }}
{{ .Continuation.Name }}._set = true
{{ declare .Continuation }}
{{ .Continuation.Name }}._set = true
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ .Row | flatten | addrof | comma }}{{ .Continuation | flatten | slice 0 -1 | addrof }})
if err != nil {
return nil, nil, obj.makeErr(err)
}
rows = append(rows, {{ arg .Row }})
next = {{ addrof .Continuation }}
}
if err := __rows.Err(); err != nil {
return nil, nil, obj.makeErr(err)
}
for __rows.Next() {
{{ initnew .Row }}
err = __rows.Scan({{ .Row | flatten | addrof | comma }}{{ .Continuation | flatten | slice 0 -1 | addrof }})
if err != nil {
return nil, nil, err
}
rows = append(rows, {{ arg .Row }})
next = {{ addrof .Continuation }}
}
return rows, next, nil
if err := __rows.Err(); err != nil {
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,32 +17,46 @@ Find_{{ .Suffix }}({{ ctxarg .Args }})
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for {
{{ arg .Row }}, err = func() ({{ param .Row }}, err error) {
__rows, err := obj.driver.QueryContext(ctx, __stmt, __values...)
if err != nil {
return nil, err
}
defer __rows.Close()
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return nil, nil
}
if !__rows.Next() {
if err := __rows.Err(); err != nil {
return nil, err
}
return nil, nil
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, obj.makeErr(err)
}
{{ init .Row }}
err = __rows.Scan({{ addrof (flatten .Row) }})
if err != nil {
return nil, err
}
if __rows.Next() {
return nil, tooManyRows({{ printf "%q" .Suffix }})
}
if __rows.Next() {
return nil, errTooManyRows
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
if err := __rows.Err(); err != nil {
return nil, err
}
return {{ arg .Row }}, nil
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 -}}