Skip to content

Commit

Permalink
fix(tsm1): "snapshot in progress" error during backup
Browse files Browse the repository at this point in the history
This fix adds a skipCacheOk flag to
tsdb.Store.CreateShardSnapshot() and tsdb.Shard.CreateSnapshot()
to pass to tsdb.Engine.CreateSnapshot()
A value of true allows the backup to proceed even if a cache snapshot
cannot be taken.
This flag is set to true in tsm1.Engine.Backup(), the OSS backup code path
This flag is set to false in tsm1.Engine.Export()

influxdata/plutonium#3227
  • Loading branch information
davidby-influx committed Nov 5, 2020
1 parent 23be20b commit 6ec446f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ func (e *Engine) WriteSnapshot() (err error) {
// in-memory cache data when a previous snapshot is in progress
func (e *Engine) CreateSnapshot(skipCacheOk bool) (string, error) {
if err := e.WriteSnapshot(); (err == ErrSnapshotInProgress) && skipCacheOk {
e.logger.Warn("Snapshotter busy: Backup or export proceeding without cache snapshot contents.")
e.logger.Warn("Snapshotter busy: proceeding without cache contents.")
} else if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions tsdb/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,12 +1153,12 @@ func (s *Shard) Restore(r io.Reader, basePath string) error {

// CreateSnapshot will return a path to a temp directory
// containing hard links to the underlying shard files.
func (s *Shard) CreateSnapshot() (string, error) {
func (s *Shard) CreateSnapshot(skipCacheOk bool) (string, error) {
engine, err := s.Engine()
if err != nil {
return "", err
}
return engine.CreateSnapshot(true)
return engine.CreateSnapshot(skipCacheOk)
}

// ForEachMeasurementName iterates over each measurement in the shard.
Expand Down
4 changes: 2 additions & 2 deletions tsdb/shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func TestShard_WritePoints_FieldConflictConcurrent(t *testing.T) {
}

_ = sh.WritePoints(points[:500])
if f, err := sh.CreateSnapshot(); err == nil {
if f, err := sh.CreateSnapshot(false); err == nil {
os.RemoveAll(f)
}

Expand All @@ -472,7 +472,7 @@ func TestShard_WritePoints_FieldConflictConcurrent(t *testing.T) {
}

_ = sh.WritePoints(points[500:])
if f, err := sh.CreateSnapshot(); err == nil {
if f, err := sh.CreateSnapshot(false); err == nil {
os.RemoveAll(f)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ func (s *Store) CreateShard(database, retentionPolicy string, shardID uint64, en

// CreateShardSnapShot will create a hard link to the underlying shard and return a path.
// The caller is responsible for cleaning up (removing) the file path returned.
func (s *Store) CreateShardSnapshot(id uint64) (string, error) {
func (s *Store) CreateShardSnapshot(id uint64, skipCacheOk bool) (string, error) {
sh := s.Shard(id)
if sh == nil {
return "", ErrShardNotFound
}

return sh.CreateSnapshot()
return sh.CreateSnapshot(skipCacheOk)
}

// SetShardEnabled enables or disables a shard for read and writes.
Expand Down
2 changes: 1 addition & 1 deletion tsdb/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestStore_CreateShardSnapShot(t *testing.T) {
t.Fatalf("expected shard")
}

dir, e := s.CreateShardSnapshot(1)
dir, e := s.CreateShardSnapshot(1, false)
if e != nil {
t.Fatal(e)
}
Expand Down

0 comments on commit 6ec446f

Please sign in to comment.