MM-14145: The config store Set will now Save automatically (#10377)
* MM-14145: The config store Set will now Save automatically When UpdateConfig (and configStore.Set) is called in admin.go and config.go, commonStore.Set now takes a store-specific persist function. It uses that persist function to save the configuration automatically. Removed: Now callers do not have to call configStore.Save or app.PersistConfig, and those functions have been removed. Possible downside: this means a "failed to persist config" error can now be thrown during a app.UpdateConfig or commonStore.Set call. But considering application code never really sets a config without saving it (except in the test cases, which were testing that -- see below), it seems fine to group these responsibilities. Also removed: tests for 'set without save'. Since that can not happen anymore, the tests are not needed. * Removed Save completely, cleaned up formatting, joined save test with set tests. * fixed shadowed variable error
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
06261d32ba
Коммит
8bd182c38f
@@ -36,10 +36,11 @@ func (cs *commonStore) GetEnvironmentOverrides() map[string]interface{} {
|
||||
return cs.environmentOverrides
|
||||
}
|
||||
|
||||
// set replaces the current configuration in its entirety, without updating the backing store.
|
||||
// set replaces the current configuration in its entirety, and updates the backing store
|
||||
// using the persist function argument.
|
||||
//
|
||||
// This function assumes no lock has been acquired, as it acquires a write lock itself.
|
||||
func (cs *commonStore) set(newCfg *model.Config, isValid func(*model.Config) error) (*model.Config, error) {
|
||||
func (cs *commonStore) set(newCfg *model.Config, isValid func(*model.Config) error, persist func(*model.Config) error) (*model.Config, error) {
|
||||
cs.configLock.Lock()
|
||||
var unlockOnce sync.Once
|
||||
defer unlockOnce.Do(cs.configLock.Unlock)
|
||||
@@ -71,12 +72,9 @@ func (cs *commonStore) set(newCfg *model.Config, isValid func(*model.Config) err
|
||||
}
|
||||
}
|
||||
|
||||
// Ideally, Set would persist automatically and abstract this completely away from the
|
||||
// client. Doing so requires a few upstream changes first, so for now an explicit Save()
|
||||
// remains required.
|
||||
// if err := cs.persist(newCfg); err != nil {
|
||||
// return nil, errors.Wrap(err, "failed to persist")
|
||||
// }
|
||||
if err := persist(newCfg); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to persist")
|
||||
}
|
||||
|
||||
cs.config = newCfg
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user