Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data deleted outside of time range #8979

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
- [#8909](https://github.com/influxdata/influxdb/issues/8909): Fix use of `INFLUXD_OPTS` in service file
- [#8952](https://github.com/influxdata/influxdb/issues/8952): Fix WAL panic: runtime error: makeslice: cap out of range
- [#8975](https://github.com/influxdata/influxdb/pull/8975): Copy returned bytes from TSI meta functions.
- [#7797](https://github.com/influxdata/influxdb/issues/7706): Fix data deleted outside of time range

## v1.3.4 [unreleased]

Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/tsm1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ func (d *indirectIndex) DeleteRange(keys [][]byte, minTime, maxTime int64) {
}

tombstones := map[string][]TimeRange{}
for _, k := range keys {
for i, k := range keys {
// Is the range passed in outside the time range for this key?
entries := d.Entries(k)

Expand All @@ -850,7 +850,7 @@ func (d *indirectIndex) DeleteRange(keys [][]byte, minTime, maxTime int64) {

// Is the range passed in cover every value for the key?
if minTime <= min && maxTime >= max {
d.Delete(keys)
d.Delete(keys[i : i+1])
continue
}

Expand Down
73 changes: 73 additions & 0 deletions tsdb/engine/tsm1/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,79 @@ func TestTSMReader_MMAP_TombstoneFullRange(t *testing.T) {
}
}

func TestTSMReader_MMAP_TombstoneFullRangeMultiple(t *testing.T) {
dir := mustTempDir()
defer os.RemoveAll(dir)
f := mustTempFile(dir)
defer f.Close()

w, err := NewTSMWriter(f)
if err != nil {
t.Fatalf("unexpected error creating writer: %v", err)
}

expValues := []Value{
NewValue(1, 1.0),
NewValue(2, 2.0),
NewValue(3, 3.0),
}
if err := w.Write([]byte("cpu"), expValues); err != nil {
t.Fatalf("unexpected error writing: %v", err)
}

expValues1 := []Value{
NewValue(3, 1.0),
NewValue(4, 2.0),
NewValue(5, 3.0),
}

if err := w.Write([]byte("mem"), expValues1); err != nil {
t.Fatalf("unexpected error writing: %v", err)
}

if err := w.WriteIndex(); err != nil {
t.Fatalf("unexpected error writing index: %v", err)
}

if err := w.Close(); err != nil {
t.Fatalf("unexpected error closing: %v", err)
}

f, err = os.Open(f.Name())
if err != nil {
t.Fatalf("unexpected error open file: %v", err)
}

r, err := NewTSMReader(f)
if err != nil {
t.Fatalf("unexpected error created reader: %v", err)
}
defer r.Close()

if err := r.DeleteRange([][]byte{[]byte("mem"), []byte("cpu")}, 0, 3); err != nil {
t.Fatalf("unexpected error deleting: %v", err)
}

// Make sure everything is deleted
values, err := r.ReadAll([]byte("cpu"))
if err != nil {
t.Fatalf("unexpected error reading all: %v", err)
}

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

values, err = r.ReadAll([]byte("mem"))
if err != nil {
t.Fatalf("unexpected error reading all: %v", err)
}

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

func TestTSMReader_MMAP_TombstoneMultipleRanges(t *testing.T) {
dir := mustTempDir()
defer os.RemoveAll(dir)
Expand Down