Skip to content

Commit

Permalink
Fix read tombstones: EOF
Browse files Browse the repository at this point in the history
Due to an bug in TSM tombstone files, it was possible to create
empty tombstone files.  At startup, the TSM file would error out
and not load the TSM file.

Instead, treat it as an empty v1 file so the TSM file can load
correctly.

Fixes #6641
  • Loading branch information
jwilder committed May 19, 2016
1 parent 7fcf95c commit 4c089a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [#6406](https://github.com/influxdata/influxdb/issues/6406): Max index entries exceeded
- [#6557](https://github.com/influxdata/influxdb/issues/6557): Overwriting points on large series can cause memory spikes during compactions
- [#6611](https://github.com/influxdata/influxdb/issues/6611): Queries slow down hundreds times after overwriting points
- [#6641](https://github.com/influxdata/influxdb/issues/6641): Fix read tombstones: EOF

## v0.13.0 [2016-05-12]

Expand Down
6 changes: 4 additions & 2 deletions tsdb/engine/tsm1/tombstone.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ func (t *Tombstoner) readTombstone() ([]Tombstone, error) {
var b [4]byte
_, err := f.Read(b[:])
if err != nil {
return nil, err
// Might be a zero length file which should not exist, but
// an old bug allowed them to occur. Treat it as an empty
// v1 tombstone file so we don't abort loading the TSM file.
return t.readTombstoneV1(f)
}

if _, err := f.Seek(0, os.SEEK_SET); err != nil {
Expand All @@ -171,7 +174,6 @@ func (t *Tombstoner) readTombstone() ([]Tombstone, error) {
if binary.BigEndian.Uint32(b[:]) == v2header {
return t.readTombstoneV2(f)
}

return t.readTombstoneV1(f)
}
return nil, nil
Expand Down
28 changes: 28 additions & 0 deletions tsdb/engine/tsm1/tombstone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,31 @@ func TestTombstoner_ReadV1(t *testing.T) {
t.Fatalf("value mismatch: got %v, exp %v", got, exp)
}
}

func TestTombstoner_ReadEmptyV1(t *testing.T) {
dir := MustTempDir()
defer func() { os.RemoveAll(dir) }()

f := MustTempFile(dir)
f.Close()

if err := os.Rename(f.Name(), f.Name()+".tombstone"); err != nil {
t.Fatalf("rename tombstone failed: %v", err)
}

ts := &tsm1.Tombstoner{Path: f.Name()}

entries, err := ts.ReadAll()
if err != nil {
fatal(t, "ReadAll", err)
}

entries, err = ts.ReadAll()
if err != nil {
fatal(t, "ReadAll", err)
}

if got, exp := len(entries), 0; got != exp {
t.Fatalf("length mismatch: got %v, exp %v", got, exp)
}
}

0 comments on commit 4c089a5

Please sign in to comment.