datasystem

package
v7.14.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

View Source
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) Start

func (f *FDv1) Start(closeWhenReady chan struct{})

func (*FDv1) Stop

func (f *FDv1) Stop() error

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) Offline added in v7.8.0

func (f *FDv2) Offline() bool

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

func (f *FDv2) Stop() error

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

func (s *Store) Close() error

Close closes the store. If there is a persistent store configured, it will be closed.

func (*Store) Commit

func (s *Store) Commit() error

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 (*Store) GetAll

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 (s *Store) IsInitialized() bool

func (*Store) Selector

func (s *Store) Selector() subsystems.Selector

Selector returns the current selector.

func (*Store) Snapshot added in v7.10.2

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.

Jump to

Keyboard shortcuts

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