@@ -74,8 +74,15 @@ and output a hex encoded line of binary for each input line`)
74
74
log .Fatal ("start-snap and start-index flags cannot be used together." )
75
75
}
76
76
77
+ startFromIndex := false
78
+ flag .Visit (func (f * flag.Flag ) {
79
+ if f .Name == "start-index" {
80
+ startFromIndex = true
81
+ }
82
+ })
83
+
77
84
if ! * raw {
78
- ents := readUsingReadAll (lg , index , snapfile , dataDir , waldir )
85
+ ents := readUsingReadAll (lg , startFromIndex , index , snapfile , dataDir , waldir )
79
86
80
87
fmt .Printf ("WAL entries: %d\n " , len (ents ))
81
88
if len (ents ) > 0 {
@@ -104,16 +111,14 @@ and output a hex encoded line of binary for each input line`)
104
111
}
105
112
}
106
113
107
- func readUsingReadAll (lg * zap.Logger , index * uint64 , snapfile * string , dataDir string , waldir * string ) []raftpb.Entry {
114
+ func readUsingReadAll (lg * zap.Logger , startFromIndex bool , index * uint64 , snapfile * string , dataDir string , waldir * string ) []raftpb.Entry {
108
115
var (
109
116
walsnap walpb.Snapshot
110
117
snapshot * raftpb.Snapshot
111
118
err error
112
119
)
113
120
114
- isIndex := * index != 0
115
-
116
- if isIndex {
121
+ if startFromIndex {
117
122
fmt .Printf ("Start dumping log entries from index %d.\n " , * index )
118
123
walsnap .Index = * index
119
124
} else {
@@ -154,7 +159,7 @@ func readUsingReadAll(lg *zap.Logger, index *uint64, snapfile *string, dataDir s
154
159
}
155
160
wmetadata , state , ents , err := w .ReadAll ()
156
161
w .Close ()
157
- if err != nil && (! isIndex || ! errors .Is (err , wal .ErrSnapshotNotFound )) {
162
+ if err != nil && (! startFromIndex || ! errors .Is (err , wal .ErrSnapshotNotFound )) {
158
163
log .Fatalf ("Failed reading WAL: %v" , err )
159
164
}
160
165
id , cid := parseWALMetadata (wmetadata )
0 commit comments