Skip to content

Commit

Permalink
mvcc/backend: Delete orphaned db.tmp files before defrag
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbetz committed Feb 12, 2020
1 parent 61f2794 commit ce8464e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mvcc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ func (b *backend) defrag() error {

b.batchTx.tx = nil

tmpdb, err := bolt.Open(b.db.Path()+".tmp", 0600, boltOpenOptions)
tmpdbPath := b.db.Path() + ".tmp"
if _, err := os.Stat(tmpdbPath); err == nil {
// Ensure we start with a clean slate since
// db.tmp files can be orphaned if etcd is terminated
// before defrag completes
os.Remove(tmpdbPath)
}
tmpdb, err := bolt.Open(tmpdbPath, 0600, boltOpenOptions)
if err != nil {
return err
}
Expand Down

0 comments on commit ce8464e

Please sign in to comment.