Skip to content

Commit

Permalink
fix #8677: check for snapshot size == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dgnorton committed Aug 16, 2017
1 parent 14ab24f commit db67f1c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#8607](https://github.com/influxdata/influxdb/issues/8607): Fix time zone shifts when the shift happens on a time zone boundary.
- [#8639](https://github.com/influxdata/influxdb/issues/8639): Parse time literals using the time zone in the select statement.
- [#8701](https://github.com/influxdata/influxdb/pull/8701): Fix drop measurement not dropping all data
- [#8677](https://github.com/influxdata/influxdb/issues/8677): Fix backups when snapshot is empty.

## v1.3.3 [2017-08-10]

Expand Down
6 changes: 6 additions & 0 deletions tsdb/engine/tsm1/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,11 @@ func (e *Engine) WriteSnapshot() error {
return err
}

if snapshot.Size() == 0 {
e.Cache.ClearSnapshot(true)
return nil
}

// The snapshotted cache may have duplicate points and unsorted data. We need to deduplicate
// it before writing the snapshot. This can be very expensive so it's done while we are not
// holding the engine write lock.
Expand Down Expand Up @@ -1136,6 +1141,7 @@ func (e *Engine) writeSnapshotAndCommit(closedFiles []string, snapshot *Cache) (
e.Cache.ClearSnapshot(false)
}
}()

// write the new snapshot files
newFiles, err := e.Compactor.WriteSnapshot(snapshot)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions tsdb/engine/tsm1/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,41 @@ func TestEngine_LastModified(t *testing.T) {
}
}

func TestEngine_SnapshotsDisabled(t *testing.T) {
// Generate temporary file.
dir, _ := ioutil.TempDir("", "tsm")
walPath := filepath.Join(dir, "wal")
os.MkdirAll(walPath, 0777)
defer os.RemoveAll(dir)

// Create a tsm1 engine.
db := path.Base(dir)
opt := tsdb.NewEngineOptions()
opt.InmemIndex = inmem.NewIndex(db)
idx := tsdb.MustOpenIndex(1, db, filepath.Join(dir, "index"), opt)
defer idx.Close()

e := tsm1.NewEngine(1, idx, db, dir, walPath, opt).(*tsm1.Engine)

// mock the planner so compactions don't run during the test
e.CompactionPlan = &mockPlanner{}

e.SetEnabled(false)
if err := e.Open(); err != nil {
t.Fatalf("failed to open tsm1 engine: %s", err.Error())
}

// Make sure Snapshots are disabled.
e.SetCompactionsEnabled(false)
e.Compactor.DisableSnapshots()

// Writing a snapshot should not fail when the snapshot is empty
// even if snapshots are disabled.
if err := e.WriteSnapshot(); err != nil {
t.Fatalf("failed to snapshot: %s", err.Error())
}
}

func BenchmarkEngine_CreateIterator_Count_1K(b *testing.B) {
benchmarkEngineCreateIteratorCount(b, 1000)
}
Expand Down

0 comments on commit db67f1c

Please sign in to comment.