Skip to content

Commit 11cfae5

Browse files
committed
* Changed type of truncated result error from StreamExecuteScanQuery to retryable error
1 parent 510ab4b commit 11cfae5

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Marked the truncated result as retryable error
1+
* Changed type of truncated result error from `StreamExecuteScanQuery` to retryable error
22
* Added closing sessions if node removed from discovery results
33
* Moved session status type from `table/options` package to `table`
44
* Changed session status source type from `uint32` to `string` alias

MIGRATION_v2_v3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@
146146

147147
## About truncated result <a name="truncated"></a>
148148

149-
Call of `session.Execute` may returns a result with a flag `Truncated` because `YDB` have a default limit of rows is a 1000.
150-
In this case query must be changed for supporting pagination. Trucated flag in result must be checks explicitly.
149+
Call of `session.Execute` may return a result with a flag `Truncated` because `YDB` have a default limit of rows is a 1000.
150+
In this case query must be changed for supporting pagination. Truncated flag in result must be checks explicitly.
151151
- in `v2`:
152152
```go
153153
var res *table.Result
@@ -178,7 +178,7 @@ In this case query must be changed for supporting pagination. Trucated flag in r
178178
}
179179
```
180180
- in `v3`:
181-
By default, truncated result wraps as non-retryable error
181+
By default, truncated result wraps as non-retryable error for `session.Execute` and retryable error for `session.StreamExecuteScanQuery`
182182
```go
183183
import (
184184
"github.com/ydb-platform/ydb-go-sdk/v3/table/result"

internal/table/scanner/result.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func WithIgnoreTruncated(ignoreTruncated bool) option {
7878
}
7979
}
8080

81+
func WithMarkTruncatedAsRetryable() option {
82+
return func(r *baseResult) {
83+
r.scanner.markTruncatedAsRetryable = true
84+
}
85+
}
86+
8187
func NewStream(
8288
recv func(ctx context.Context) (*Ydb.ResultSet, *Ydb_TableStats.QueryStats, error),
8389
onClose func(error) error,

internal/table/scanner/scanner.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ import (
2323
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
2424
)
2525

26-
var errTruncated = xerrors.Retryable(errors.New("truncated result"))
26+
var errTruncated = xerrors.Wrap(errors.New("truncated result"))
2727

2828
type scanner struct {
29-
set *Ydb.ResultSet
30-
row *Ydb.Value
31-
converter *rawConverter
32-
stack scanStack
33-
nextRow int
34-
nextItem int
35-
ignoreTruncated bool
29+
set *Ydb.ResultSet
30+
row *Ydb.Value
31+
converter *rawConverter
32+
stack scanStack
33+
nextRow int
34+
nextItem int
35+
ignoreTruncated bool
36+
markTruncatedAsRetryable bool
3637

3738
columnIndexes []int
3839

@@ -226,6 +227,9 @@ func (s *scanner) Err() error {
226227
return s.err
227228
}
228229
if !s.ignoreTruncated && s.truncated() {
230+
if s.markTruncatedAsRetryable {
231+
return xerrors.WithStackTrace(xerrors.Retryable(errTruncated))
232+
}
229233
return xerrors.WithStackTrace(errTruncated)
230234
}
231235
return nil

internal/table/session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ func (s *session) StreamExecuteScanQuery(
10841084
return err
10851085
},
10861086
scanner.WithIgnoreTruncated(s.config.IgnoreTruncated()),
1087+
scanner.WithMarkTruncatedAsRetryable(),
10871088
), nil
10881089
}
10891090

0 commit comments

Comments
 (0)