Skip to content

Commit

Permalink
rename Cursor.Seek() to Cursor.SeekTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Sep 22, 2015
1 parent 56cb2fa commit 96715d7
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ $fmtcount -gt 0 ]; then
fi

# Due to the way composites work, vet will fail for some of our tests so we ignore it
vetcount=`go tool vet --composites=false --methods=false ./ 2>&1 | wc -l`
vetcount=`go tool vet --composites=false ./ 2>&1 | wc -l`
if [ $vetcount -gt 0 ]; then
echo "Some files aren't passing vet heuristics, please run 'go vet ./...' to see the errors it flags and correct your source code before committing"
exit 1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [#4165](https://github.com/influxdb/influxdb/pull/4165): Tag all Go runtime stats when writing to internal database.
- [#4118](https://github.com/influxdb/influxdb/issues/4118): Return consistent, correct result for SHOW MEASUREMENTS with multiple AND conditions
- [#4191](https://github.com/influxdb/influxdb/pull/4191): Correctly marshal remote mapper responses. Fixes [#4170](https://github.com/influxdb/influxdb/issues/4170)
- [#4180](https://github.com/influxdb/influxdb/pull/4180): Cursor & SelectMapper Refactor

## v0.9.4 [2015-09-14]

Expand Down
2 changes: 1 addition & 1 deletion cmd/inspect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func main() {
}

// Seek to the beginning
_, fields := cursor.Seek(0)
_, fields := cursor.SeekTo(0)
if fields, ok := fields.(map[string]interface{}); ok {
for field, value := range fields {
fieldSummary = append(fieldSummary, fmt.Sprintf("%s:%T", field, value))
Expand Down
12 changes: 6 additions & 6 deletions tsdb/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EOF = int64(-1)

// Cursor represents an iterator over a series.
type Cursor interface {
Seek(seek int64) (key int64, value interface{})
SeekTo(seek int64) (key int64, value interface{})
Next() (key int64, value interface{})
Ascending() bool
}
Expand All @@ -38,12 +38,12 @@ type multiCursor struct {
}

// Seek moves the cursor to a given key.
func (mc *multiCursor) Seek(seek int64) (int64, interface{}) {
func (mc *multiCursor) SeekTo(seek int64) (int64, interface{}) {
// Initialize heap.
h := make(cursorHeap, 0, len(mc.cursors))
for i, c := range mc.cursors {
// Move cursor to position. Skip if it's empty.
k, v := c.Seek(seek)
k, v := c.SeekTo(seek)
if k == EOF {
continue
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (tsc *TagSetCursor) Init(seek int64) {

// Prime the buffers.
for i := 0; i < len(tsc.cursors); i++ {
k, v := tsc.cursors[i].Seek(seek)
k, v := tsc.cursors[i].SeekTo(seek)
if k == EOF {
k, v = tsc.cursors[i].Next()
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func NewTagsCursor(c Cursor, filter influxql.Expr, tags map[string]string) *Tags
}

// Seek positions returning the key and value at that key.
func (c *TagsCursor) Seek(seek int64) (int64, interface{}) {
func (c *TagsCursor) SeekTo(seek int64) (int64, interface{}) {
// We've seeked on this cursor. This seek is after that previous cached seek
// and the result it gave was after the key for this seek.
//
Expand All @@ -347,7 +347,7 @@ func (c *TagsCursor) Seek(seek int64) (int64, interface{}) {
}

// Seek to key/value in underlying cursor.
key, value := c.cursor.Seek(seek)
key, value := c.cursor.SeekTo(seek)

// Save the seek to the buffer.
c.seek = seek
Expand Down
16 changes: 8 additions & 8 deletions tsdb/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMultiCursor_Single(t *testing.T) {
{Key: 2, Value: 20},
}, true))

if k, v := mc.Seek(0); k != 0 || v.(int) != 0 {
if k, v := mc.SeekTo(0); k != 0 || v.(int) != 0 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 1 || v.(int) != 10 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand All @@ -39,7 +39,7 @@ func TestMultiCursor_Single_Reverse(t *testing.T) {
{Key: 2, Value: 20},
}, false))

if k, v := mc.Seek(2); k != 2 || v.(int) != 20 {
if k, v := mc.SeekTo(2); k != 2 || v.(int) != 20 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 1 || v.(int) != 10 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand All @@ -64,7 +64,7 @@ func TestMultiCursor_Multiple_NonOverlapping(t *testing.T) {
}, true),
)

if k, v := mc.Seek(0); k != 0 || v.(int) != 0 {
if k, v := mc.SeekTo(0); k != 0 || v.(int) != 0 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 1 || v.(int) != 10 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestMultiCursor_Multiple_NonOverlapping_Reverse(t *testing.T) {
}, false),
)

if k, v := mc.Seek(4); k != 4 || v.(int) != 40 {
if k, v := mc.SeekTo(4); k != 4 || v.(int) != 40 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 3 || v.(int) != 30 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestMultiCursor_Multiple_Overlapping(t *testing.T) {
}, true),
)

if k, v := mc.Seek(0); k != 0 || v.(int) != 0 {
if k, v := mc.SeekTo(0); k != 0 || v.(int) != 0 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 2 || v.(int) != 0xF2 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestMultiCursor_Multiple_Overlapping_Reverse(t *testing.T) {
}, false),
)

if k, v := mc.Seek(4); k != 4 || v.(int) != 4 {
if k, v := mc.SeekTo(4); k != 4 || v.(int) != 4 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = mc.Next(); k != 3 || v.(int) != 3 {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestMultiCursor_Quick(t *testing.T) {

// Create multi-cursor and iterate over all items.
mc := tsdb.MultiCursor(tsdbCursorSlice(cursors)...)
for k, v := mc.Seek(seek); k != tsdb.EOF; k, v = mc.Next() {
for k, v := mc.SeekTo(seek); k != tsdb.EOF; k, v = mc.Next() {
got = append(got, CursorItem{k, v.(int)})
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func NewCursor(items []CursorItem, ascending bool) *Cursor {
func (c *Cursor) Ascending() bool { return c.ascending }

// Seek seeks to an item by key.
func (c *Cursor) Seek(seek int64) (key int64, value interface{}) {
func (c *Cursor) SeekTo(seek int64) (key int64, value interface{}) {
if c.ascending {
return c.seekForward(seek)
}
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/b1/b1.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ type Cursor struct {
func (c *Cursor) Ascending() bool { return c.ascending }

// Seek moves the cursor to a position and returns the closest key/value pair.
func (c *Cursor) Seek(seek int64) (key int64, value interface{}) {
func (c *Cursor) SeekTo(seek int64) (key int64, value interface{}) {
// Seek bolt cursor.
seekBytes := u64tob(uint64(seek))
if c.cursor != nil {
Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/b1/b1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestEngine_WritePoints(t *testing.T) {
defer tx.Rollback()

c := tx.Cursor("temperature", []string{"value"}, mf.Codec, true)
if k, v := c.Seek(0); k != 1434059627000000000 {
if k, v := c.SeekTo(0); k != 1434059627000000000 {
t.Fatalf("unexpected key: %#v", k)
} else if v == nil || v.(float64) != 200 {
t.Errorf("unexpected value: %#v", v)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestEngine_WritePoints_Reverse(t *testing.T) {
defer tx.Rollback()

c := tx.Cursor("temperature", []string{"value"}, mf.Codec, false)
if k, _ := c.Seek(math.MaxInt64); k != time.Unix(1, 0).UnixNano() {
if k, _ := c.SeekTo(math.MaxInt64); k != time.Unix(1, 0).UnixNano() {
t.Fatalf("unexpected key: %v", k)
} else if k, v := c.Next(); k != time.Unix(0, 0).UnixNano() {
t.Fatalf("unexpected key: %v", k)
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/bz1/bz1.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func (c *Cursor) last() {
func (c *Cursor) Ascending() bool { return c.ascending }

// Seek moves the cursor to a position and returns the closest key/value pair.
func (c *Cursor) Seek(seek int64) (key int64, value interface{}) {
func (c *Cursor) SeekTo(seek int64) (key int64, value interface{}) {
seekBytes := u64tob(uint64(seek))

// Move cursor to appropriate block and set to buffer.
Expand Down
63 changes: 31 additions & 32 deletions tsdb/engine/bz1/bz1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/influxdb/influxdb/models"
"github.com/influxdb/influxdb/tsdb"
"github.com/influxdb/influxdb/tsdb/engine/bz1"
//"github.com/influxdb/influxdb/tsdb/engine/wal"
)

// Ensure the engine can write series metadata and reload it.
Expand Down Expand Up @@ -152,11 +151,11 @@ func TestEngine_WriteIndex_Append(t *testing.T) {
// Append points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(1), MustEncodeFields(codec, tsdb.Fields{"value": float64(10)})...),
append(u64tob(2), MustEncodeFields(codec, tsdb.Fields{"value": float64(20)})...),
append(u64tob(1), MustEncodeFields(codec, models.Fields{"value": float64(10)})...),
append(u64tob(2), MustEncodeFields(codec, models.Fields{"value": float64(20)})...),
},
"mem": [][]byte{
append(u64tob(0), MustEncodeFields(codec, tsdb.Fields{"value": float64(30)})...),
append(u64tob(0), MustEncodeFields(codec, models.Fields{"value": float64(30)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -168,7 +167,7 @@ func TestEngine_WriteIndex_Append(t *testing.T) {

// Iterate over "cpu" series.
c := tx.Cursor("cpu", []string{"value"}, codec, true)
if k, v := c.Seek(0); k != 1 || v.(float64) != float64(10) {
if k, v := c.SeekTo(0); k != 1 || v.(float64) != float64(10) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = c.Next(); k != 2 || v.(float64) != float64(20) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand All @@ -178,7 +177,7 @@ func TestEngine_WriteIndex_Append(t *testing.T) {

// Iterate over "mem" series.
c = tx.Cursor("mem", []string{"value"}, codec, true)
if k, v := c.Seek(0); k != 0 || v.(float64) != float64(30) {
if k, v := c.SeekTo(0); k != 0 || v.(float64) != float64(30) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, _ = c.Next(); k != tsdb.EOF {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand All @@ -198,9 +197,9 @@ func TestEngine_WriteIndex_Insert(t *testing.T) {
// Write initial points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(10), MustEncodeFields(codec, tsdb.Fields{"value": float64(10)})...),
append(u64tob(20), MustEncodeFields(codec, tsdb.Fields{"value": float64(20)})...),
append(u64tob(30), MustEncodeFields(codec, tsdb.Fields{"value": float64(30)})...),
append(u64tob(10), MustEncodeFields(codec, models.Fields{"value": float64(10)})...),
append(u64tob(20), MustEncodeFields(codec, models.Fields{"value": float64(20)})...),
append(u64tob(30), MustEncodeFields(codec, models.Fields{"value": float64(30)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -209,10 +208,10 @@ func TestEngine_WriteIndex_Insert(t *testing.T) {
// Write overlapping points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(9), MustEncodeFields(codec, tsdb.Fields{"value": float64(9)})...),
append(u64tob(10), MustEncodeFields(codec, tsdb.Fields{"value": float64(255)})...),
append(u64tob(25), MustEncodeFields(codec, tsdb.Fields{"value": float64(25)})...),
append(u64tob(31), MustEncodeFields(codec, tsdb.Fields{"value": float64(31)})...),
append(u64tob(9), MustEncodeFields(codec, models.Fields{"value": float64(9)})...),
append(u64tob(10), MustEncodeFields(codec, models.Fields{"value": float64(255)})...),
append(u64tob(25), MustEncodeFields(codec, models.Fields{"value": float64(25)})...),
append(u64tob(31), MustEncodeFields(codec, models.Fields{"value": float64(31)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -221,7 +220,7 @@ func TestEngine_WriteIndex_Insert(t *testing.T) {
// Write overlapping points to index again.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(31), MustEncodeFields(codec, tsdb.Fields{"value": float64(255)})...),
append(u64tob(31), MustEncodeFields(codec, models.Fields{"value": float64(255)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -233,7 +232,7 @@ func TestEngine_WriteIndex_Insert(t *testing.T) {

// Iterate over "cpu" series.
c := tx.Cursor("cpu", []string{"value"}, codec, true)
if k, v := c.Seek(0); k != 9 || v.(float64) != float64(9) {
if k, v := c.SeekTo(0); k != 9 || v.(float64) != float64(9) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = c.Next(); k != 10 || v.(float64) != float64(255) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand Down Expand Up @@ -261,9 +260,9 @@ func TestEngine_Cursor_Reverse(t *testing.T) {
// Write initial points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(10), MustEncodeFields(codec, tsdb.Fields{"value": float64(10)})...),
append(u64tob(20), MustEncodeFields(codec, tsdb.Fields{"value": float64(20)})...),
append(u64tob(30), MustEncodeFields(codec, tsdb.Fields{"value": float64(30)})...),
append(u64tob(10), MustEncodeFields(codec, models.Fields{"value": float64(10)})...),
append(u64tob(20), MustEncodeFields(codec, models.Fields{"value": float64(20)})...),
append(u64tob(30), MustEncodeFields(codec, models.Fields{"value": float64(30)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -272,10 +271,10 @@ func TestEngine_Cursor_Reverse(t *testing.T) {
// Write overlapping points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(9), MustEncodeFields(codec, tsdb.Fields{"value": float64(9)})...),
append(u64tob(10), MustEncodeFields(codec, tsdb.Fields{"value": float64(255)})...),
append(u64tob(25), MustEncodeFields(codec, tsdb.Fields{"value": float64(25)})...),
append(u64tob(31), MustEncodeFields(codec, tsdb.Fields{"value": float64(31)})...),
append(u64tob(9), MustEncodeFields(codec, models.Fields{"value": float64(9)})...),
append(u64tob(10), MustEncodeFields(codec, models.Fields{"value": float64(255)})...),
append(u64tob(25), MustEncodeFields(codec, models.Fields{"value": float64(25)})...),
append(u64tob(31), MustEncodeFields(codec, models.Fields{"value": float64(31)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -284,7 +283,7 @@ func TestEngine_Cursor_Reverse(t *testing.T) {
// Write overlapping points to index again.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(31), MustEncodeFields(codec, tsdb.Fields{"value": float64(255)})...),
append(u64tob(31), MustEncodeFields(codec, models.Fields{"value": float64(255)})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -296,7 +295,7 @@ func TestEngine_Cursor_Reverse(t *testing.T) {

// Iterate over "cpu" series.
c := tx.Cursor("cpu", []string{"value"}, codec, false)
if k, v := c.Seek(math.MaxInt64); k != 31 || v.(float64) != float64(255) {
if k, v := c.SeekTo(math.MaxInt64); k != 31 || v.(float64) != float64(255) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = c.Next(); k != 30 || v.(float64) != float64(30) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
Expand All @@ -306,7 +305,7 @@ func TestEngine_Cursor_Reverse(t *testing.T) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = c.Next(); k != 10 || v.(float64) != float64(255) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
} else if k, v = c.Seek(0); k != 9 || v.(float64) != float64(9) {
} else if k, v = c.SeekTo(0); k != 9 || v.(float64) != float64(9) {
t.Fatalf("unexpected key/value: %x / %x", k, v)
}
}
Expand All @@ -328,10 +327,10 @@ func TestEngine_WriteIndex_SeekAgainstInBlockValue(t *testing.T) {
// Write initial points to index.
if err := e.WriteIndex(map[string][][]byte{
"cpu": [][]byte{
append(u64tob(10), MustEncodeFields(codec, tsdb.Fields{"value": data})...),
append(u64tob(20), MustEncodeFields(codec, tsdb.Fields{"value": data})...),
append(u64tob(30), MustEncodeFields(codec, tsdb.Fields{"value": data})...),
append(u64tob(40), MustEncodeFields(codec, tsdb.Fields{"value": data})...),
append(u64tob(10), MustEncodeFields(codec, models.Fields{"value": data})...),
append(u64tob(20), MustEncodeFields(codec, models.Fields{"value": data})...),
append(u64tob(30), MustEncodeFields(codec, models.Fields{"value": data})...),
append(u64tob(40), MustEncodeFields(codec, models.Fields{"value": data})...),
},
}, nil, nil); err != nil {
t.Fatal(err)
Expand All @@ -343,11 +342,11 @@ func TestEngine_WriteIndex_SeekAgainstInBlockValue(t *testing.T) {

// Ensure that we can seek to a block in the middle
c := tx.Cursor("cpu", []string{"value"}, codec, true)
if k, _ := c.Seek(15); k != 20 {
if k, _ := c.SeekTo(15); k != 20 {
t.Fatalf("expected to seek to time 20, but got %d", k)
}
// Ensure that we can seek to the block on the end
if k, _ := c.Seek(35); k != 40 {
if k, _ := c.SeekTo(35); k != 40 {
t.Fatalf("expected to seek to time 40, but got %d", k)
}
}
Expand Down Expand Up @@ -452,7 +451,7 @@ type Cursor struct {

func (c *Cursor) Ascending() bool { return c.ascending }

func (c *Cursor) Seek(key int64) (int64, interface{}) { return tsdb.EOF, nil }
func (c *Cursor) SeekTo(key int64) (int64, interface{}) { return tsdb.EOF, nil }

func (c *Cursor) Next() (int64, interface{}) { return tsdb.EOF, nil }

Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ func newCursor(cache [][]byte, fields []string, dec *tsdb.FieldCodec, ascending
func (c *cursor) Ascending() bool { return c.ascending }

// Seek will point the cursor to the given time (or key)
func (c *cursor) Seek(seek int64) (key int64, value interface{}) {
func (c *cursor) SeekTo(seek int64) (key int64, value interface{}) {
seekBytes := u64tob(uint64(seek))

// Seek cache index
Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestWAL_WritePoints(t *testing.T) {
}

c := log.Cursor("cpu,host=A", []string{"value"}, codec, true)
k, v := c.Seek(1)
k, v := c.SeekTo(1)

// ensure the series are there and points are in order
if v.(float64) != 23.2 {
Expand Down Expand Up @@ -602,7 +602,7 @@ func TestWAL_QueryDuringCompaction(t *testing.T) {

verify := func() {
c := log.Cursor("cpu,host=A", []string{"value"}, codec, true)
k, v := c.Seek(1)
k, v := c.SeekTo(1)
// ensure the series are there and points are in order
if v.(float64) != 23.2 {
<-finishCompaction
Expand Down
Loading

0 comments on commit 96715d7

Please sign in to comment.