فهرست منبع

wal: wal.OpenFromIndex -> wal.OpenAtIndex

The first entry read from the wal should be the index provided. This
name makes that more clear.
Brandon Philips 11 سال پیش
والد
کامیت
884c702512
4فایلهای تغییر یافته به همراه13 افزوده شده و 13 حذف شده
  1. 1 1
      main.go
  2. 1 1
      wal/doc.go
  3. 5 5
      wal/wal.go
  4. 6 6
      wal/wal_test.go

+ 1 - 1
main.go

@@ -107,7 +107,7 @@ func startRaft(id int64, peerIDs []int64, waldir string) (raft.Node, *wal.WAL) {
 
 	// restart a node from previous wal
 	// TODO(xiangli): check snapshot; not open from zero
-	w, err := wal.OpenFromIndex(waldir, 0)
+	w, err := wal.OpenAtIndex(waldir, 0)
 	if err != nil {
 		log.Fatal(err)
 	}

+ 1 - 1
wal/doc.go

@@ -44,7 +44,7 @@ Cut is issues 0x10 entries later then the file will be called:
 
 At a later time a WAL can be opened at a particular raft index:
 
-	w, err := wal.OpenFromIndex("/var/lib/etcd", 0)
+	w, err := wal.OpenAtIndex("/var/lib/etcd", 0)
 	...
 
 Additional items cannot be Saved to this WAL until all of the items from 0 to

+ 5 - 5
wal/wal.go

@@ -92,11 +92,11 @@ func Create(dirpath string) (*WAL, error) {
 	return w, nil
 }
 
-// OpenFromIndex opens the WAL files containing all the entries after
-// the given index.
-// The returned WAL is ready to read. The WAL cannot be appended to before
-// reading out all of its previous records.
-func OpenFromIndex(dirpath string, index int64) (*WAL, error) {
+// OpenAtIndex opens the WAL at the given index.
+// 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 int64) (*WAL, error) {
 	log.Printf("path=%s wal.load index=%d", dirpath, index)
 	names, err := readDir(dirpath)
 	if err != nil {

+ 6 - 6
wal/wal_test.go

@@ -65,7 +65,7 @@ func TestNewForInitedDir(t *testing.T) {
 	}
 }
 
-func TestOpenFromIndex(t *testing.T) {
+func TestOpenAtIndex(t *testing.T) {
 	dir, err := ioutil.TempDir(os.TempDir(), "waltest")
 	if err != nil {
 		t.Fatal(err)
@@ -78,7 +78,7 @@ func TestOpenFromIndex(t *testing.T) {
 	}
 	f.Close()
 
-	w, err := OpenFromIndex(dir, 0)
+	w, err := OpenAtIndex(dir, 0)
 	if err != nil {
 		t.Fatalf("err = %v, want nil", err)
 	}
@@ -94,7 +94,7 @@ func TestOpenFromIndex(t *testing.T) {
 	}
 	f.Close()
 
-	w, err = OpenFromIndex(dir, 5)
+	w, err = OpenAtIndex(dir, 5)
 	if err != nil {
 		t.Fatalf("err = %v, want nil", err)
 	}
@@ -108,7 +108,7 @@ func TestOpenFromIndex(t *testing.T) {
 		t.Fatal(err)
 	}
 	defer os.RemoveAll(emptydir)
-	if _, err = OpenFromIndex(emptydir, 0); err != ErrNotFound {
+	if _, err = OpenAtIndex(emptydir, 0); err != ErrNotFound {
 		t.Errorf("err = %v, want %v", err, ErrNotFound)
 	}
 }
@@ -176,7 +176,7 @@ func TestRecover(t *testing.T) {
 	}
 	w.Close()
 
-	if w, err = OpenFromIndex(p, 0); err != nil {
+	if w, err = OpenAtIndex(p, 0); err != nil {
 		t.Fatal(err)
 	}
 	id, state, entries, err := w.ReadAll()
@@ -301,7 +301,7 @@ func TestRecoverAfterCut(t *testing.T) {
 	}
 
 	for i := 0; i < 10; i++ {
-		w, err := OpenFromIndex(p, int64(i))
+		w, err := OpenAtIndex(p, int64(i))
 		if i <= 3 {
 			if err != ErrNotFound {
 				t.Errorf("#%d: err = %v, want %v", i, err, ErrNotFound)