wal: rename openAtIndex -> open; OpenAtIndexUntilUsing -> openNotInUse

release-2.0
Xiang Li 2014-12-14 19:33:06 -08:00
parent f538cba272
commit 53bf7e4b5e
4 changed files with 13 additions and 11 deletions

View File

@ -67,7 +67,7 @@ func handleBackup(c *cli.Context) {
} }
} }
w, err := wal.OpenAtIndexUntilUsing(srcWAL, index) w, err := wal.OpenNotInUse(srcWAL, index)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -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) { func readWAL(waldir string, index uint64) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) {
var err error 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) log.Fatalf("etcdserver: open wal error: %v", err)
} }
var wmetadata []byte var wmetadata []byte

View File

@ -117,17 +117,19 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
return w, nil 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 // The index SHOULD have been previously committed to the WAL, or the following
// ReadAll will fail. // ReadAll will fail.
// The returned WAL is ready to read and the first record will be the given // 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 // index. The WAL cannot be appended to before reading out all of its
// previous records. // previous records.
func OpenAtIndex(dirpath string, index uint64) (*WAL, error) { func Open(dirpath string, index uint64) (*WAL, error) {
return openAtIndex(dirpath, index, true) 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) return openAtIndex(dirpath, index, false)
} }

View File

@ -90,7 +90,7 @@ func TestOpenAtIndex(t *testing.T) {
} }
f.Close() f.Close()
w, err := OpenAtIndex(dir, 0) w, err := Open(dir, 0)
if err != nil { if err != nil {
t.Fatalf("err = %v, want nil", err) t.Fatalf("err = %v, want nil", err)
} }
@ -109,7 +109,7 @@ func TestOpenAtIndex(t *testing.T) {
} }
f.Close() f.Close()
w, err = OpenAtIndex(dir, 5) w, err = Open(dir, 5)
if err != nil { if err != nil {
t.Fatalf("err = %v, want nil", err) t.Fatalf("err = %v, want nil", err)
} }
@ -126,7 +126,7 @@ func TestOpenAtIndex(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(emptydir) 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) t.Errorf("err = %v, want %v", err, ErrFileNotFound)
} }
} }
@ -219,7 +219,7 @@ func TestRecover(t *testing.T) {
} }
w.Close() w.Close()
if w, err = OpenAtIndex(p, 0); err != nil { if w, err = Open(p, 0); err != nil {
t.Fatal(err) t.Fatal(err)
} }
metadata, state, entries, err := w.ReadAll() metadata, state, entries, err := w.ReadAll()
@ -342,7 +342,7 @@ func TestRecoverAfterCut(t *testing.T) {
} }
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
w, err := OpenAtIndex(p, uint64(i)) w, err := Open(p, uint64(i))
if err != nil { if err != nil {
if i <= 4 { if i <= 4 {
if err != ErrFileNotFound { if err != ErrFileNotFound {
@ -386,7 +386,7 @@ func TestOpenAtUncommittedIndex(t *testing.T) {
} }
w.Close() w.Close()
w, err = OpenAtIndex(p, 1) w, err = Open(p, 1)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }