Skip to content

Commit

Permalink
fix: return and respect cursor errors (#24791)
Browse files Browse the repository at this point in the history
ArrayCursors were ignoring errors, which led to panics when nil
cursors were operated on. This fix passes errors back up the stack
and uses them to enforce healthy cursor creation.

Closes #24789
---------
Co-authored-by: Stuart Carnie <[email protected]>
  • Loading branch information
davidby-influx authored Mar 26, 2024
1 parent 8ff06d5 commit fe6c64b
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 95 deletions.
7 changes: 4 additions & 3 deletions cmd/influx_tools/internal/storage/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ func (ci *CursorIterator) Next() bool {
}

var shard tsdb.CursorIterator
var err error
ci.cur = nil
for ci.cur == nil && len(ci.itrs) > 0 {
for ci.cur == nil && len(ci.itrs) > 0 && err == nil {
shard, ci.itrs = ci.itrs[0], ci.itrs[1:]
ci.cur, _ = shard.Next(ci.ctx, &ci.req)
ci.cur, err = shard.Next(ci.ctx, &ci.req)
}

return ci.cur != nil
return ci.cur != nil && err == nil
}

func (ci *CursorIterator) Cursor() tsdb.Cursor {
Expand Down
40 changes: 25 additions & 15 deletions storage/reads/array_cursor.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,15 @@ func (c *floatMultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.FloatArrayCursor
next, ok = cur.(cursors.FloatArrayCursor)
if !ok {
Expand Down Expand Up @@ -1340,13 +1342,15 @@ func (c *integerMultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.IntegerArrayCursor
next, ok = cur.(cursors.IntegerArrayCursor)
if !ok {
Expand Down Expand Up @@ -2345,13 +2349,15 @@ func (c *unsignedMultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.UnsignedArrayCursor
next, ok = cur.(cursors.UnsignedArrayCursor)
if !ok {
Expand Down Expand Up @@ -3350,13 +3356,15 @@ func (c *stringMultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.StringArrayCursor
next, ok = cur.(cursors.StringArrayCursor)
if !ok {
Expand Down Expand Up @@ -3777,13 +3785,15 @@ func (c *booleanMultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.BooleanArrayCursor
next, ok = cur.(cursors.BooleanArrayCursor)
if !ok {
Expand Down
8 changes: 5 additions & 3 deletions storage/reads/array_cursor.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,15 @@ func (c *{{.name}}MultiShardArrayCursor) nextArrayCursor() bool {

var itr cursors.CursorIterator
var cur cursors.Cursor
for cur == nil && len(c.itrs) > 0 {
var err error
for cur == nil && len(c.itrs) > 0 && err == nil {
itr, c.itrs = c.itrs[0], c.itrs[1:]
cur, _ = itr.Next(c.ctx, c.req)
cur, err = itr.Next(c.ctx, c.req)
}

c.err = err
var ok bool
if cur != nil {
if cur != nil && err == nil {
var next cursors.{{.Name}}ArrayCursor
next, ok = cur.(cursors.{{.Name}}ArrayCursor)
if !ok {
Expand Down
5 changes: 3 additions & 2 deletions storage/reads/array_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ func (m *multiShardArrayCursors) createCursor(row SeriesRow) cursors.Cursor {

var shard cursors.CursorIterator
var cur cursors.Cursor
var err error
for cur == nil && len(row.Query) > 0 {
shard, row.Query = row.Query[0], row.Query[1:]
cur, _ = shard.Next(m.ctx, &m.req)
cur, err = shard.Next(m.ctx, &m.req)
}

if cur == nil {
if cur == nil || err != nil {
return nil
}

Expand Down
Loading

0 comments on commit fe6c64b

Please sign in to comment.