Documentation ¶
Index ¶
- Variables
- func DrainChunks(chunks <-chan io.ReadCloser)
- func IsFormatSupported(snapshotter ExtensionSnapshotter, format uint32) bool
- func ValidRestoreHeight(format uint32, height uint64) error
- type ChunkReader
- type ChunkWriter
- type CommitSnapshotter
- type ExtensionPayloadReader
- type ExtensionPayloadWriter
- type ExtensionSnapshotter
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) Create(height uint64) (*types.Snapshot, error)
- func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error
- func (m *Manager) EndMigration(commitSnapshotter CommitSnapshotter)
- func (m *Manager) GetInterval() uint64
- func (m *Manager) GetKeepRecent() uint32
- func (m *Manager) GetSnapshotBlockRetentionHeights() int64
- func (m *Manager) List() ([]*types.Snapshot, error)
- func (m *Manager) LoadChunk(height uint64, format, chunk uint32) ([]byte, error)
- func (m *Manager) Prune(retain uint32) (uint64, error)
- func (m *Manager) RegisterExtensions(extensions ...ExtensionSnapshotter) error
- func (m *Manager) Restore(snapshot types.Snapshot) error
- func (m *Manager) RestoreChunk(chunk []byte) (bool, error)
- func (m *Manager) RestoreLocalSnapshot(height uint64, format uint32) error
- func (m *Manager) SnapshotIfApplicable(height int64)
- type SnapshotOptions
- type Store
- func (s *Store) Delete(height uint64, format uint32) error
- func (s *Store) Get(height uint64, format uint32) (*types.Snapshot, error)
- func (s *Store) GetLatest() (*types.Snapshot, error)
- func (s *Store) List() ([]*types.Snapshot, error)
- func (s *Store) Load(height uint64, format uint32) (*types.Snapshot, <-chan io.ReadCloser, error)
- func (s *Store) LoadChunk(height uint64, format, chunk uint32) (io.ReadCloser, error)
- func (s *Store) MigrateFromV1(db corestore.KVStore) error
- func (s *Store) PathChunk(height uint64, format, chunk uint32) string
- func (s *Store) Prune(retain uint32) (uint64, error)
- func (s *Store) Save(height uint64, format uint32, chunks <-chan io.ReadCloser) (*types.Snapshot, error)
- type StreamReader
- type StreamWriter
- type WriteCloser
Constants ¶
This section is empty.
Variables ¶
var ErrOptsZeroSnapshotInterval = errors.New("snapshot-interval must not be 0")
Functions ¶
func DrainChunks ¶
func DrainChunks(chunks <-chan io.ReadCloser)
DrainChunks drains and closes all remaining chunks from a chunk channel.
func IsFormatSupported ¶
func IsFormatSupported(snapshotter ExtensionSnapshotter, format uint32) bool
IsFormatSupported returns if the snapshotter supports restoration from given format.
func ValidRestoreHeight ¶
ValidRestoreHeight will check height is valid for snapshot restore or not
Types ¶
type ChunkReader ¶
type ChunkReader struct {
// contains filtered or unexported fields
}
ChunkReader reads chunks from a channel of io.ReadClosers and outputs them as an io.Reader
func NewChunkReader ¶
func NewChunkReader(ch <-chan io.ReadCloser) *ChunkReader
NewChunkReader creates a new ChunkReader.
type ChunkWriter ¶
type ChunkWriter struct {
// contains filtered or unexported fields
}
ChunkWriter reads an input stream, splits it into fixed-size chunks, and writes them to a sequence of io.ReadClosers via a channel.
func NewChunkWriter ¶
func NewChunkWriter(ch chan<- io.ReadCloser, chunkSize uint64) *ChunkWriter
NewChunkWriter creates a new ChunkWriter. If chunkSize is 0, no chunking will be done.
func (*ChunkWriter) CloseWithError ¶
func (w *ChunkWriter) CloseWithError(err error)
CloseWithError closes the writer and sends an error to the reader.
type CommitSnapshotter ¶
type CommitSnapshotter interface { // Snapshot writes a snapshot of the commitment state at the given version. Snapshot(version uint64, protoWriter protoio.Writer) error // Restore restores the commitment state from the snapshot reader. Restore(version uint64, format uint32, protoReader protoio.Reader) (types.SnapshotItem, error) }
CommitSnapshotter defines an API for creating and restoring snapshots of the commitment state.
type ExtensionPayloadReader ¶
ExtensionPayloadReader read extension payloads, it returns io.EOF when reached either end of stream or the extension boundaries.
type ExtensionPayloadWriter ¶
ExtensionPayloadWriter is a helper to write extension payloads to underlying stream.
type ExtensionSnapshotter ¶
type ExtensionSnapshotter interface { // SnapshotName returns the name of snapshotter, it should be unique in the manager. SnapshotName() string // SnapshotFormat returns the default format the extension snapshotter use to encode the // payloads when taking a snapshot. // It's defined within the extension, different from the global format for the whole state-sync snapshot. SnapshotFormat() uint32 // SupportedFormats returns a list of formats it can restore from. SupportedFormats() []uint32 // SnapshotExtension writes extension payloads into the underlying protobuf stream. SnapshotExtension(height uint64, payloadWriter ExtensionPayloadWriter) error // RestoreExtension restores an extension state snapshot, // the payload reader returns `io.EOF` when reached the extension boundaries. RestoreExtension(height uint64, format uint32, payloadReader ExtensionPayloadReader) error }
ExtensionSnapshotter is an extension Snapshotter that is appended to the snapshot stream. ExtensionSnapshotter has an unique name and manages it's own internal formats.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages snapshot and restore operations for an app, making sure only a single long-running operation is in progress at any given time, and provides convenience methods mirroring the ABCI interface.
Although the ABCI interface (and this manager) passes chunks as byte slices, the internal snapshot/restore APIs use IO streams (i.e. chan io.ReadCloser), for two reasons:
In the future, ABCI should support streaming. Consider e.g. InitChain during chain upgrades, which currently passes the entire chain state as an in-memory byte slice. https://github.com/tendermint/tendermint/issues/5184
io.ReadCloser streams automatically propagate IO errors, and can pass arbitrary errors via io.Pipe.CloseWithError().
func NewManager ¶
func NewManager(store *Store, opts SnapshotOptions, commitSnapshotter CommitSnapshotter, extensions map[string]ExtensionSnapshotter, logger corelog.Logger) *Manager
NewManager creates a new manager.
func (*Manager) CreateMigration ¶
func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error
CreateMigration creates a migration snapshot and writes it to the given writer. It is used to migrate the state from the original store to the store/v2.
func (*Manager) EndMigration ¶
func (m *Manager) EndMigration(commitSnapshotter CommitSnapshotter)
EndMigration ends the migration operation. It will replace the current commitSnapshotter with the new one.
func (*Manager) GetInterval ¶
GetInterval returns snapshot interval represented in heights.
func (*Manager) GetKeepRecent ¶
GetKeepRecent returns snapshot keep-recent represented in heights.
func (*Manager) GetSnapshotBlockRetentionHeights ¶
GetSnapshotBlockRetentionHeights returns the number of heights needed for block retention. Blocks since the oldest available snapshot must be available for state sync nodes to catch up (oldest because a node may be restoring an old snapshot while a new snapshot was taken).
func (*Manager) List ¶
List lists snapshots, mirroring ABCI ListSnapshots. It can be concurrent with other operations.
func (*Manager) LoadChunk ¶
LoadChunk loads a chunk into a byte slice, mirroring ABCI LoadChunk. It can be called concurrently with other operations. If the chunk does not exist, nil is returned.
func (*Manager) RegisterExtensions ¶
func (m *Manager) RegisterExtensions(extensions ...ExtensionSnapshotter) error
RegisterExtensions register extension snapshotters to manager
func (*Manager) Restore ¶
Restore begins an async snapshot restoration, mirroring ABCI OfferSnapshot. Chunks must be fed via RestoreChunk() until the restore is complete or a chunk fails.
func (*Manager) RestoreChunk ¶
RestoreChunk adds a chunk to an active snapshot restoration, mirroring ABCI ApplySnapshotChunk. Chunks must be given until the restore is complete, returning true, or a chunk errors.
func (*Manager) RestoreLocalSnapshot ¶
RestoreLocalSnapshot restores app state from a local snapshot.
func (*Manager) SnapshotIfApplicable ¶
SnapshotIfApplicable takes a snapshot of the current state if we are on a snapshot height. It also prunes any old snapshots.
type SnapshotOptions ¶
type SnapshotOptions struct { // Interval defines at which heights the snapshot is taken. Interval uint64 // KeepRecent defines how many snapshots to keep in heights. KeepRecent uint32 }
SnapshotOptions defines the snapshot strategy used when determining which heights are snapshotted for state sync.
func NewSnapshotOptions ¶
func NewSnapshotOptions(interval uint64, keepRecent uint32) SnapshotOptions
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a snapshot store, containing snapshot metadata and binary chunks.
func (*Store) Load ¶
Load loads a snapshot (both metadata and binary chunks). The chunks must be consumed and closed. Returns nil if the snapshot does not exist.
func (*Store) LoadChunk ¶
LoadChunk loads a chunk from disk, or returns nil if it does not exist. The caller must call Close() on it when done.
type StreamReader ¶
type StreamReader struct {
// contains filtered or unexported fields
}
StreamReader set up a restore stream pipeline chan io.ReadCloser -> chunkReader -> zlib -> delimited Protobuf -> ExportNode
func NewStreamReader ¶
func NewStreamReader(chunks <-chan io.ReadCloser) (*StreamReader, error)
NewStreamReader set up a restore stream pipeline.
func (*StreamReader) Close ¶
func (sr *StreamReader) Close() error
Close implements io.Closer interface
type StreamWriter ¶
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter set up a stream pipeline to serialize snapshot nodes: Exported Items -> delimited Protobuf -> zlib -> buffer -> chunkWriter -> chan io.ReadCloser
func NewStreamWriter ¶
func NewStreamWriter(ch chan<- io.ReadCloser) *StreamWriter
NewStreamWriter set up a stream pipeline to serialize snapshot DB records.
func (*StreamWriter) Close ¶
func (sw *StreamWriter) Close() error
Close implements io.Closer interface
func (*StreamWriter) CloseWithError ¶
func (sw *StreamWriter) CloseWithError(err error)
CloseWithError pass error to chunkWriter
type WriteCloser ¶
type WriteCloser interface { protoio.WriteCloser // CloseWithError closes the writer and sends an error to the reader. CloseWithError(err error) }