@@ -45,7 +45,7 @@ type Store struct {
45
45
// Points to the active store. Swapped upon initialization.
46
46
active subsystems.DataStore
47
47
48
- quality DataQuality
48
+ persist bool
49
49
50
50
// Protects the availability, persistentStore, quality, and active fields.
51
51
mu sync.RWMutex
@@ -79,13 +79,19 @@ func NewStore(loggers ldlog.Loggers) *Store {
79
79
s := & Store {
80
80
persistentStore : nil ,
81
81
memoryStore : datastore .NewInMemoryDataStore (loggers ),
82
- quality : QualityNone ,
82
+ persist : false ,
83
83
loggers : loggers ,
84
84
}
85
85
s .active = s .memoryStore
86
86
return s
87
87
}
88
88
89
+ func (s * Store ) SetPersist (persist bool ) {
90
+ s .mu .Lock ()
91
+ defer s .mu .Unlock ()
92
+ s .persist = persist
93
+ }
94
+
89
95
// Close closes the store. If there is a persistent store configured, it will be closed.
90
96
func (s * Store ) Close () error {
91
97
s .mu .Lock ()
@@ -105,12 +111,11 @@ func (s *Store) getActive() subsystems.DataStore {
105
111
}
106
112
107
113
// 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
111
116
}
112
117
113
- // nolint:revive // Standard DataSourceUpdateSink method
118
+ // nolint:revive // Standard DataDestination method
114
119
func (s * Store ) Init (allData []ldstoretypes.Collection , payloadVersion * int ) bool {
115
120
s .mu .Lock ()
116
121
defer s .mu .Unlock ()
@@ -119,16 +124,15 @@ func (s *Store) Init(allData []ldstoretypes.Collection, payloadVersion *int) boo
119
124
// TODO: handle errors from initializing the memory or persistent stores.
120
125
if err := s .memoryStore .Init (allData ); err == nil {
121
126
s .active = s .memoryStore
122
- s .quality = QualityTrusted
123
127
}
124
128
125
- if s .mirroring () {
129
+ if s .shouldPersist () {
126
130
_ = s .persistentStore .impl .Init (allData ) // TODO: insert in topo-sort order
127
131
}
128
132
return true
129
133
}
130
134
131
- // nolint:revive // Standard DataSourceUpdateSink method
135
+ // nolint:revive // Standard DataDestination method
132
136
func (s * Store ) Upsert (kind ldstoretypes.DataKind , key string , item ldstoretypes.ItemDescriptor ) bool {
133
137
s .mu .RLock ()
134
138
defer s .mu .RUnlock ()
@@ -141,13 +145,14 @@ func (s *Store) Upsert(kind ldstoretypes.DataKind, key string, item ldstoretypes
141
145
// TXNS-PS: Requirement 1.3.3, must apply updates to in-memory before the persistent store.
142
146
_ , memErr = s .memoryStore .Upsert (kind , key , item )
143
147
144
- if s .mirroring () {
148
+ if s .shouldPersist () {
145
149
_ , persErr = s .persistentStore .impl .Upsert (kind , key , item )
146
150
}
147
151
return memErr == nil && persErr == nil
148
152
}
149
153
150
- // nolint:revive // Standard DataSourceUpdateSink method
154
+ // GetDataStoreStatusProvider returns the status provider for the persistent store, if one is configured, otherwise
155
+ // nil.
151
156
func (s * Store ) GetDataStoreStatusProvider () interfaces.DataStoreStatusProvider {
152
157
s .mu .RLock ()
153
158
defer s .mu .RUnlock ()
@@ -171,15 +176,14 @@ func (s *Store) WithPersistence(persistent subsystems.DataStore, mode subsystems
171
176
}
172
177
173
178
s .active = s .persistentStore .impl
174
- s .quality = QualityUntrusted
175
179
return s
176
180
}
177
181
178
182
func (s * Store ) Commit () error {
179
183
s .mu .RLock ()
180
184
defer s .mu .RUnlock ()
181
185
182
- if s .mirroring () {
186
+ if s .shouldPersist () {
183
187
flags , err := s .memoryStore .GetAll (datakinds .Features )
184
188
if err != nil {
185
189
return err
@@ -207,17 +211,3 @@ func (s *Store) Get(kind ldstoretypes.DataKind, key string) (ldstoretypes.ItemDe
207
211
func (s * Store ) IsInitialized () bool {
208
212
return s .getActive ().IsInitialized ()
209
213
}
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