snap

package
v0.0.0-...-dc80162 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package snap stores raft nodes' states with snapshots.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSnapshot    = errors.New("snap: no available snapshot")
	ErrEmptySnapshot = errors.New("snap: empty snapshot")
	ErrCRCMismatch   = errors.New("snap: crc mismatch")
)
View Source
var ErrNoDBSnapshot = errors.New("snap: snapshot file doesn't exist")

Functions

func Read

func Read(snapname string) (*raftpb.Snapshot, error)

Read reads the snapshot named by snapname and returns the snapshot.

Types

type Message

type Message struct {
	raftpb.Message
	ReadCloser io.ReadCloser
	TotalSize  int64
	// contains filtered or unexported fields
}

Message is a struct that contains a raft Message and a ReadCloser. The type of raft message MUST be MsgSnap, which contains the raft meta-data and an additional data []byte field that contains the snapshot of the actual state machine. Message contains the ReadCloser field for handling large snapshot. This avoid copying the entire snapshot into a byte array, which consumes a lot of memory.

User of Message should close the Message after sending it.

func NewMessage

func NewMessage(rs raftpb.Message, rc io.ReadCloser, rcSize int64) *Message

func (Message) CloseNotify

func (m Message) CloseNotify() <-chan bool

CloseNotify returns a channel that receives a single value when the message sent is finished. true indicates the sent is successful.

func (Message) CloseWithError

func (m Message) CloseWithError(err error)

type Snapshotter

type Snapshotter struct {
	// contains filtered or unexported fields
}

func New

func New(dir string) *Snapshotter

func (*Snapshotter) DBFilePath

func (s *Snapshotter) DBFilePath(id uint64) (string, error)

DBFilePath returns the file path for the snapshot of the database with 该方法是在dbFilePath()方法之上实现的,用于查找指定的快照db文件 given id. If the snapshot does not exist, it returns error.

func (*Snapshotter) Load

func (s *Snapshotter) Load() (*raftpb.Snapshot, error)

该方法会读取指定目录下的全部快照文件,并查找其中最近的可用快照文件,然后通过Snapshotter.loadSnap()方法加载其中的快照数据。

func (*Snapshotter) SaveDBFrom

func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) (int64, error)

SaveDBFrom saves snapshot of the database from the given reader. It guarantees the save operation is atomic.

func (*Snapshotter) SaveSnap

func (s *Snapshotter) SaveSnap(snapshot raftpb.Snapshot) error

该方法的主要功能是将快照数据保存到快照文件中,其底层是通过调用save()方法实现的。

Directories

Path Synopsis
Package snappb is a generated protocol buffer package.
Package snappb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL