Documentation
¶
Overview ¶
Package sqlite provides an implementation of state.State in sqlite.
Index ¶
- func ErrAlreadyExists(r resource.Reference) error
- func ErrInvalidWatchBookmark(e error) error
- func ErrNotFound(r resource.Pointer) error
- func ErrOwnerConflict(r resource.Pointer, owner string) error
- func ErrPendingFinalizers(r resource.Pointer, fins []string) error
- func ErrPhaseConflict(r resource.Reference, expectedPhase resource.Phase) error
- func ErrUnsupported(operation string) error
- func ErrVersionConflict(r resource.Pointer, expected, found uint64) error
- type CompactionInfo
- type State
- func (s *State) Close()
- func (s *State) Compact(ctx context.Context) (*CompactionInfo, error)
- func (st *State) Create(ctx context.Context, res resource.Resource, opts ...state.CreateOption) error
- func (st *State) Destroy(ctx context.Context, ptr resource.Pointer, opts ...state.DestroyOption) error
- func (st *State) Get(ctx context.Context, ptr resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
- func (st *State) List(ctx context.Context, resourceKind resource.Kind, opts ...state.ListOption) (resource.List, error)
- func (st *State) Update(ctx context.Context, newResource resource.Resource, opts ...state.UpdateOption) error
- func (st *State) Watch(ctx context.Context, ptr resource.Pointer, ch chan<- state.Event, ...) error
- func (st *State) WatchKind(ctx context.Context, resourceKind resource.Kind, ch chan<- state.Event, ...) error
- func (st *State) WatchKindAggregated(ctx context.Context, resourceKind resource.Kind, ch chan<- []state.Event, ...) error
- type StateOption
- type StateOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrAlreadyExists ¶
ErrAlreadyExists generates error compatible with state.ErrConflict.
func ErrInvalidWatchBookmark ¶
ErrInvalidWatchBookmark generates error compatible with state.ErrInvalidWatchBookmark.
func ErrNotFound ¶
ErrNotFound generates error compatible with state.ErrNotFound.
func ErrOwnerConflict ¶
ErrOwnerConflict generates error compatible with state.ErrConflict.
func ErrPendingFinalizers ¶
ErrPendingFinalizers generates error compatible with state.ErrConflict.
func ErrPhaseConflict ¶
ErrPhaseConflict generates error compatible with ErrConflict.
func ErrUnsupported ¶
ErrUnsupported generates error compatible with state.ErrUnsupported.
Types ¶
type CompactionInfo ¶
CompactionInfo holds information about a compaction operation.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State implements state storage in sqlite database.
func NewState ¶
func NewState(ctx context.Context, db *sql.DB, marshaler store.Marshaler, opts ...StateOption) (*State, error)
NewState creates new State with default options.
The following options should be enabled on the sqlite database:
- busy_timeout pragma should be set to a reasonable value (e.g. 5000 ms)
- journal_mode pragma should be set to WAL
- txlock=immediate should be set in the DSN to avoid busy errors on concurrent writes.
func (*State) Close ¶
func (s *State) Close()
Close shuts down the state and releases all resources.
func (*State) Compact ¶
func (s *State) Compact(ctx context.Context) (*CompactionInfo, error)
Compact performs database compaction.
func (*State) Create ¶
func (st *State) Create(ctx context.Context, res resource.Resource, opts ...state.CreateOption) error
Create a resource.
If a resource already exists, Create returns an error.
func (*State) Destroy ¶
func (st *State) Destroy(ctx context.Context, ptr resource.Pointer, opts ...state.DestroyOption) error
Destroy a resource.
If a resource doesn't exist, error is returned. If a resource has pending finalizers, error is returned.
func (*State) Get ¶
func (st *State) Get(ctx context.Context, ptr resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
Get a resource by type and ID.
If a resource is not found, error is returned.
func (*State) List ¶
func (st *State) List(ctx context.Context, resourceKind resource.Kind, opts ...state.ListOption) (resource.List, error)
List resources by type.
func (*State) Update ¶
func (st *State) Update(ctx context.Context, newResource resource.Resource, opts ...state.UpdateOption) error
Update a resource.
If a resource doesn't exist, error is returned. On update current version of resource `new` in the state should match the version on the backend, otherwise conflict error is returned.
func (*State) Watch ¶
func (st *State) Watch(ctx context.Context, ptr resource.Pointer, ch chan<- state.Event, opts ...state.WatchOption) error
Watch state of a resource by type.
It's fine to watch for a resource which doesn't exist yet. Watch is canceled when context gets canceled. Watch sends initial resource state as the very first event on the channel, and then sends any updates to the resource as events.
type StateOption ¶
type StateOption func(*StateOptions)
StateOption configures sqlite state.
func WithCompactMaxEvents ¶
func WithCompactMaxEvents(maxEvents int) StateOption
WithCompactMaxEvents sets the maximum number of events to keep during compaction.
func WithCompactMinAge ¶
func WithCompactMinAge(minAge time.Duration) StateOption
WithCompactMinAge sets the minimum age of events to keep during compaction.
func WithCompactionInterval ¶
func WithCompactionInterval(interval time.Duration) StateOption
WithCompactionInterval sets the interval between automatic database compactions.
func WithLogger ¶
func WithLogger(logger *zap.Logger) StateOption
WithLogger sets the logger for the sqlite state.
func WithTablePrefix ¶
func WithTablePrefix(prefix string) StateOption
WithTablePrefix sets the table prefix for all tables used by the sqlite state.
type StateOptions ¶
type StateOptions struct {
// Logger is the logger to use for logging.
Logger *zap.Logger
// TablePrefix is the prefix to use for all tables used by the sqlite state.
//
// Default is empty string.
// Setting a table prefix allows multiple independent states to share the same database.
TablePrefix string
// CompactionInterval is the interval between automatic database compactions.
//
// Default is 30 minutes.
CompactionInterval time.Duration
// CompactMaxEvents is the maximum number of events to keep during compaction.
//
// Default is 1000.
CompactMaxEvents int
// CompactMinAge is the minimum age of events to keep during compaction.
//
// It might be important to keep recent events to allow restarting a watch
// from a bookmark.
//
// Default is 1 hour.
CompactMinAge time.Duration
}
StateOptions configures sqlite state.
func DefaultStateOptions ¶
func DefaultStateOptions() StateOptions
DefaultStateOptions returns default sqlite state options.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
filter
Package filter translates List/Watch request filters into sqlite conditions.
|
Package filter translates List/Watch request filters into sqlite conditions. |
|
sub
Package sub contains simple subscription management.
|
Package sub contains simple subscription management. |