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 (st *State) Close()
- func (st *State) Compact(ctx context.Context) (*CompactionInfo, error)
- func (st *State) Create(ctx context.Context, res resource.Resource, opts ...state.CreateOption) error
- func (st *State) DBSize(ctx context.Context) (int64, 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 *sqlitex.Pool, marshaler store.Marshaler, opts ...StateOption) (*State, error)
NewState creates new State with default options.
The following options should be enabled on the sqlite database: [TODO]: update this comment when we finalize the required options
- 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 (st *State) Close()
Close shuts down the state and releases all resources.
func (*State) Compact ¶
func (st *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) DBSize ¶ added in v0.3.0
DBSize returns the size in bytes of tables used by this package.
It uses SQLite's dbstat virtual table to calculate the size of the resources and events tables within the main database file (logical table page usage), which does not include any separate WAL/SHM files.
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 WithCompactKeepEvents ¶ added in v0.1.1
func WithCompactKeepEvents(keepEvents int) StateOption
WithCompactKeepEvents sets the minimum 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
// CompactKeepEvents is the number of events to keep during compaction.
//
// This ensures tat at least this many events are kept in the database to avoid
// event ID wraparound and to allow watches to restart from recent bookmarks.
//
// Default is 1000.
CompactKeepEvents 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.
Source Files
¶
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. |