diff --git a/etcdserver/snapshot_merge.go b/etcdserver/snapshot_merge.go index f6dac7245..c09a4051a 100644 --- a/etcdserver/snapshot_merge.go +++ b/etcdserver/snapshot_merge.go @@ -20,7 +20,7 @@ import ( "github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/snap" - dstorage "github.com/coreos/etcd/storage" + "github.com/coreos/etcd/storage/backend" ) // createMergedSnapshotMessage creates a snapshot message that contains: raft status (term, conf), @@ -40,7 +40,7 @@ func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapi uint64, } // get a snapshot of v3 KV as readCloser - rc := newSnapshotReaderCloser(s.kv.Snapshot()) + rc := newSnapshotReaderCloser(s.be.Snapshot()) // put the []byte snapshot of store into raft snapshot and return the merged snapshot with // KV readCloser snapshot. @@ -57,7 +57,7 @@ func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapi uint64, return *snap.NewMessage(m, rc) } -func newSnapshotReaderCloser(snapshot dstorage.Snapshot) io.ReadCloser { +func newSnapshotReaderCloser(snapshot backend.Snapshot) io.ReadCloser { pr, pw := io.Pipe() go func() { _, err := snapshot.WriteTo(pw) diff --git a/storage/backend/backend.go b/storage/backend/backend.go index 9f5ba33a7..2f77b7e90 100644 --- a/storage/backend/backend.go +++ b/storage/backend/backend.go @@ -105,6 +105,7 @@ func (b *backend) ForceCommit() { } func (b *backend) Snapshot() Snapshot { + b.batchTx.Commit() tx, err := b.db.Begin(false) if err != nil { log.Fatalf("storage: cannot begin tx (%s)", err) diff --git a/storage/kv.go b/storage/kv.go index 134703122..2833d1bc4 100644 --- a/storage/kv.go +++ b/storage/kv.go @@ -20,8 +20,6 @@ import ( "github.com/coreos/etcd/storage/storagepb" ) -type Snapshot backend.Snapshot - type KV interface { // Rev returns the current revision of the KV. Rev() int64 @@ -65,9 +63,6 @@ type KV interface { // This method is designed for consistency checking purpose. Hash() (uint32, error) - // Snapshot snapshots the full KV store. - Snapshot() Snapshot - // Commit commits txns into the underlying backend. Commit() diff --git a/storage/kv_test.go b/storage/kv_test.go index 130db3d2d..01ef5730e 100644 --- a/storage/kv_test.go +++ b/storage/kv_test.go @@ -714,7 +714,7 @@ func TestKVSnapshot(t *testing.T) { } defer os.Remove(newPath) - snap := s.Snapshot() + snap := s.b.Snapshot() defer snap.Close() _, err = snap.WriteTo(f) if err != nil { diff --git a/storage/kvstore.go b/storage/kvstore.go index d83533472..6a60c6557 100644 --- a/storage/kvstore.go +++ b/storage/kvstore.go @@ -235,11 +235,6 @@ func (s *store) Hash() (uint32, error) { return s.b.Hash() } -func (s *store) Snapshot() Snapshot { - s.b.ForceCommit() - return s.b.Snapshot() -} - func (s *store) Commit() { s.b.ForceCommit() } func (s *store) Restore(b backend.Backend) error {