mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1861 from yichengq/250
wal: sync after writing data to disk in Cut function
This commit is contained in:
commit
a16dd7ea67
@ -240,7 +240,10 @@ func (w *WAL) Cut() error {
|
||||
if err := w.encoder.encode(&walpb.Record{Type: metadataType, Data: w.metadata}); err != nil {
|
||||
return err
|
||||
}
|
||||
return w.SaveState(&w.state)
|
||||
if err := w.SaveState(&w.state); err != nil {
|
||||
return err
|
||||
}
|
||||
return w.sync()
|
||||
}
|
||||
|
||||
func (w *WAL) sync() error {
|
||||
|
@ -131,6 +131,7 @@ func TestOpenAtIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: split it into smaller tests for better readability
|
||||
func TestCut(t *testing.T) {
|
||||
p, err := ioutil.TempDir(os.TempDir(), "waltest")
|
||||
if err != nil {
|
||||
@ -142,6 +143,7 @@ func TestCut(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
// TODO(unihorn): remove this when cut can operate on an empty file
|
||||
if err := w.SaveEntry(&raftpb.Entry{}); err != nil {
|
||||
@ -170,19 +172,20 @@ func TestCut(t *testing.T) {
|
||||
if g := path.Base(w.f.Name()); g != wname {
|
||||
t.Errorf("name = %s, want %s", g, wname)
|
||||
}
|
||||
w.Close()
|
||||
|
||||
// check the state in the last WAL
|
||||
// We do check before closing the WAL to ensure that Cut syncs the data
|
||||
// into the disk.
|
||||
f, err := os.Open(path.Join(p, wname))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
w = &WAL{
|
||||
nw := &WAL{
|
||||
decoder: newDecoder(f),
|
||||
ri: 2,
|
||||
}
|
||||
_, gst, _, err := w.ReadAll()
|
||||
_, gst, _, err := nw.ReadAll()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user