mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: do not backup files still in use
This commit is contained in:
parent
ea94d19147
commit
f538cba272
@ -67,7 +67,7 @@ func handleBackup(c *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := wal.OpenAtIndex(srcWAL, index)
|
w, err := wal.OpenAtIndexUntilUsing(srcWAL, index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
16
wal/wal.go
16
wal/wal.go
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -123,6 +124,14 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
|
|||||||
// index. The WAL cannot be appended to before reading out all of its
|
// index. The WAL cannot be appended to before reading out all of its
|
||||||
// previous records.
|
// previous records.
|
||||||
func OpenAtIndex(dirpath string, index uint64) (*WAL, error) {
|
func OpenAtIndex(dirpath string, index uint64) (*WAL, error) {
|
||||||
|
return openAtIndex(dirpath, index, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenAtIndexUntilUsing(dirpath string, index uint64) (*WAL, error) {
|
||||||
|
return openAtIndex(dirpath, index, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openAtIndex(dirpath string, index uint64, all bool) (*WAL, error) {
|
||||||
names, err := fileutil.ReadDir(dirpath)
|
names, err := fileutil.ReadDir(dirpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -153,7 +162,12 @@ func OpenAtIndex(dirpath string, index uint64) (*WAL, error) {
|
|||||||
}
|
}
|
||||||
err = l.TryLock()
|
err = l.TryLock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
if all {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
log.Printf("wal: opened all the files until %s, since it is still in use by an etcd server", name)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rcs = append(rcs, f)
|
rcs = append(rcs, f)
|
||||||
ls = append(ls, l)
|
ls = append(ls, l)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user