refactor replCfg to look more like plugins/plugin config (#91142)
* refactor replCfg to look more like plugins/plugin config * validateReplicaConfigs must handle inconsistencies in type names due to the WithHooks suffix
This commit is contained in:
@@ -99,7 +99,7 @@ func ProvideServiceWithReadReplica(primary *SQLStore, cfg *setting.Cfg,
|
||||
replCfg.Type = WrapDatabaseReplDriverWithHooks(replCfg.Type, uint(i), tracer)
|
||||
}
|
||||
|
||||
s, err := newReadOnlySQLStore(cfg, replCfg, features, bus, tracer)
|
||||
s, err := newReadOnlySQLStore(cfg, &replCfg, features, bus, tracer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -190,13 +190,13 @@ func (ss *SQLStore) initReadOnlyEngine(engine *xorm.Engine) error {
|
||||
}
|
||||
|
||||
// NewRODatabaseConfig creates a new read-only database configuration.
|
||||
func NewRODatabaseConfigs(cfg *setting.Cfg, features featuremgmt.FeatureToggles) ([]*DatabaseConfig, error) {
|
||||
func NewRODatabaseConfigs(cfg *setting.Cfg, features featuremgmt.FeatureToggles) ([]DatabaseConfig, error) {
|
||||
if cfg == nil {
|
||||
return nil, errors.New("cfg cannot be nil")
|
||||
}
|
||||
|
||||
// if only one replica is configured in the database_replicas section, use it as the default
|
||||
defaultReplCfg := &DatabaseConfig{}
|
||||
// If one replica is configured in the database_replicas section, use it as the default
|
||||
defaultReplCfg := DatabaseConfig{}
|
||||
if err := defaultReplCfg.readConfigSection(cfg, "database_replicas"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -204,13 +204,13 @@ func NewRODatabaseConfigs(cfg *setting.Cfg, features featuremgmt.FeatureToggles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []*DatabaseConfig{defaultReplCfg}
|
||||
ret := []DatabaseConfig{defaultReplCfg}
|
||||
|
||||
// Check for additional replicas as children of the database_replicas section (e.g. database_replicas.one, database_replicas.cheetara)
|
||||
repls := cfg.Raw.Section("database_replicas")
|
||||
// Check for individual replicas in the database_replica section (e.g. database_replica.one, database_replica.cheetara)
|
||||
repls := cfg.Raw.Section("database_replica")
|
||||
if len(repls.ChildSections()) > 0 {
|
||||
for _, sec := range repls.ChildSections() {
|
||||
replCfg := &DatabaseConfig{}
|
||||
replCfg := DatabaseConfig{}
|
||||
if err := replCfg.parseConfigIni(sec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user