-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bigtable): Track number of readrows to set rowsLimit in subsequent requests #10213
base: main
Are you sure you want to change the base?
Changes from all commits
ab8b94a
cc7d220
cd50e9d
1a21f06
26cd101
0f7ac71
bc08882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,7 +391,21 @@ func (t *Table) ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts | |
func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt *builtinMetricsTracer, opts ...ReadOption) (err error) { | ||
var prevRowKey string | ||
attrMap := make(map[string]interface{}) | ||
|
||
numRowsRead := int64(0) | ||
rowLimitSet := false | ||
intialRowLimit := int64(0) | ||
for _, opt := range opts { | ||
if l, ok := opt.(limitRows); ok { | ||
rowLimitSet = true | ||
intialRowLimit = l.limit | ||
} | ||
} | ||
err = gaxInvokeWithRecorder(ctx, mt, "ReadRows", func(ctx context.Context, headerMD, trailerMD *metadata.MD, _ gax.CallSettings) error { | ||
if rowLimitSet && numRowsRead == intialRowLimit { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a safety check in case |
||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the number of rows requested ( If so, can we add a test with this scenario? (e.g. a table with 2 rows and set |
||
} | ||
|
||
req := &btpb.ReadRowsRequest{ | ||
AppProfileId: t.c.appProfile, | ||
} | ||
|
@@ -410,7 +424,7 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt * | |
} | ||
req.Rows = arg.proto() | ||
} | ||
settings := makeReadSettings(req) | ||
settings := makeReadSettings(req, numRowsRead) | ||
for _, opt := range opts { | ||
mutianf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
opt.set(&settings) | ||
} | ||
|
@@ -473,7 +487,9 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt * | |
continue | ||
} | ||
prevRowKey = row.Key() | ||
if !f(row) { | ||
continueReading := f(row) | ||
numRowsRead++ | ||
if !continueReading { | ||
// Cancel and drain stream. | ||
cancel() | ||
for { | ||
|
@@ -939,10 +955,11 @@ type FullReadStatsFunc func(*FullReadStats) | |
type readSettings struct { | ||
req *btpb.ReadRowsRequest | ||
fullReadStatsFunc FullReadStatsFunc | ||
numRowsRead int64 | ||
} | ||
|
||
func makeReadSettings(req *btpb.ReadRowsRequest) readSettings { | ||
return readSettings{req, nil} | ||
func makeReadSettings(req *btpb.ReadRowsRequest, numRowsRead int64) readSettings { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: it took me a while to understand how |
||
return readSettings{req, nil, numRowsRead} | ||
} | ||
|
||
// A ReadOption is an optional argument to ReadRows. | ||
|
@@ -965,7 +982,9 @@ func LimitRows(limit int64) ReadOption { return limitRows{limit} } | |
|
||
type limitRows struct{ limit int64 } | ||
|
||
func (lr limitRows) set(settings *readSettings) { settings.req.RowsLimit = lr.limit } | ||
func (lr limitRows) set(settings *readSettings) { | ||
settings.req.RowsLimit = lr.limit - settings.numRowsRead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment explaining the reasoning for this subtraction |
||
} | ||
|
||
// WithFullReadStats returns a ReadOption that will request FullReadStats | ||
// and invoke the given callback on the resulting FullReadStats. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe fail fast on
l.limit < 0