Documentation
¶
Overview ¶
Package datasystem encapsulates the interactions between the SDK's data store, data source, and other related components. Currently, there is only one data system implementation, FDv1, which represents the functionality of the SDK before the FDv2 protocol was introduced.
Index ¶
- Constants
- type DataAvailability
- type FDv1
- func (f *FDv1) DataAvailability() DataAvailability
- func (f *FDv1) DataSourceStatusProvider() interfaces.DataSourceStatusProvider
- func (f *FDv1) DataStoreStatusProvider() interfaces.DataStoreStatusProvider
- func (f *FDv1) EnvironmentIDProvider() internal.EnvironmentIDProvider
- func (f *FDv1) FlagChangeEventBroadcaster() *internal.Broadcaster[interfaces.FlagChangeEvent]
- func (f *FDv1) Start(closeWhenReady chan struct{})
- func (f *FDv1) Stop() error
- func (f *FDv1) Store() subsystems.ReadOnlyStore
- func (f *FDv1) TargetAvailability() DataAvailability
- type FDv2
- func (f *FDv2) DataAvailability() DataAvailability
- func (f *FDv2) DataSourceStatusProvider() interfaces.DataSourceStatusProvider
- func (f *FDv2) DataStoreStatusProvider() interfaces.DataStoreStatusProvider
- func (f *FDv2) EnvironmentIDProvider() internal.EnvironmentIDProvider
- func (f *FDv2) FlagChangeEventBroadcaster() *internal.Broadcaster[interfaces.FlagChangeEvent]
- func (f *FDv2) Offline() bool
- func (f *FDv2) Start(closeWhenReady chan struct{})
- func (f *FDv2) Stop() error
- func (f *FDv2) Store() subsystems.ReadOnlyStore
- func (f *FDv2) TargetAvailability() DataAvailability
- func (f *FDv2) UpdateStatus(state interfaces.DataSourceState, err interfaces.DataSourceErrorInfo)
- type Store
- func (s *Store) Apply(changeSet subsystems.ChangeSet, persist bool)
- func (s *Store) Close() error
- func (s *Store) Commit() error
- func (s *Store) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
- func (s *Store) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
- func (s *Store) GetDataStoreStatusProvider() interfaces.DataStoreStatusProvider
- func (s *Store) IsInitialized() bool
- func (s *Store) Selector() subsystems.Selector
- func (s *Store) Snapshot() (map[ldstoretypes.DataKind][]ldstoretypes.KeyedItemDescriptor, ...)
- func (s *Store) WithPersistence(persistent subsystems.DataStore, mode subsystems.DataStoreMode, ...) *Store
Constants ¶
const ( // Defaults means the SDK has no data and will evaluate flags using the application-provided default values. Defaults = DataAvailability("defaults") // Cached means the SDK has data, not necessarily the latest, which will be used to evaluate flags. Cached = DataAvailability("cached") // Refreshed means the SDK has obtained, at least once, the latest known data from LaunchDarkly. Refreshed = DataAvailability("refreshed") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataAvailability ¶
type DataAvailability string
DataAvailability represents the availability of data in the SDK.
func (DataAvailability) AtLeast ¶ added in v7.9.0
func (da DataAvailability) AtLeast(other DataAvailability) bool
AtLeast returns true if the DataAvailability is at least as good as the other DataAvailability in terms of data quality.
type FDv1 ¶
type FDv1 struct {
// contains filtered or unexported fields
}
FDv1 implements the configuration and interactions between the SDK's data store, data source, and other related components.
func NewFDv1 ¶
func NewFDv1(offline bool, dataStoreFactory subsystems.ComponentConfigurer[subsystems.DataStore], dataSourceFactory subsystems.ComponentConfigurer[subsystems.DataSource], clientContext *internal.ClientContextImpl, ) (*FDv1, error)
NewFDv1 creates a new FDv1 instance from data store and data source configurers. Offline determines if the client is in offline mode. If configuration is invalid, an error will be returned.
func (*FDv1) DataAvailability ¶
func (f *FDv1) DataAvailability() DataAvailability
func (*FDv1) DataSourceStatusProvider ¶
func (f *FDv1) DataSourceStatusProvider() interfaces.DataSourceStatusProvider
func (*FDv1) DataStoreStatusProvider ¶
func (f *FDv1) DataStoreStatusProvider() interfaces.DataStoreStatusProvider
func (*FDv1) EnvironmentIDProvider ¶ added in v7.13.0
func (f *FDv1) EnvironmentIDProvider() internal.EnvironmentIDProvider
func (*FDv1) FlagChangeEventBroadcaster ¶
func (f *FDv1) FlagChangeEventBroadcaster() *internal.Broadcaster[interfaces.FlagChangeEvent]
func (*FDv1) Store ¶
func (f *FDv1) Store() subsystems.ReadOnlyStore
func (*FDv1) TargetAvailability ¶ added in v7.9.0
func (f *FDv1) TargetAvailability() DataAvailability
type FDv2 ¶ added in v7.8.0
type FDv2 struct {
// contains filtered or unexported fields
}
FDv2 is an implementation of the DataSystem interface that uses the Flag Delivery V2 protocol for obtaining and keeping data up-to-date. Additionally, it operates with an optional persistent store in read-only or read/write mode.
func NewFDv2 ¶ added in v7.8.0
func NewFDv2(disabled bool, cfgBuilder subsystems.ComponentConfigurer[subsystems.DataSystemConfiguration], clientContext *internal.ClientContextImpl, ldRelayWrapper func(subsystems.ReadOnlyDataStore, <-chan subsystems.ChangeSet), ) (*FDv2, error)
NewFDv2 creates a new instance of the FDv2 data system. The first argument indicates if the system is enabled or disabled.
func (*FDv2) DataAvailability ¶ added in v7.8.0
func (f *FDv2) DataAvailability() DataAvailability
func (*FDv2) DataSourceStatusProvider ¶ added in v7.8.0
func (f *FDv2) DataSourceStatusProvider() interfaces.DataSourceStatusProvider
func (*FDv2) DataStoreStatusProvider ¶ added in v7.8.0
func (f *FDv2) DataStoreStatusProvider() interfaces.DataStoreStatusProvider
func (*FDv2) EnvironmentIDProvider ¶ added in v7.13.0
func (f *FDv2) EnvironmentIDProvider() internal.EnvironmentIDProvider
func (*FDv2) FlagChangeEventBroadcaster ¶ added in v7.8.0
func (f *FDv2) FlagChangeEventBroadcaster() *internal.Broadcaster[interfaces.FlagChangeEvent]
func (*FDv2) Start ¶ added in v7.8.0
func (f *FDv2) Start(closeWhenReady chan struct{})
Start starts the FDv2 data system. If not disabled, it will begin initializing via the configured initializers, and then start the primary synchronizer.
func (*FDv2) Stop ¶ added in v7.8.0
Stop shuts down the data system. It will close any active synchronizers. If initialization is in progress, it will cancel the process gracefully.
func (*FDv2) Store ¶ added in v7.8.0
func (f *FDv2) Store() subsystems.ReadOnlyStore
func (*FDv2) TargetAvailability ¶ added in v7.9.0
func (f *FDv2) TargetAvailability() DataAvailability
func (*FDv2) UpdateStatus ¶ added in v7.8.0
func (f *FDv2) UpdateStatus(state interfaces.DataSourceState, err interfaces.DataSourceErrorInfo)
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a dual-mode persistent/in-memory store that serves requests for data from the evaluation algorithm.
At any given moment one of two stores is active: in-memory, or persistent. This doesn't preclude a caller from holding on to a reference to the persistent store even when we swap to the in-memory store.
Once the in-memory store has data (either from initializers or a synchronizer), the persistent store is no longer read from. From that point forward, calls to Get will serve data from the memory store.
One motivation behind using persistent stores is to offer a way to immediately start evaluating flags before a connection is made to LD (or even in the moment before an initializer has run).
The persistent store has TTL caching logic which can result in inconsistent/stale date being returned. Therefore, once we have fresh data from LD, we don't want to use the persistent store for reads any longer.
One complication is that persistent stores have historically operated in multiple regimes. The first, "daemon mode", is when the SDK is effectively using the store in read-only mode, with the store being populated by Relay or another SDK.
The second is normal persistent store mode, where it is both read and written to. In the FDv2 system, we explicitly differentiate these cases using a read/read-write mode switch. In all cases, the in-memory store is used once it has data available, although in read-write mode the persistent store may still be written to when data updates arrive, even though the memory store is serving reads.
This contrasts from FDv1 where even if data from LD is available, that data may fall out of memory due to the persistent store's caching logic ("sparse mode", when the TTL is non-infinite). This was because the SDK's main Store implementation was a wrapper around the persistent store, rather than entirely independent.
We have found the previous behavior to almost always be undesirable for users. By keeping the persistent and memory stores distinct, it should be much clearer where exactly data is coming from and the behavior should be more predictable at runtime.
func NewStore ¶
func NewStore( loggers ldlog.Loggers, flagChangeEvent *internal.Broadcaster[interfaces.FlagChangeEvent], changeSet *internal.Broadcaster[subsystems.ChangeSet], ) *Store
NewStore creates a new store. If a persistent store needs to be configured, call WithPersistence before any other method is called.
func (*Store) Apply ¶ added in v7.11.0
func (s *Store) Apply(changeSet subsystems.ChangeSet, persist bool)
Apply applies a changeset to the store. The changeset must be a valid set of changes that can be applied to the store. If the changeset is not valid, an error will be logged and the changeset will not be applied.
func (*Store) Close ¶
Close closes the store. If there is a persistent store configured, it will be closed.
func (*Store) Commit ¶
Commit persists the data in the memory store to the persistent store, if configured. The persistent store must also be in write mode, and the last call to setBasis or applyDelta must have had persist set to true.
func (*Store) Get ¶
func (s *Store) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
func (*Store) GetAll ¶
func (s *Store) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
func (*Store) GetDataStoreStatusProvider ¶
func (s *Store) GetDataStoreStatusProvider() interfaces.DataStoreStatusProvider
GetDataStoreStatusProvider returns the status provider for the persistent store, if one is configured, otherwise nil.
func (*Store) IsInitialized ¶
func (*Store) Selector ¶
func (s *Store) Selector() subsystems.Selector
Selector returns the current selector.
func (*Store) Snapshot ¶ added in v7.10.2
func (s *Store) Snapshot() ( map[ldstoretypes.DataKind][]ldstoretypes.KeyedItemDescriptor, subsystems.Selector, error, )
func (*Store) WithPersistence ¶
func (s *Store) WithPersistence(persistent subsystems.DataStore, mode subsystems.DataStoreMode, statusProvider interfaces.DataStoreStatusProvider, ) *Store
WithPersistence exists to accommodate the SDK's configuration builders. We need a ClientContext before we can call Build to actually get the persistent store. That ClientContext requires the DataDestination, which is what this store struct implements. Therefore, the call to NewStore and WithPersistence need to be separate.