Documentation
¶
Index ¶
- Constants
- type BlockStore
- type DBSnapshotter
- type NamespaceManager
- type Snapshot
- type SnapshotChunkReq
- type SnapshotConfig
- type SnapshotKey
- type SnapshotMetadata
- type SnapshotReq
- type SnapshotStore
- func (s *SnapshotStore) CreateSnapshot(ctx context.Context, height uint64, snapshotID string, ...) error
- func (s *SnapshotStore) Enabled() bool
- func (s *SnapshotStore) GetSnapshot(height uint64, _ uint32) *Snapshot
- func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
- func (s *SnapshotStore) ListSnapshots() []*Snapshot
- func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkIdx uint32) ([]byte, error)
- func (s *SnapshotStore) RegisterSnapshot(snapshot *Snapshot) error
- func (s *SnapshotStore) RegisterSnapshotStreamHandlers(ctx context.Context, host host.Host, discovery discovery.Discovery)
- type Snapshotter
Constants ¶
const ( DiscoverSnapshotsMsg = "discover_snapshots" ProtocolIDSnapshotCatalog protocol.ID = "/kwil/snapcat/1.0.0" ProtocolIDSnapshotChunk protocol.ID = "/kwil/snapchunk/1.0.0" ProtocolIDSnapshotMeta protocol.ID = "/kwil/snapmeta/1.0.0" SnapshotCatalogNS = "snapshot-catalog" // namespace on which snapshot catalogs are advertised )
const ( DefaultSnapshotFormat = 0 CreateSchema = "CREATE SCHEMA" CreateTable = "CREATE TABLE" CreateFunction = "CREATE FUNCTION" )
const HashLen int = 32
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockStore ¶
type DBSnapshotter ¶
type NamespaceManager ¶
type NamespaceManager interface {
ListPostgresSchemasToDump() []string
}
type Snapshot ¶
type Snapshot struct { Height uint64 `json:"height"` Format uint32 `json:"format"` ChunkHashes [][HashLen]byte `json:"chunk_hashes"` ChunkCount uint32 `json:"chunk_count"` SnapshotHash []byte `json:"hash"` SnapshotSize uint64 `json:"size"` }
Snapshot is the header of a snapshot file representing the snapshot of the database at a certain height. It contains the height, format, chunk count, hash, size, and name of the snapshot. WARNING: This struct CAN NOT be changed without breaking functionality, since it is used for communication between nodes.
func (*Snapshot) MarshalBinary ¶
func (*Snapshot) UnmarshalBinary ¶
type SnapshotChunkReq ¶
type SnapshotChunkReq struct { Height uint64 Format uint32 Index uint32 Hash types.Hash // TODO: Is this required? maybe providers serve the chunk only if the snapshot hash matches }
SnapshotChunkReq is for ProtocolIDSnapshotChunk "/kwil/snapchunk/1.0.0"
func (SnapshotChunkReq) MarshalBinary ¶
func (r SnapshotChunkReq) MarshalBinary() ([]byte, error)
func (*SnapshotChunkReq) ReadFrom ¶
func (r *SnapshotChunkReq) ReadFrom(rd io.Reader) (int64, error)
func (*SnapshotChunkReq) UnmarshalBinary ¶
func (r *SnapshotChunkReq) UnmarshalBinary(data []byte) error
type SnapshotConfig ¶
type SnapshotKey ¶
SnapshotKey is a snapshot key used for lookups.
type SnapshotMetadata ¶
type SnapshotMetadata struct { Height uint64 `json:"height"` Format uint32 `json:"format"` Chunks uint32 `json:"chunk_count"` Hash []byte `json:"hash"` Size uint64 `json:"size"` ChunkHashes [][32]byte `json:"chunk_hashes"` AppHash []byte `json:"app_hash"` }
func (*SnapshotMetadata) Key ¶
func (s *SnapshotMetadata) Key() SnapshotKey
Key generates a snapshot key, used for lookups. It takes into account not only the height and format, but also the chunks, snapshot hash and chunk hashes in case peers have generated snapshots in a non-deterministic manner. All fields must be equal for the snapshot to be considered the same.
func (*SnapshotMetadata) String ¶
func (sm *SnapshotMetadata) String() string
type SnapshotReq ¶
SnapshotReq is for ProtocolIDSnapshotMeta "/kwil/snapmeta/1.0.0"
func (SnapshotReq) MarshalBinary ¶
func (r SnapshotReq) MarshalBinary() ([]byte, error)
func (*SnapshotReq) UnmarshalBinary ¶
func (r *SnapshotReq) UnmarshalBinary(data []byte) error
type SnapshotStore ¶
type SnapshotStore struct {
// contains filtered or unexported fields
}
func NewSnapshotStore ¶
func NewSnapshotStore(cfg *SnapshotConfig, bs BlockStore, ns NamespaceManager, logger log.Logger) (*SnapshotStore, error)
func (*SnapshotStore) CreateSnapshot ¶
func (s *SnapshotStore) CreateSnapshot(ctx context.Context, height uint64, snapshotID string, schemas, excludedTables []string, excludeTableData []string) error
CreateSnapshot creates a new snapshot at the given height and snapshot ID. SnapshotStore ensures that the number of snapshots does not exceed the maximum configured snapshots. If exceeds, it deletes the oldest snapshot. It takes a list of schemas, excludedTables and excludeTableData args to specify the contents of the snapshot. schemas: list of schemas to include in the snapshot excludedTables: list of tables to exclude from the snapshot excludeTableData: list of tables to include schema but exclude data from the snapshot
func (*SnapshotStore) Enabled ¶
func (s *SnapshotStore) Enabled() bool
func (*SnapshotStore) GetSnapshot ¶
func (s *SnapshotStore) GetSnapshot(height uint64, _ uint32) *Snapshot
func (*SnapshotStore) IsSnapshotDue ¶
func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
IsSnapshotDue checks if a snapshot is due at the given height.
func (*SnapshotStore) ListSnapshots ¶
func (s *SnapshotStore) ListSnapshots() []*Snapshot
List snapshots lists all the registered snapshots in the snapshot store.
func (*SnapshotStore) LoadSnapshotChunk ¶
func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkIdx uint32) ([]byte, error)
LoadSnapshotChunk loads a snapshot chunk at the given height and chunk index of given format. It returns the snapshot chunk as a byte slice of max size 16MB. errors if the chunk of chunkIndex corresponding to snapshot at given height and format does not exist.
func (*SnapshotStore) RegisterSnapshot ¶
func (s *SnapshotStore) RegisterSnapshot(snapshot *Snapshot) error
RegisterSnapshot registers the existing snapshot in the snapshot store. It ensures that the number of snapshots does not exceed the maximum configured snapshots. If exceeds, it deletes the oldest snapshot.
func (*SnapshotStore) RegisterSnapshotStreamHandlers ¶
func (s *SnapshotStore) RegisterSnapshotStreamHandlers(ctx context.Context, host host.Host, discovery discovery.Discovery)
RegisterSnapshotStreamHandlers registers the snapshot stream handlers if snapshotting is enabled.
type Snapshotter ¶
type Snapshotter struct {
// contains filtered or unexported fields
}
func NewSnapshotter ¶
func NewSnapshotter(cfg *config.DBConfig, dir string, namespaceMgr NamespaceManager, logger log.Logger) *Snapshotter