@@ -45,7 +45,7 @@ type Store struct {
4545 // Points to the active store. Swapped upon initialization.
4646 active subsystems.DataStore
4747
48- quality DataQuality
48+ persist bool
4949
5050 // Protects the availability, persistentStore, quality, and active fields.
5151 mu sync.RWMutex
@@ -79,13 +79,19 @@ func NewStore(loggers ldlog.Loggers) *Store {
7979 s := & Store {
8080 persistentStore : nil ,
8181 memoryStore : datastore .NewInMemoryDataStore (loggers ),
82- quality : QualityNone ,
82+ persist : false ,
8383 loggers : loggers ,
8484 }
8585 s .active = s .memoryStore
8686 return s
8787}
8888
89+ func (s * Store ) SetPersist (persist bool ) {
90+ s .mu .Lock ()
91+ defer s .mu .Unlock ()
92+ s .persist = persist
93+ }
94+
8995// Close closes the store. If there is a persistent store configured, it will be closed.
9096func (s * Store ) Close () error {
9197 s .mu .Lock ()
@@ -105,12 +111,11 @@ func (s *Store) getActive() subsystems.DataStore {
105111}
106112
107113// Mirroring returns true data is being mirrored to a persistent store.
108- func (s * Store ) mirroring () bool {
109- return s .persistentStore != nil && s .persistentStore .mode == subsystems .DataStoreModeReadWrite &&
110- s .quality == QualityTrusted
114+ func (s * Store ) shouldPersist () bool {
115+ return s .persist && s .persistentStore != nil && s .persistentStore .mode == subsystems .DataStoreModeReadWrite
111116}
112117
113- // nolint:revive // Standard DataSourceUpdateSink method
118+ // nolint:revive // Standard DataDestination method
114119func (s * Store ) Init (allData []ldstoretypes.Collection , payloadVersion * int ) bool {
115120 s .mu .Lock ()
116121 defer s .mu .Unlock ()
@@ -119,16 +124,15 @@ func (s *Store) Init(allData []ldstoretypes.Collection, payloadVersion *int) boo
119124 // TODO: handle errors from initializing the memory or persistent stores.
120125 if err := s .memoryStore .Init (allData ); err == nil {
121126 s .active = s .memoryStore
122- s .quality = QualityTrusted
123127 }
124128
125- if s .mirroring () {
129+ if s .shouldPersist () {
126130 _ = s .persistentStore .impl .Init (allData ) // TODO: insert in topo-sort order
127131 }
128132 return true
129133}
130134
131- // nolint:revive // Standard DataSourceUpdateSink method
135+ // nolint:revive // Standard DataDestination method
132136func (s * Store ) Upsert (kind ldstoretypes.DataKind , key string , item ldstoretypes.ItemDescriptor ) bool {
133137 s .mu .RLock ()
134138 defer s .mu .RUnlock ()
@@ -141,13 +145,14 @@ func (s *Store) Upsert(kind ldstoretypes.DataKind, key string, item ldstoretypes
141145 // TXNS-PS: Requirement 1.3.3, must apply updates to in-memory before the persistent store.
142146 _ , memErr = s .memoryStore .Upsert (kind , key , item )
143147
144- if s .mirroring () {
148+ if s .shouldPersist () {
145149 _ , persErr = s .persistentStore .impl .Upsert (kind , key , item )
146150 }
147151 return memErr == nil && persErr == nil
148152}
149153
150- // nolint:revive // Standard DataSourceUpdateSink method
154+ // GetDataStoreStatusProvider returns the status provider for the persistent store, if one is configured, otherwise
155+ // nil.
151156func (s * Store ) GetDataStoreStatusProvider () interfaces.DataStoreStatusProvider {
152157 s .mu .RLock ()
153158 defer s .mu .RUnlock ()
@@ -171,15 +176,14 @@ func (s *Store) WithPersistence(persistent subsystems.DataStore, mode subsystems
171176 }
172177
173178 s .active = s .persistentStore .impl
174- s .quality = QualityUntrusted
175179 return s
176180}
177181
178182func (s * Store ) Commit () error {
179183 s .mu .RLock ()
180184 defer s .mu .RUnlock ()
181185
182- if s .mirroring () {
186+ if s .shouldPersist () {
183187 flags , err := s .memoryStore .GetAll (datakinds .Features )
184188 if err != nil {
185189 return err
@@ -207,17 +211,3 @@ func (s *Store) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDe
207211func (s * Store ) IsInitialized () bool {
208212 return s .getActive ().IsInitialized ()
209213}
210-
211- type DataQuality int
212-
213- const (
214- QualityNone = DataQuality (0 )
215- QualityUntrusted = DataQuality (1 )
216- QualityTrusted = DataQuality (2 )
217- )
218-
219- func (s * Store ) DataQuality () DataQuality {
220- s .mu .RLock ()
221- defer s .mu .RUnlock ()
222- return s .quality
223- }
0 commit comments