snapshot

package
v8.24.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LatestIndex added in v8.16.5

func LatestIndex(dir string) (uint64, error)

LatestIndex returns the index of the latest snapshot in the given directory.

func RemoveAllTmpSnapshotData

func RemoveAllTmpSnapshotData(dir string) error

RemoveAllTmpSnapshotData removes all temporary Snapshot data from the directory. This process is defined as follows: for every directory in dir, if the directory is a temporary directory, remove the directory. Then remove all other files that contain the name of a temporary directory, minus the temporary suffix, as prefix.

func ResetStats

func ResetStats()

ResetStats resets the expvar stats for this module. Mostly for test purposes.

func Upgrade

func Upgrade(old, new string, logger *log.Logger) (retErr error)

Upgrade writes a copy of the 7.x-format Snapshot directory at 'old' to a new Snapshot directory at 'new'. If the upgrade is successful, the 'old' directory is removed before the function returns.

Types

type LockingSink

type LockingSink struct {
	raft.SnapshotSink
	// contains filtered or unexported fields
}

LockingSink is a wrapper around a SnapshotSink holds the CAS lock while the Sink is in use.

func NewLockingSink added in v8.24.1

func NewLockingSink(sink raft.SnapshotSink, str *Store) *LockingSink

NewLockingSink returns a new LockingSink.

func (*LockingSink) Cancel

func (s *LockingSink) Cancel() error

Cancel cancels the sink, unlocking the Store for creation of a new sink.

func (*LockingSink) Close

func (s *LockingSink) Close() error

Close closes the sink, unlocking the Store for creation of a new sink.

type LockingSnapshot added in v8.24.1

type LockingSnapshot struct {
	*os.File
	// contains filtered or unexported fields
}

LockingSnapshot is a snapshot which holds the Snapshot Store CAS while open.

func NewLockingSnapshot added in v8.24.1

func NewLockingSnapshot(fd *os.File, str *Store) *LockingSnapshot

NewLockingSink returns a new LockingSink.

func (*LockingSnapshot) Close added in v8.24.1

func (l *LockingSnapshot) Close() error

Close closes the Snapshot and releases the Snapshot Store lock.

type Sink

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

Sink is a sink for writing snapshot data to a Snapshot store.

func NewSink

func NewSink(str *Store, meta *raft.SnapshotMeta) *Sink

NewSink creates a new Sink object.

func (*Sink) Cancel

func (s *Sink) Cancel() error

Cancel cancels the snapshot. Cancel must be called if the snapshot is not going to be closed.

func (*Sink) Close

func (s *Sink) Close() error

Close closes the sink, and finalizes creation of the snapshot. It is critical that Close is called, or the snapshot will not be in place. It is OK to call Close without every calling Write. In that case the Snapshot will be finalized as usual, but will effectively be the same as the previously created snapshot.

func (*Sink) ID

func (s *Sink) ID() string

ID returns the ID of the snapshot being written.

func (*Sink) Open

func (s *Sink) Open() error

Open opens the sink for writing.

func (*Sink) Write

func (s *Sink) Write(p []byte) (n int, err error)

Write writes snapshot data to the sink. The snapshot is not in place until Close is called.

type Snapshot

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

Snapshot represents a snapshot of the database state.

func NewSnapshot

func NewSnapshot(rc io.ReadCloser) *Snapshot

NewSnapshot creates a new snapshot.

func (*Snapshot) Persist

func (s *Snapshot) Persist(sink raft.SnapshotSink) error

Persist writes the snapshot to the given sink.

func (*Snapshot) Release

func (s *Snapshot) Release()

Release releases the snapshot.

type Store

type Store struct {
	LogReaping bool
	// contains filtered or unexported fields
}

Store stores Snapshots.

func NewStore

func NewStore(dir string) (*Store, error)

NewStore returns a new Snapshot Store.

func (*Store) Create

func (s *Store) Create(version raft.SnapshotVersion, index, term uint64, configuration raft.Configuration,
	configurationIndex uint64, trans raft.Transport) (retSink raft.SnapshotSink, retErr error)

Create creates a new Sink object, ready for writing a snapshot. Sinks make certain assumptions about the state of the store, and if those assumptions were changed by another Sink writing to the store it could cause failures. Therefore we only allow 1 Sink to be in existence at a time. This shouldn't be a problem, since snapshots are taken infrequently in one at a time.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the directory where the snapshots are stored.

func (*Store) FullNeeded

func (s *Store) FullNeeded() (bool, error)

FullNeeded returns true if a full snapshot is needed.

func (*Store) List

func (s *Store) List() ([]*raft.SnapshotMeta, error)

List returns a list of all the snapshots in the Store. In practice, this will at most be a list of 1, and that will be the newest snapshot available.

func (*Store) Open

func (s *Store) Open(id string) (_ *raft.SnapshotMeta, _ io.ReadCloser, retErr error)

Open opens the snapshot with the given ID. Close() must be called on the snapshot when finished with it.

func (*Store) Reap

func (s *Store) Reap() (retN int, retErr error)

Reap reaps all snapshots, except the most recent one. Returns the number of snapshots reaped. This function does not take the Store CAS lock, and so it is up to the caller to ensure no other operations are happening on the Store.

func (*Store) SetFullNeeded

func (s *Store) SetFullNeeded() error

SetFullNeeded sets the flag that indicates a full snapshot is needed. This flag will be cleared when a snapshot is successfully persisted.

func (*Store) Stats

func (s *Store) Stats() (map[string]interface{}, error)

Stats returns stats about the Snapshot Store. This function may return an error if the Store is in an inconsistent state. In that case the stats returned may be incomplete or invalid.

Jump to

Keyboard shortcuts

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