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
Этот коммит содержится в:
Christopher Poile
2019-02-28 10:51:42 -05:00
коммит произвёл Jesse Hallam
родитель 06261d32ba
Коммит 8bd182c38f
11 изменённых файлов: 39 добавлений и 107 удалений

Просмотреть файл

@@ -86,7 +86,7 @@ func resolveConfigFilePath(path string) (string, error) {
return "", fmt.Errorf("failed to find config file %s", path)
}
// 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.
func (fs *FileStore) Set(newCfg *model.Config) (*model.Config, error) {
return fs.commonStore.set(newCfg, func(cfg *model.Config) error {
if *fs.config.ClusterSettings.Enable && *fs.config.ClusterSettings.ReadOnlyConfig {
@@ -94,7 +94,7 @@ func (fs *FileStore) Set(newCfg *model.Config) (*model.Config, error) {
}
return nil
})
}, fs.persist)
}
// persist writes the configuration to the configured file.
@@ -152,14 +152,6 @@ func (fs *FileStore) Load() (err error) {
return fs.commonStore.load(f, needsSave, fs.persist)
}
// Save writes the current configuration to the backing store.
func (fs *FileStore) Save() error {
fs.configLock.Lock()
defer fs.configLock.Unlock()
return fs.persist(fs.config)
}
// startWatcher starts a watcher to monitor for external config file changes.
func (fs *FileStore) startWatcher() error {
if fs.watcher != nil {