Beispiel #1
0
func newSnapshotReaderCloser(snapshot dstorage.Snapshot) io.ReadCloser {
	pr, pw := io.Pipe()
	go func() {
		_, err := snapshot.WriteTo(pw)
		pw.CloseWithError(err)
		snapshot.Close()
	}()
	return pr
}
Beispiel #2
0
func newSnapshot(r raftpb.Snapshot, kv dstorage.Snapshot) *snapshot {
	done := make(chan struct{})
	pr, pw := io.Pipe()
	go func() {
		_, err := kv.WriteTo(pw)
		pw.CloseWithError(err)
		kv.Close()
		close(done)
	}()
	return &snapshot{
		r:          r,
		ReadCloser: pr,
		done:       done,
	}
}