mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #12037 from spzala/automated-cherry-pick-of-#11807-upstream-release-3.4
Automated cherry pick of #11807
This commit is contained in:
commit
493f15c156
@ -61,6 +61,7 @@ var (
|
|||||||
ErrCRCMismatch = errors.New("wal: crc mismatch")
|
ErrCRCMismatch = errors.New("wal: crc mismatch")
|
||||||
ErrSnapshotMismatch = errors.New("wal: snapshot mismatch")
|
ErrSnapshotMismatch = errors.New("wal: snapshot mismatch")
|
||||||
ErrSnapshotNotFound = errors.New("wal: snapshot not found")
|
ErrSnapshotNotFound = errors.New("wal: snapshot not found")
|
||||||
|
ErrDecoderNotFound = errors.New("wal: decoder not found")
|
||||||
crcTable = crc32.MakeTable(crc32.Castagnoli)
|
crcTable = crc32.MakeTable(crc32.Castagnoli)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,7 +96,8 @@ type WAL struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a WAL ready for appending records. The given metadata is
|
// Create creates a WAL ready for appending records. The given metadata is
|
||||||
// recorded at the head of each WAL file, and can be retrieved with ReadAll.
|
// recorded at the head of each WAL file, and can be retrieved with ReadAll
|
||||||
|
// after the file is Open.
|
||||||
func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) {
|
func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) {
|
||||||
if Exist(dirpath) {
|
if Exist(dirpath) {
|
||||||
return nil, os.ErrExist
|
return nil, os.ErrExist
|
||||||
@ -434,6 +436,10 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
|
|||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
rec := &walpb.Record{}
|
rec := &walpb.Record{}
|
||||||
|
|
||||||
|
if w.decoder == nil {
|
||||||
|
return nil, state, nil, ErrDecoderNotFound
|
||||||
|
}
|
||||||
decoder := w.decoder
|
decoder := w.decoder
|
||||||
|
|
||||||
var match bool
|
var match bool
|
||||||
|
@ -1059,3 +1059,24 @@ func TestValidSnapshotEntriesAfterPurgeWal(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestReadAllFail ensure ReadAll error if used without opening the WAL
|
||||||
|
func TestReadAllFail(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "waltest")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
// create initial WAL
|
||||||
|
f, err := Create(zap.NewExample(), dir, []byte("metadata"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
// try to read without opening the WAL
|
||||||
|
_, _, _, err = f.ReadAll()
|
||||||
|
if err == nil || err != ErrDecoderNotFound {
|
||||||
|
t.Fatalf("err = %v, want ErrDecoderNotFound", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user