diff --git a/CHANGELOG.md b/CHANGELOG.md index 29aa800a797..9fc4c489711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index 8446272a66f..d0e98aa51d7 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -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. @@ -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 { diff --git a/tsdb/engine/tsm1/engine_test.go b/tsdb/engine/tsm1/engine_test.go index a6b747cdaf4..621fbaabb23 100644 --- a/tsdb/engine/tsm1/engine_test.go +++ b/tsdb/engine/tsm1/engine_test.go @@ -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) }