Fix panic: runtime error: index out of range

There was a fix in 5b1791, but is not present in the current branch likely due to a rebase issue.
The current code panics with a query like:

select value from cpu group by host order by time desc limit 1

This fixes the panic as well as prevents #5193 from re-occurring.  The issue is that agressively
closing the cursors clears out the seeks slice so re-seeking will fail.
pull/5623/head
Jason Wilder 2016-02-10 14:00:58 -07:00
parent 2f1e83427b
commit 0ce6dd1304
3 changed files with 6 additions and 23 deletions

View File

@ -30,7 +30,7 @@ import (
"github.com/influxdata/influxdb/services/udp"
"github.com/influxdata/influxdb/tcp"
"github.com/influxdata/influxdb/tsdb"
client "github.com/influxdb/usage-client/v1"
client "github.com/influxdata/usage-client/v1"
// Initialize the engine packages
_ "github.com/influxdata/influxdb/tsdb/engine"
)

View File

@ -1,5 +1,8 @@
// Generated by tmpl
// https://github.com/benbjohnson/tmpl
//
// DO NOT EDIT!
// Source: iterator.gen.go.tmpl
package tsm1
@ -240,7 +243,6 @@ func (c *floatAscendingCursor) peekCache() (t int64, v float64) {
// peekTSM returns the current time/value from tsm.
func (c *floatAscendingCursor) peekTSM() (t int64, v float64) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, math.NaN()
}
@ -294,7 +296,6 @@ func (c *floatAscendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadFloatBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -352,7 +353,6 @@ func (c *floatDescendingCursor) peekCache() (t int64, v float64) {
// peekTSM returns the current time/value from tsm.
func (c *floatDescendingCursor) peekTSM() (t int64, v float64) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, math.NaN()
}
@ -406,7 +406,6 @@ func (c *floatDescendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadFloatBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -576,7 +575,6 @@ func (c *integerAscendingCursor) peekCache() (t int64, v int64) {
// peekTSM returns the current time/value from tsm.
func (c *integerAscendingCursor) peekTSM() (t int64, v int64) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, 0
}
@ -630,7 +628,6 @@ func (c *integerAscendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadIntegerBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -688,7 +685,6 @@ func (c *integerDescendingCursor) peekCache() (t int64, v int64) {
// peekTSM returns the current time/value from tsm.
func (c *integerDescendingCursor) peekTSM() (t int64, v int64) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, 0
}
@ -742,7 +738,6 @@ func (c *integerDescendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadIntegerBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -912,7 +907,6 @@ func (c *stringAscendingCursor) peekCache() (t int64, v string) {
// peekTSM returns the current time/value from tsm.
func (c *stringAscendingCursor) peekTSM() (t int64, v string) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, ""
}
@ -966,7 +960,6 @@ func (c *stringAscendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadStringBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -1024,7 +1017,6 @@ func (c *stringDescendingCursor) peekCache() (t int64, v string) {
// peekTSM returns the current time/value from tsm.
func (c *stringDescendingCursor) peekTSM() (t int64, v string) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, ""
}
@ -1078,7 +1070,6 @@ func (c *stringDescendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadStringBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -1248,7 +1239,6 @@ func (c *booleanAscendingCursor) peekCache() (t int64, v bool) {
// peekTSM returns the current time/value from tsm.
func (c *booleanAscendingCursor) peekTSM() (t int64, v bool) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, false
}
@ -1302,7 +1292,6 @@ func (c *booleanAscendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadBooleanBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -1360,7 +1349,6 @@ func (c *booleanDescendingCursor) peekCache() (t int64, v bool) {
// peekTSM returns the current time/value from tsm.
func (c *booleanDescendingCursor) peekTSM() (t int64, v bool) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, false
}
@ -1414,7 +1402,6 @@ func (c *booleanDescendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.ReadBooleanBlock(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0

View File

@ -4,7 +4,7 @@ import (
"sort"
"fmt"
"math"
"github.com/influxdata/influxdb/influxql"
"github.com/influxdata/influxdb/tsdb"
)
@ -72,7 +72,7 @@ func (c *bufCursor) nextAt(seek int64) interface{} {
} else if k < seek {
continue
}
c.unread(k, v)
// Return "nil" value for type.
@ -239,7 +239,6 @@ func (c *{{.name}}AscendingCursor) peekCache() (t int64, v {{.Type}}) {
// peekTSM returns the current time/value from tsm.
func (c *{{.name}}AscendingCursor) peekTSM() (t int64, v {{.Type}}) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, {{.Nil}}
}
@ -293,7 +292,6 @@ func (c *{{.name}}AscendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.Read{{.Name}}Block(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0
@ -351,7 +349,6 @@ func (c *{{.name}}DescendingCursor) peekCache() (t int64, v {{.Type}}) {
// peekTSM returns the current time/value from tsm.
func (c *{{.name}}DescendingCursor) peekTSM() (t int64, v {{.Type}}) {
if c.tsm.pos < 0 || c.tsm.pos >= len(c.tsm.values) {
c.tsm.keyCursor.Close()
return tsdb.EOF, {{.Nil}}
}
@ -405,7 +402,6 @@ func (c *{{.name}}DescendingCursor) nextTSM() {
c.tsm.keyCursor.Next()
c.tsm.values, _ = c.tsm.keyCursor.Read{{.Name}}Block(c.tsm.buf)
if len(c.tsm.values) == 0 {
c.tsm.keyCursor.Close()
return
}
c.tsm.pos = 0