...

Source file src/github.com/launchdarkly/go-server-sdk/v6/subsystems/data_store.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/subsystems

     1  package subsystems
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/launchdarkly/go-server-sdk/v6/subsystems/ldstoretypes"
     7  )
     8  
     9  // DataStore is an interface for a data store that holds feature flags and related data received by
    10  // the SDK.
    11  //
    12  // Ordinarily, the only implementations of this interface are the default in-memory implementation,
    13  // which holds references to actual SDK data model objects, and the persistent data store
    14  // implementation that delegates to a PersistentDataStore.
    15  type DataStore interface {
    16  	io.Closer
    17  
    18  	// Init overwrites the store's contents with a set of items for each collection.
    19  	//
    20  	// All previous data should be discarded, regardless of versioning.
    21  	//
    22  	// The update should be done atomically. If it cannot be done atomically, then the store
    23  	// must first add or update each item in the same order that they are given in the input
    24  	// data, and then delete any previously stored items that were not in the input data.
    25  	Init(allData []ldstoretypes.Collection) error
    26  
    27  	// Get retrieves an item from the specified collection, if available.
    28  	//
    29  	// If the specified key does not exist in the collection, it should return an ItemDescriptor
    30  	// whose Version is -1.
    31  	//
    32  	// If the item has been deleted and the store contains a placeholder, it should return an
    33  	// ItemDescriptor whose Version is the version of the placeholder, and whose Item is nil.
    34  	Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDescriptor, error)
    35  
    36  	// GetAll retrieves all items from the specified collection.
    37  	//
    38  	// If the store contains placeholders for deleted items, it should include them in the results,
    39  	// not filter them out.
    40  	GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error)
    41  
    42  	// Upsert updates or inserts an item in the specified collection. For updates, the object will only be
    43  	// updated if the existing version is less than the new version.
    44  	//
    45  	// The SDK may pass an ItemDescriptor whose Item is nil, to represent a placeholder for a deleted
    46  	// item. In that case, assuming the version is greater than any existing version of that item, the
    47  	// store should retain that placeholder rather than simply not storing anything.
    48  	//
    49  	// The method returns true if the item was updated, or false if it was not updated because the store
    50  	// contains an equal or greater version.
    51  	Upsert(kind ldstoretypes.DataKind, key string, item ldstoretypes.ItemDescriptor) (bool, error)
    52  
    53  	// IsInitialized returns true if the data store contains a data set, meaning that Init has been
    54  	// called at least once.
    55  	//
    56  	// In a shared data store, it should be able to detect this even if Init was called in a
    57  	// different process: that is, the test should be based on looking at what is in the data store.
    58  	// Once this has been determined to be true, it can continue to return true without having to
    59  	// check the store again; this method should be as fast as possible since it may be called during
    60  	// feature flag evaluations.
    61  	IsInitialized() bool
    62  
    63  	// IsStatusMonitoringEnabled returns true if this data store implementation supports status
    64  	// monitoring.
    65  	//
    66  	// This is normally only true for persistent data stores created with ldcomponents.PersistentDataStore(),
    67  	// but it could also be true for any custom DataStore implementation that makes use of the
    68  	// statusUpdater parameter provided to the DataStoreFactory. Returning true means that the store
    69  	// guarantees that if it ever enters an invalid state (that is, an operation has failed or it knows
    70  	// that operations cannot succeed at the moment), it will publish a status update, and will then
    71  	// publish another status update once it has returned to a valid state.
    72  	//
    73  	// The same value will be returned from DataStoreStatusProvider.IsStatusMonitoringEnabled().
    74  	IsStatusMonitoringEnabled() bool
    75  }
    76  

View as plain text