MM-11262: database config store (#10281)
* vendor github.com/jmoiron/sqlx * MM-11262: introduce a database store * revert unnecessary fmt.Errorf * simplify unit test helper methods * remote TODO re: retry * relocate initializeConfigurationsTable for clarity * factor out a commonStore * acquire database config lock on close for safety * add missing header * fix lock comment
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
898a3a289c
Коммит
9bf5687311
@@ -138,19 +138,31 @@ func configSubpathCmdF(command *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getConfigStore(command *cobra.Command) (config.Store, error) {
|
||||
if err := utils.TranslationsPreInit(); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize i18n")
|
||||
}
|
||||
|
||||
configDSN, err := command.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse --config flag")
|
||||
}
|
||||
|
||||
configStore, err := config.NewStore(configDSN, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize config store")
|
||||
}
|
||||
|
||||
return configStore, nil
|
||||
}
|
||||
|
||||
func configGetCmdF(command *cobra.Command, args []string) error {
|
||||
app, err := InitDBCommandContextCobra(command)
|
||||
configStore, err := getConfigStore(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer app.Shutdown()
|
||||
|
||||
// create the model for config
|
||||
// Note: app.Config() returns a pointer, make appropriate changes
|
||||
config := app.Config()
|
||||
|
||||
// get the print config setting and any error if there is
|
||||
out, err := printConfigValues(configToMap(*config), strings.Split(args[0], "."), args[0])
|
||||
out, err := printConfigValues(configToMap(*configStore.Get()), strings.Split(args[0], "."), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -161,18 +173,17 @@ func configGetCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func configShowCmdF(command *cobra.Command, args []string) error {
|
||||
app, err := InitDBCommandContextCobra(command)
|
||||
configStore, err := getConfigStore(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer app.Shutdown()
|
||||
|
||||
err = cobra.NoArgs(command, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%s", prettyPrintStruct(*app.Config()))
|
||||
fmt.Printf("%s", prettyPrintStruct(*configStore.Get()))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -199,26 +210,24 @@ func printConfigValues(configMap map[string]interface{}, configSetting []string,
|
||||
}
|
||||
|
||||
func configSetCmdF(command *cobra.Command, args []string) error {
|
||||
app, err := InitDBCommandContextCobra(command)
|
||||
configStore, err := getConfigStore(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer app.Shutdown()
|
||||
|
||||
// args[0] -> holds the config setting that we want to change
|
||||
// args[1:] -> the new value of the config setting
|
||||
configSetting := args[0]
|
||||
newVal := args[1:]
|
||||
|
||||
// create the function to update config
|
||||
oldConfig := app.Config()
|
||||
newConfig := app.Config()
|
||||
f := updateConfigValue(configSetting, newVal, oldConfig, newConfig)
|
||||
oldConfig := configStore.Get()
|
||||
newConfig := configStore.Get()
|
||||
|
||||
app.UpdateConfig(f)
|
||||
if err := newConfig.IsValid(); err != nil {
|
||||
return err
|
||||
f := updateConfigValue(configSetting, newVal, oldConfig, newConfig)
|
||||
f(newConfig)
|
||||
if _, err := configStore.Set(newConfig); err != nil {
|
||||
return errors.Wrap(err, "failed to set config")
|
||||
}
|
||||
|
||||
// UpdateConfig above would have already fixed these invalid locales, but we check again
|
||||
@@ -228,8 +237,7 @@ func configSetCmdF(command *cobra.Command, args []string) error {
|
||||
return errors.New("Invalid locale configuration")
|
||||
}
|
||||
|
||||
// make the changes persist
|
||||
app.PersistConfig()
|
||||
configStore.Save()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func InitDBCommandContext(configFileLocation string) (*app.App, error) {
|
||||
func InitDBCommandContext(configDSN string) (*app.App, error) {
|
||||
if err := utils.TranslationsPreInit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
model.AppErrorInit(utils.T)
|
||||
|
||||
s, err := app.NewServer(app.ConfigFile(configFileLocation, true))
|
||||
s, err := app.NewServer(app.Config(configDSN, false))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ func serverCmdF(command *cobra.Command, args []string) error {
|
||||
return runServer(config, disableConfigWatch, usedPlatform, interruptChan)
|
||||
}
|
||||
|
||||
func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
|
||||
func runServer(configDSN string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
|
||||
options := []app.Option{
|
||||
app.ConfigFile(configFileLocation, !disableConfigWatch),
|
||||
app.Config(configDSN, !disableConfigWatch),
|
||||
app.RunJobs,
|
||||
app.JoinCluster,
|
||||
app.StartElasticsearch,
|
||||
|
||||
Ссылка в новой задаче
Block a user