mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tool: dump tool supports index
This commit is contained in:
parent
7c65857283
commit
d6f8a30f7c
@ -32,35 +32,47 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
from := flag.String("data-dir", "", "")
|
from := flag.String("data-dir", "", "")
|
||||||
snapfile := flag.String("snap-file", "", "The base name of snapshot file to read")
|
snapfile := flag.String("start-snap", "", "The base name of snapshot file to start dumping")
|
||||||
|
index := flag.Uint64("start-index", 0, "The index to start dumping")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *from == "" {
|
if *from == "" {
|
||||||
log.Fatal("Must provide -data-dir flag")
|
log.Fatal("Must provide -data-dir flag.")
|
||||||
|
}
|
||||||
|
if *snapfile != "" && *index != 0 {
|
||||||
|
log.Fatal("start-snap and start-index flags cannot be used together.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
walsnap walpb.Snapshot
|
||||||
snapshot *raftpb.Snapshot
|
snapshot *raftpb.Snapshot
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
if *snapfile == "" {
|
isIndex := *index != 0
|
||||||
ss := snap.New(snapDir(*from))
|
|
||||||
snapshot, err = ss.Load()
|
|
||||||
} else {
|
|
||||||
snapshot, err = snap.Read(path.Join(snapDir(*from), *snapfile))
|
|
||||||
}
|
|
||||||
|
|
||||||
var walsnap walpb.Snapshot
|
if isIndex {
|
||||||
switch err {
|
fmt.Printf("Start dumping log entries from index %d.\n", *index)
|
||||||
case nil:
|
walsnap.Index = *index
|
||||||
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
|
} else {
|
||||||
nodes := genIDSlice(snapshot.Metadata.ConfState.Nodes)
|
if *snapfile == "" {
|
||||||
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s\n",
|
ss := snap.New(snapDir(*from))
|
||||||
walsnap.Term, walsnap.Index, nodes)
|
snapshot, err = ss.Load()
|
||||||
case snap.ErrNoSnapshot:
|
} else {
|
||||||
fmt.Printf("Snapshot:\nempty\n")
|
snapshot, err = snap.Read(path.Join(snapDir(*from), *snapfile))
|
||||||
default:
|
}
|
||||||
log.Fatalf("Failed loading snapshot: %v", err)
|
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
|
||||||
|
nodes := genIDSlice(snapshot.Metadata.ConfState.Nodes)
|
||||||
|
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s\n",
|
||||||
|
walsnap.Term, walsnap.Index, nodes)
|
||||||
|
case snap.ErrNoSnapshot:
|
||||||
|
fmt.Printf("Snapshot:\nempty\n")
|
||||||
|
default:
|
||||||
|
log.Fatalf("Failed loading snapshot: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println("Start dupmping log entries from snapshot.")
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := wal.Open(walDir(*from), walsnap)
|
w, err := wal.Open(walDir(*from), walsnap)
|
||||||
@ -69,7 +81,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
wmetadata, state, ents, err := w.ReadAll()
|
wmetadata, state, ents, err := w.ReadAll()
|
||||||
w.Close()
|
w.Close()
|
||||||
if err != nil {
|
if err != nil && (!isIndex || err != wal.ErrSnapshotNotFound) {
|
||||||
log.Fatalf("Failed reading WAL: %v", err)
|
log.Fatalf("Failed reading WAL: %v", err)
|
||||||
}
|
}
|
||||||
id, cid := parseWALMetadata(wmetadata)
|
id, cid := parseWALMetadata(wmetadata)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user