Skip to content

Commit

Permalink
fix typo in wal doc, log:
Browse files Browse the repository at this point in the history
- fix logs in wal Repair

- unify broken file name to val
  • Loading branch information
ben1009 committed Aug 31, 2021
1 parent 873f369 commit af10e87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions server/storage/wal/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// limitations under the License.

/*
Package wal provides an implementation of a write ahead log that is used by
Package wal provides an implementation of write ahead log that is used by
etcd.
A WAL is created at a particular directory and is made up of a number of
segmented WAL files. Inside of each file the raft state and entries are appended
segmented WAL files. Inside each file the raft state and entries are appended
to it with the Save method:
metadata := []byte{}
Expand All @@ -41,18 +41,18 @@ protobuf. The record protobuf contains a CRC, a type, and a data payload. The le
record is 8-byte aligned so that the length field is never torn. The CRC contains the CRC32
value of all record protobufs preceding the current record.
WAL files are placed inside of the directory in the following format:
WAL files are placed inside the directory in the following format:
$seq-$index.wal
The first WAL file to be created will be 0000000000000000-0000000000000000.wal
indicating an initial sequence of 0 and an initial raft index of 0. The first
entry written to WAL MUST have raft index 0.
WAL will cut its current tail wal file if its size exceeds 64MB. This will increment an internal
WAL will cut its current tail wal file if its size exceeds 64 MB. This will increment an internal
sequence number and cause a new file to be created. If the last raft index saved
was 0x20 and this is the first time cut has been called on this WAL then the sequence will
increment from 0x0 to 0x1. The new file will be: 0000000000000001-0000000000000021.wal.
If a second cut issues 0x10 entries with incremental index later then the file will be called:
If a second cut issues 0x10 entries with incremental index later, then the file will be called:
0000000000000002-0000000000000031.wal.
At a later time a WAL can be opened at a particular snapshot. If there is no
Expand All @@ -63,7 +63,7 @@ snapshot, an empty snapshot should be passed in.
The snapshot must have been written to the WAL.
Additional items cannot be Saved to this WAL until all of the items from the given
Additional items cannot be Saved to this WAL until all the items from the given
snapshot to the end of the WAL are read first:
metadata, state, ents, err := w.ReadAll()
Expand Down
7 changes: 4 additions & 3 deletions server/storage/wal/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ func Repair(lg *zap.Logger, dirpath string) bool {
return true

case io.ErrUnexpectedEOF:
bf, bferr := os.Create(f.Name() + ".broken")
brokenName := f.Name() + ".broken"
bf, bferr := os.Create(brokenName)
if bferr != nil {
lg.Warn("failed to create backup file", zap.String("path", f.Name()+".broken"), zap.Error(bferr))
lg.Warn("failed to create backup file", zap.String("path", brokenName), zap.Error(bferr))
return false
}
defer bf.Close()
Expand All @@ -77,7 +78,7 @@ func Repair(lg *zap.Logger, dirpath string) bool {
}

if _, err = io.Copy(bf, f); err != nil {
lg.Warn("failed to copy", zap.String("from", f.Name()+".broken"), zap.String("to", f.Name()), zap.Error(err))
lg.Warn("failed to copy", zap.String("from", f.Name()), zap.String("to", brokenName), zap.Error(err))
return false
}

Expand Down

0 comments on commit af10e87

Please sign in to comment.