From 53bf7e4b5e7faf34d6eebfc08cd76bb9319275b7 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sun, 14 Dec 2014 19:33:06 -0800 Subject: [PATCH] wal: rename openAtIndex -> open; OpenAtIndexUntilUsing -> openNotInUse --- etcdctl/command/backup_command.go | 2 +- etcdserver/server.go | 2 +- wal/wal.go | 8 +++++--- wal/wal_test.go | 12 ++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/etcdctl/command/backup_command.go b/etcdctl/command/backup_command.go index 778cbcc44..42ec38797 100644 --- a/etcdctl/command/backup_command.go +++ b/etcdctl/command/backup_command.go @@ -67,7 +67,7 @@ func handleBackup(c *cli.Context) { } } - w, err := wal.OpenAtIndexUntilUsing(srcWAL, index) + w, err := wal.OpenNotInUse(srcWAL, index) if err != nil { log.Fatal(err) } diff --git a/etcdserver/server.go b/etcdserver/server.go index 31f292538..1f5de691f 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -987,7 +987,7 @@ func restartNode(cfg *ServerConfig, index uint64, snapshot *raftpb.Snapshot) (ty func readWAL(waldir string, index uint64) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) { var err error - if w, err = wal.OpenAtIndex(waldir, index); err != nil { + if w, err = wal.Open(waldir, index); err != nil { log.Fatalf("etcdserver: open wal error: %v", err) } var wmetadata []byte diff --git a/wal/wal.go b/wal/wal.go index 36480b0b2..47fc491d1 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -117,17 +117,19 @@ func Create(dirpath string, metadata []byte) (*WAL, error) { return w, nil } -// OpenAtIndex opens the WAL at the given index. +// Open opens the WAL at the given index. // The index SHOULD have been previously committed to the WAL, or the following // ReadAll will fail. // The returned WAL is ready to read and the first record will be the given // index. The WAL cannot be appended to before reading out all of its // previous records. -func OpenAtIndex(dirpath string, index uint64) (*WAL, error) { +func Open(dirpath string, index uint64) (*WAL, error) { return openAtIndex(dirpath, index, true) } -func OpenAtIndexUntilUsing(dirpath string, index uint64) (*WAL, error) { +// OpenNotInUse only opens the wal files that are not in use. +// Other than that, it is similar to Open. +func OpenNotInUse(dirpath string, index uint64) (*WAL, error) { return openAtIndex(dirpath, index, false) } diff --git a/wal/wal_test.go b/wal/wal_test.go index 41b24b53b..94734df10 100644 --- a/wal/wal_test.go +++ b/wal/wal_test.go @@ -90,7 +90,7 @@ func TestOpenAtIndex(t *testing.T) { } f.Close() - w, err := OpenAtIndex(dir, 0) + w, err := Open(dir, 0) if err != nil { t.Fatalf("err = %v, want nil", err) } @@ -109,7 +109,7 @@ func TestOpenAtIndex(t *testing.T) { } f.Close() - w, err = OpenAtIndex(dir, 5) + w, err = Open(dir, 5) if err != nil { t.Fatalf("err = %v, want nil", err) } @@ -126,7 +126,7 @@ func TestOpenAtIndex(t *testing.T) { t.Fatal(err) } defer os.RemoveAll(emptydir) - if _, err = OpenAtIndex(emptydir, 0); err != ErrFileNotFound { + if _, err = Open(emptydir, 0); err != ErrFileNotFound { t.Errorf("err = %v, want %v", err, ErrFileNotFound) } } @@ -219,7 +219,7 @@ func TestRecover(t *testing.T) { } w.Close() - if w, err = OpenAtIndex(p, 0); err != nil { + if w, err = Open(p, 0); err != nil { t.Fatal(err) } metadata, state, entries, err := w.ReadAll() @@ -342,7 +342,7 @@ func TestRecoverAfterCut(t *testing.T) { } for i := 0; i < 10; i++ { - w, err := OpenAtIndex(p, uint64(i)) + w, err := Open(p, uint64(i)) if err != nil { if i <= 4 { if err != ErrFileNotFound { @@ -386,7 +386,7 @@ func TestOpenAtUncommittedIndex(t *testing.T) { } w.Close() - w, err = OpenAtIndex(p, 1) + w, err = Open(p, 1) if err != nil { t.Fatal(err) }