1 package subsystems 2 3 import ( 4 "github.com/launchdarkly/go-server-sdk/v6/interfaces" 5 "github.com/launchdarkly/go-server-sdk/v6/subsystems/ldstoretypes" 6 ) 7 8 // DataSourceUpdateSink is an interface that a data source implementation will use to push data into the SDK. 9 // 10 // Application code does not need to use this type. It is for data source implementations. 11 // 12 // The data source interacts with this object, rather than manipulating the data store directly, so that 13 // the SDK can perform any other necessary operations that must happen when data is updated. The SDK 14 // passes this in the ClientContext when it is creating a data source component. 15 type DataSourceUpdateSink interface { 16 // Init overwrites the current contents of the data store with a set of items for each collection. 17 // 18 // If the underlying data store returns an error during this operation, the SDK will log it, 19 // and set the data source state to DataSourceStateInterrupted with an error of 20 // DataSourceErrorKindStoreError. It will not return the error to the data source, but will 21 // return false to indicate that the operation failed. 22 Init(allData []ldstoretypes.Collection) bool 23 24 // Upsert updates or inserts an item in the specified collection. For updates, the object will only be 25 // updated if the existing version is less than the new version. 26 // 27 // To mark an item as deleted, pass an ItemDescriptor with a nil Item and a nonzero version 28 // number. Deletions must be versioned so that they do not overwrite a later update in case updates 29 // are received out of order. 30 // 31 // If the underlying data store returns an error during this operation, the SDK will log it, 32 // and set the data source state to DataSourceStateInterrupted with an error of 33 // DataSourceErrorKindStoreError. It will not return the error to the data source, but will 34 // return false to indicate that the operation failed. 35 Upsert(kind ldstoretypes.DataKind, key string, item ldstoretypes.ItemDescriptor) bool 36 37 // UpdateStatus informs the SDK of a change in the data source's status. 38 // 39 // Data source implementations should use this method if they have any concept of being in a valid 40 // state, a temporarily disconnected state, or a permanently stopped state. 41 // 42 // If newState is different from the previous state, and/or newError is non-empty, the SDK 43 // will start returning the new status (adding a timestamp for the change) from 44 // DataSourceStatusProvider.GetStatus(), and will trigger status change events to any 45 // registered listeners. 46 // 47 // A special case is that if newState is DataSourceStateInterrupted, but the previous state was 48 // but the previous state was DataSourceStateInitializing, the state will remain at Initializing 49 // because Interrupted is only meaningful after a successful startup. 50 UpdateStatus(newState interfaces.DataSourceState, newError interfaces.DataSourceErrorInfo) 51 52 // GetDataStoreStatusProvider returns an object that provides status tracking for the data store, if 53 // applicable. 54 // 55 // This may be useful if the data source needs to be aware of storage problems that might require it 56 // to take some special action: for instance, if a database outage may have caused some data to be 57 // lost and therefore the data should be re-requested from LaunchDarkly. 58 GetDataStoreStatusProvider() interfaces.DataStoreStatusProvider 59 } 60