snapshot

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MPL-2.0 Imports: 16 Imported by: 5

README

raft-snapshot

Documentation

Overview

The archive utilities manage the internal format of a snapshot, which is a tar file with the following contents:

meta.json - JSON-encoded snapshot metadata from Raft state.bin - Encoded snapshot data from Raft SHA256SUMS - SHA-256 sums of the above two files

The integrity information is automatically created and checked, and a failure there just looks like an error to the caller.

snapshot manages the interactions between Consul and Raft in order to take and restore snapshots for disaster recovery. The internal format of a snapshot is simply a tar file, as described in archive.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse added in v1.0.2

func Parse(in io.Reader, out io.Writer) (*raft.SnapshotMeta, error)

Parse reads the snapshot from the input reader, decompresses it, and pipes the binary data to the output writer.

func Restore

func Restore(logger hclog.Logger, in io.Reader, r *raft.Raft) error

Restore takes the snapshot from the reader and attempts to apply it to the given Raft instance.

func RestoreWithSealer added in v1.0.1

func RestoreWithSealer(logger hclog.Logger, in io.Reader, r *raft.Raft, sealer Sealer) error

func Verify

func Verify(in io.Reader) (*raft.SnapshotMeta, error)

Verify takes the snapshot from the reader and verifies its contents.

func Write added in v1.0.3

func Write(logger hclog.Logger, r *raft.Raft, sealer Sealer, w io.Writer) error

Write takes a state snapshot of the given Raft instance into w.

func WriteToTempFile added in v1.0.1

func WriteToTempFile(logger hclog.Logger, in io.Reader, metadata *raft.SnapshotMeta) (*os.File, func(), error)

func WriteToTempFileWithSealer added in v1.0.1

func WriteToTempFileWithSealer(logger hclog.Logger, in io.Reader, metadata *raft.SnapshotMeta, sealer Sealer) (*os.File, func(), error)

Types

type Sealer added in v1.0.1

type Sealer interface {
	Seal(context.Context, []byte) ([]byte, error)
	Open(context.Context, []byte) ([]byte, error)
}

Sealer is used to seal and open the SHASUM file inside the archive.

type Snapshot

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

Snapshot is a structure that holds state about a temporary file that is used to hold a snapshot. By using an intermediate file we avoid holding everything in memory.

func New

func New(logger hclog.Logger, r *raft.Raft) (*Snapshot, error)

New takes a state snapshot of the given Raft instance into a temporary file and returns an object that gives access to the file as an io.Reader. You must arrange to call Close() on the returned object or else you will leak a temporary file.

func NewWithSealer added in v1.0.1

func NewWithSealer(logger hclog.Logger, r *raft.Raft, sealer Sealer) (*Snapshot, error)

func (*Snapshot) Checksum added in v1.0.2

func (s *Snapshot) Checksum() string

Checksum returns the checksum for the snapshot in the <algo>=<base64 of hash> format e.g. "sha-256=gPelGB7..."

func (*Snapshot) Close

func (s *Snapshot) Close() error

Close closes the snapshot and removes any temporary storage associated with it. You must arrange to call this whenever NewSnapshot() has been called successfully. This is safe to call on a nil snapshot.

func (*Snapshot) Index

func (s *Snapshot) Index() uint64

Index returns the index of the snapshot. This is safe to call on a nil snapshot, it will just return 0.

func (*Snapshot) Read

func (s *Snapshot) Read(p []byte) (n int, err error)

Read passes through to the underlying snapshot file. This is safe to call on a nil snapshot, it will just return an EOF.

func (*Snapshot) Size added in v1.0.2

func (s *Snapshot) Size() (int64, error)

Size returns the file size of the snapshot archive.

Jump to

Keyboard shortcuts

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