Revert read replica POC (#93551)
* Revert "chore: add replDB to team service (#91799)" This reverts commitc6ae2d7999. * Revert "experiment: use read replica for Get and Find Dashboards (#91706)" This reverts commit54177ca619. * Revert "QuotaService: refactor to use ReplDB for Get queries (#91333)" This reverts commit299c142f6a. * Revert "refactor replCfg to look more like plugins/plugin config (#91142)" This reverts commitac0b4bb34d. * Revert "chore (replstore): fix registration with multiple sql drivers, again (#90990)" This reverts commitdaedb358dd. * Revert "Chore (sqlstore): add validation and testing for repl config (#90683)" This reverts commitaf19f039b6. * Revert "ReplStore: Add support for round robin load balancing between multiple read replicas (#90530)" This reverts commit27b52b1507. * Revert "DashboardStore: Use ReplDB and get dashboard quotas from the ReadReplica (#90235)" This reverts commit8a6107cd35. * Revert "accesscontrol service read replica (#89963)" This reverts commit77a4869fca. * Revert "Fix: add mapping for the new mysqlRepl driver (#89551)" This reverts commitab5a079bcc. * Revert "fix: sql instrumentation dual registration error (#89508)" This reverts commitd988f5c3b0. * Revert "Experimental Feature Toggle: databaseReadReplica (#89232)" This reverts commit50244ed4a1.
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"gopkg.in/ini.v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
@@ -66,15 +65,9 @@ func NewDatabaseConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles) (*
|
||||
return dbCfg, nil
|
||||
}
|
||||
|
||||
// readConfigSection reads the database configuration from the given block of
|
||||
// the configuration file. This method allows us to add a "database_replica"
|
||||
// section to the configuration file while using the same cfg struct.
|
||||
func (dbCfg *DatabaseConfig) readConfigSection(cfg *setting.Cfg, section string) error {
|
||||
sec := cfg.Raw.Section(section)
|
||||
return dbCfg.parseConfigIni(sec)
|
||||
}
|
||||
func (dbCfg *DatabaseConfig) readConfig(cfg *setting.Cfg) error {
|
||||
sec := cfg.Raw.Section("database")
|
||||
|
||||
func (dbCfg *DatabaseConfig) parseConfigIni(sec *ini.Section) error {
|
||||
cfgURL := sec.Key("url").String()
|
||||
if len(cfgURL) != 0 {
|
||||
dbURL, err := url.Parse(cfgURL)
|
||||
@@ -108,6 +101,7 @@ func (dbCfg *DatabaseConfig) parseConfigIni(sec *ini.Section) error {
|
||||
dbCfg.MaxOpenConn = sec.Key("max_open_conn").MustInt(0)
|
||||
dbCfg.MaxIdleConn = sec.Key("max_idle_conn").MustInt(2)
|
||||
dbCfg.ConnMaxLifetime = sec.Key("conn_max_lifetime").MustInt(14400)
|
||||
|
||||
dbCfg.SslMode = sec.Key("ssl_mode").String()
|
||||
dbCfg.SSLSNI = sec.Key("ssl_sni").String()
|
||||
dbCfg.CaCertPath = sec.Key("ca_cert_path").String()
|
||||
@@ -116,20 +110,19 @@ func (dbCfg *DatabaseConfig) parseConfigIni(sec *ini.Section) error {
|
||||
dbCfg.ServerCertName = sec.Key("server_cert_name").String()
|
||||
dbCfg.Path = sec.Key("path").MustString("data/grafana.db")
|
||||
dbCfg.IsolationLevel = sec.Key("isolation_level").String()
|
||||
|
||||
dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
|
||||
dbCfg.WALEnabled = sec.Key("wal").MustBool(false)
|
||||
dbCfg.SkipMigrations = sec.Key("skip_migrations").MustBool()
|
||||
dbCfg.MigrationLock = sec.Key("migration_locking").MustBool(true)
|
||||
dbCfg.MigrationLockAttemptTimeout = sec.Key("locking_attempt_timeout_sec").MustInt()
|
||||
|
||||
dbCfg.QueryRetries = sec.Key("query_retries").MustInt()
|
||||
dbCfg.TransactionRetries = sec.Key("transaction_retries").MustInt(5)
|
||||
dbCfg.LogQueries = sec.Key("log_queries").MustBool(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
// readConfig is a wrapper around readConfigSection that read the "database" configuration block.
|
||||
func (dbCfg *DatabaseConfig) readConfig(cfg *setting.Cfg) error {
|
||||
return dbCfg.readConfigSection(cfg, "database")
|
||||
dbCfg.LogQueries = sec.Key("log_queries").MustBool(false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dbCfg *DatabaseConfig) buildConnectionString(cfg *setting.Cfg, features featuremgmt.FeatureToggles) error {
|
||||
@@ -235,50 +228,3 @@ func buildExtraConnectionString(sep rune, urlQueryParams map[string][]string) st
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func validateReplicaConfigs(primary *DatabaseConfig, cfgs []DatabaseConfig) error {
|
||||
if cfgs == nil {
|
||||
return errors.New("cfg cannot be nil")
|
||||
}
|
||||
|
||||
// Return multiple errors so we can fix them all at once!
|
||||
var result error
|
||||
|
||||
// Check for duplicate connection strings
|
||||
seen := make(map[string]struct{})
|
||||
seen[primary.ConnectionString] = struct{}{}
|
||||
for _, cfg := range cfgs {
|
||||
if _, ok := seen[cfg.ConnectionString]; ok {
|
||||
result = errors.Join(result, errors.New("duplicate connection string"))
|
||||
} else {
|
||||
seen[cfg.ConnectionString] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that every database is the same type and version, and that it matches the primary database.
|
||||
// The database Yype may include a "withHooks" suffix, which is used to differentiate drivers for instrumentation and ignored for the purpose of this check.
|
||||
for _, cfg := range cfgs {
|
||||
if databaseDriverFromName(cfg.Type) != databaseDriverFromName(primary.Type) {
|
||||
result = errors.Join(result, fmt.Errorf("the replicas must have the same database type as the primary database (%s != %s)", primary.Type, cfg.Type))
|
||||
break // Only need to report this once
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// databaseDriverFromName strips any suffixes from the driver type that are not relevant to the database driver.
|
||||
// This is used to remove the "WithHooks" or "ReplWithHooks" suffixes which are used to differentiate drivers for instrumentation.
|
||||
func databaseDriverFromName(driverTy string) string {
|
||||
if strings.HasPrefix(driverTy, migrator.MySQL) {
|
||||
return migrator.MySQL
|
||||
}
|
||||
if strings.HasPrefix(driverTy, migrator.Postgres) {
|
||||
return migrator.Postgres
|
||||
}
|
||||
if strings.HasPrefix(driverTy, migrator.SQLite) {
|
||||
return migrator.SQLite
|
||||
}
|
||||
// default
|
||||
return driverTy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user