コード例 #1
0
ファイル: fragmentstorage.go プロジェクト: syhao/sunbase
// ApplySnapshot overwrites the contents of this Storage object with
// those of the given snapshot.
func (fs *FragmentStorage) ApplySnapshot(snap pb.Snapshot) error {
	fs.Lock()
	defer fs.Unlock()
	data, err := snap.Marshal()
	if err != nil {
		return err
	}
	fs.fsnapshot.Seek(0, 0)
	_, err = fmt.Fprintln(fs.fsnapshot, data)
	if err != nil {
		return err
	}
	entries := []pb.Entry{{Term: snap.Metadata.Term, Index: snap.Metadata.Index}}
	return fs.Append(entries)
}