Skip to content

Commit

Permalink
Ensure WAL cache gets sorted when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldix authored and toddboom committed Aug 21, 2015
1 parent e91a82c commit d0646a8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tsdb/engine/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,9 @@ func (p *Partition) addToCache(key, data []byte, timestamp int64) {
}

// Determine if we'll need to sort the values for this key later
entry.isDirtySort = bytes.Compare(entry.points[len(entry.points)-1][0:8], v[0:8]) != -1
if !entry.isDirtySort { // don't bother if we already know it has to be sorted
entry.isDirtySort = bytes.Compare(entry.points[len(entry.points)-1][0:8], v[0:8]) != -1
}
entry.points = append(entry.points, v)
entry.size += len(v)
}
Expand Down
45 changes: 45 additions & 0 deletions tsdb/engine/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,51 @@ func TestWAL_QueryDuringCompaction(t *testing.T) {
verify()
}

func TestWAL_PointsSorted(t *testing.T) {
log := openTestWAL()
defer log.Close()
defer os.RemoveAll(log.path)

if err := log.Open(); err != nil {
t.Fatalf("couldn't open wal: %s", err.Error())
}

codec := tsdb.NewFieldCodec(map[string]*tsdb.Field{
"value": {
ID: uint8(1),
Name: "value",
Type: influxql.Float,
},
})

// test that we can write to two different series
p1 := parsePoint("cpu,host=A value=1.1 1", codec)
p2 := parsePoint("cpu,host=A value=4.4 4", codec)
p3 := parsePoint("cpu,host=A value=2.2 2", codec)
p4 := parsePoint("cpu,host=A value=6.6 6", codec)
if err := log.WritePoints([]tsdb.Point{p1, p2, p3, p4}, nil, nil); err != nil {
t.Fatalf("failed to write points: %s", err.Error())
}

c := log.Cursor("cpu,host=A")
k, _ := c.Next()
if btou64(k) != 1 {
t.Fatal("points out of order")
}
k, _ = c.Next()
if btou64(k) != 2 {
t.Fatal("points out of order")
}
k, _ = c.Next()
if btou64(k) != 4 {
t.Fatal("points out of order")
}
k, _ = c.Next()
if btou64(k) != 6 {
t.Fatal("points out of order")
}
}

// test that partitions get compacted and flushed when number of series hits compaction threshold
// test that partitions get compacted and flushed when a single series hits the compaction threshold
// test that writes slow down when the partition size threshold is hit
Expand Down

0 comments on commit d0646a8

Please sign in to comment.