snapshoter

package
v1.9.27 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package snapshoter This package provides the ability to snapshot all the schedules in the scheduler job store and persist them in the DB in GOB binary format. Also it provides ability to bootstrap the scheduler from this snapshot so that the scheduler can run catchup for all the schedules from the snapshoted time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	Scope                      promutils.Scope
	SnapshotSaveErrCounter     prometheus.Counter
	SnapshotCreationErrCounter prometheus.Counter
}

type Persistence

type Persistence interface {
	// Save Run(ctx context.Context)
	// Save saves the snapshot to the storage in a serialized form.
	Save(ctx context.Context, writer Writer, snapshot Snapshot)
	// Read reads the serialized snapshot from the storage and deserializes to its in memory format.
	Read(ctx context.Context, reader Reader) (Snapshot, error)
}

Persistence allows to read and save the serialized form of the snapshot from a storage. Currently we have DB implementation for it.

type Reader

type Reader interface {
	// ReadSnapshot reads the snapshot from the reader
	ReadSnapshot(reader io.Reader) (Snapshot, error)
}

Reader provides an interface to read the snapshot and deserialize it to its in memory format.

type Snapshot

type Snapshot interface {
	// GetLastExecutionTime of the schedule given by the key
	GetLastExecutionTime(key string) *time.Time
	// UpdateLastExecutionTime of the schedule given by key to the lastExecTime
	UpdateLastExecutionTime(key string, lastExecTime *time.Time)
	// CreateSnapshot creates the snapshot of all the schedules and there execution times.
	Serialize() ([]byte, error)
	// BootstrapFrom bootstraps the snapshot from a byte array
	Deserialize(snapshot []byte) error
	// GetVersion gets the version number of snapshot written
	GetVersion() int
	// IsEmpty returns true if the snapshot contains no schedules
	IsEmpty() bool
	// Create an empty snapshot
	Create() Snapshot
}

Snapshot used by the scheduler for creating, updating and reading snapshots of the schedules.

type SnapshotV1

type SnapshotV1 struct {
	// LastTimes map of the schedule name to last execution timestamp
	LastTimes map[string]*time.Time
}

SnapshotV1 stores in the inmemory states of the schedules and there last execution timestamps. This map is created periodically from the jobstore of the gocron_wrapper and written to the DB. During bootup the serialized version of it is read from the DB and the schedules are initialized from it. V1 version so that in future if we add more fields for extending the functionality then this provides a backward compatible way to read old snapshots.

func (*SnapshotV1) Create

func (s *SnapshotV1) Create() Snapshot

func (*SnapshotV1) Deserialize

func (s *SnapshotV1) Deserialize(snapshot []byte) error

func (*SnapshotV1) GetLastExecutionTime

func (s *SnapshotV1) GetLastExecutionTime(key string) *time.Time

func (*SnapshotV1) GetVersion

func (s *SnapshotV1) GetVersion() int

func (*SnapshotV1) IsEmpty

func (s *SnapshotV1) IsEmpty() bool

func (*SnapshotV1) Serialize

func (s *SnapshotV1) Serialize() ([]byte, error)

func (*SnapshotV1) UpdateLastExecutionTime

func (s *SnapshotV1) UpdateLastExecutionTime(key string, lastExecTime *time.Time)

type VersionedSnapshot

type VersionedSnapshot struct {
	Version int
	Ser     []byte
}

VersionedSnapshot stores the version and gob serialized form of the snapshot Provides a read and write methods to serialize and deserialize the gob format of the snapshot. Including a version provides compatibility check

func (*VersionedSnapshot) ReadSnapshot

func (s *VersionedSnapshot) ReadSnapshot(r io.Reader) (Snapshot, error)

func (*VersionedSnapshot) WriteSnapshot

func (s *VersionedSnapshot) WriteSnapshot(w io.Writer, snapshot Snapshot) error

type Writer

type Writer interface {
	// WriteSnapshot writes the serialized form of the snapshot to the writer
	WriteSnapshot(writer io.Writer, snapshot Snapshot) error
}

Writer provides an interface to write the serialized form of the snapshot to a writer

Jump to

Keyboard shortcuts

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