Documentation
¶
Index ¶
- Variables
- func CheckSchema(ctx context.Context, db *database.DB) error
- func ImportSchema(ctx context.Context, db *database.DB, databaseSchemaDir string) error
- type CleanupStmt
- type Delta
- type DumpSignals
- type EntitiesById
- type HA
- func (h *HA) Close(ctx context.Context) error
- func (h *HA) Done() <-chan struct{}
- func (h *HA) Environment() *v1.Environment
- func (h *HA) Err() error
- func (h *HA) Handover() chan string
- func (h *HA) State() (responsibleTsMilli int64, responsible, otherResponsible bool)
- func (h *HA) Takeover() chan string
- type RuntimeUpdates
- type ScopedEntity
- type Sync
Constants ¶
This section is empty.
Variables ¶
var ErrSchemaMismatch = stderrors.New("unexpected database schema version")
ErrSchemaMismatch implies an unexpected schema version, most likely after Icinga DB was updated but the database missed the schema upgrade.
var ErrSchemaNotExists = stderrors.New("no database schema exists")
ErrSchemaNotExists implies that no Icinga DB schema has been imported.
Functions ¶
func CheckSchema ¶ added in v1.2.1
CheckSchema verifies the correct database schema is present.
This function returns the following error types, possibly wrapped:
- If no schema exists, the error returned is ErrSchemaNotExists.
- If the schema version does not match the expected version, the error returned is ErrSchemaMismatch.
- Otherwise, the original error is returned, for example in case of general database problems.
func ImportSchema ¶ added in v1.3.0
ImportSchema performs an initial schema import in the db.
This function assumes that no schema exists. So it should only be called after a prior CheckSchema call.
Note: Running a schema file may have side effects, such as altering SQL system variables. Unless you are certain that the schema update will not interfere with future queries, consider using a dedicated database connection.
Types ¶
type CleanupStmt ¶
CleanupStmt defines information needed to compose cleanup statements.
func (*CleanupStmt) CleanupOlderThan ¶ added in v1.2.1
func (stmt *CleanupStmt) CleanupOlderThan( ctx context.Context, db *database.DB, envId types.Binary, count uint64, olderThan time.Time, onSuccess ...database.OnSuccess[struct{}], ) (uint64, error)
CleanupOlderThan deletes all rows with the specified statement that are older than the given time. Deletes a maximum of as many rows per round as defined in count. Actually deleted rows will be passed to onSuccess. Returns the total number of rows deleted.
type Delta ¶
type Delta struct {
Create EntitiesById
Update EntitiesById
Delete EntitiesById
Subject *common.SyncSubject
// contains filtered or unexported fields
}
Delta calculates the delta of actual and desired entities, and stores which entities need to be created, updated, and deleted.
type DumpSignals ¶
type DumpSignals struct {
// contains filtered or unexported fields
}
DumpSignals reads dump signals from a Redis stream via Listen. Dump-done signals are passed on via Done channels, while InProgress must be checked for dump-wip signals.
func NewDumpSignals ¶
func NewDumpSignals(redis *redis.Client, logger *logging.Logger) *DumpSignals
NewDumpSignals returns new DumpSignals.
func (*DumpSignals) Done ¶
func (s *DumpSignals) Done(key string) <-chan struct{}
Done returns a channel that is closed when the given key receives a done dump signal.
func (*DumpSignals) InProgress ¶
func (s *DumpSignals) InProgress() <-chan struct{}
InProgress returns a channel that is closed when a new dump is in progress after done signals were sent to channels returned by Done.
func (*DumpSignals) Listen ¶
func (s *DumpSignals) Listen(ctx context.Context) error
Listen starts listening for dump signals in the icinga:dump Redis stream. When a done signal is received, this is signaled via the channels returned from the Done function.
If a wip signal is received after a done signal was passed on via the Done function, this is signaled via the InProgress function and this function returns with err == nil. In this case, all other signals are invalidated. It is up to the caller to pass on this information, for example by cancelling derived contexts.
This function may only be called once for each DumpSignals object. To listen for a new iteration of dump signals, a new DumpSignals instance must be created.
type EntitiesById ¶
EntitiesById is a map of key-contracts.Entity pairs.
func (EntitiesById) Entities ¶
func (ebi EntitiesById) Entities(ctx context.Context) <-chan database.Entity
Entities streams the entities on a returned channel.
func (EntitiesById) IDs ¶
func (ebi EntitiesById) IDs() []any
IDs returns the contracts.ID of the entities.
type HA ¶
type HA struct {
// contains filtered or unexported fields
}
HA provides high availability and indicates whether a Takeover or Handover must be made.
func NewHA ¶
func NewHA(ctx context.Context, db *database.DB, heartbeat *icingaredis.Heartbeat, logger *logging.Logger) *HA
NewHA returns a new HA and starts the controller loop.
func (*HA) Done ¶
func (h *HA) Done() <-chan struct{}
Done returns a channel that's closed when the HA controller loop ended.
func (*HA) Environment ¶
func (h *HA) Environment() *v1.Environment
Environment returns the current environment.
func (*HA) Err ¶
Err returns an error if Done has been closed and there is an error. Otherwise returns nil.
func (*HA) Handover ¶
Handover returns a channel with which handovers and their reasons are signaled.
type RuntimeUpdates ¶
type RuntimeUpdates struct {
// contains filtered or unexported fields
}
RuntimeUpdates specifies the source and destination of runtime updates.
func NewRuntimeUpdates ¶
func NewRuntimeUpdates(db *database.DB, redis *redis.Client, logger *logging.Logger) *RuntimeUpdates
NewRuntimeUpdates creates a new RuntimeUpdates.
func (*RuntimeUpdates) ClearStreams ¶
ClearStreams returns the stream key to ID mapping of the runtime update streams for later use in Sync and clears the streams themselves.
func (*RuntimeUpdates) Sync ¶
func (r *RuntimeUpdates) Sync( ctx context.Context, factoryFuncs []database.EntityFactoryFunc, streams redis.Streams, allowParallel bool, ) error
Sync synchronizes runtime update streams from s.redis to s.db and deletes the original data on success. Note that Sync must be only be called configuration synchronization has been completed. allowParallel allows synchronizing out of order (not FIFO).
type ScopedEntity ¶
ScopedEntity combines an entity and a scope that specifies the WHERE conditions that entities of the enclosed entity type must satisfy in order to be SELECTed.
func NewScopedEntity ¶
func NewScopedEntity(entity database.Entity, scope any) *ScopedEntity
NewScopedEntity returns a new ScopedEntity.
func (ScopedEntity) Scope ¶
func (e ScopedEntity) Scope() any
Scope implements the contracts.Scoper interface.
func (ScopedEntity) TableName ¶
func (e ScopedEntity) TableName() string
TableName implements the contracts.TableNamer interface.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync implements a rendezvous point for Icinga DB and Redis to synchronize their entities.
func (Sync) ApplyDelta ¶
ApplyDelta applies all changes from Delta to the database.
func (Sync) Sync ¶
Sync synchronizes entities between Icinga DB and Redis created with the specified sync subject. This function does not respect dump signals. For this, use SyncAfterDump.
func (Sync) SyncAfterDump ¶
func (s Sync) SyncAfterDump(ctx context.Context, subject *common.SyncSubject, dump *DumpSignals) error
SyncAfterDump waits for a config dump to finish (using the dump parameter) and then starts a sync for the given sync subject using the Sync function.