Skip to content

Commit

Permalink
Removed persitence behavior from config
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Dec 6, 2024
1 parent 77c3bf6 commit 010c325
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 67 deletions.
19 changes: 1 addition & 18 deletions go/cmd/dolt/commands/sqlserver/command_line_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type commandLineServerConfig struct {
requireSecureTransport bool
maxLoggedQueryLen int
shouldEncodeLoggedQuery bool
persistenceBehavior string
privilegeFilePath string
branchControlFilePath string
allowCleartextPasswords bool
Expand All @@ -73,7 +72,6 @@ func DefaultCommandLineServerConfig() *commandLineServerConfig {
autoCommit: servercfg.DefaultAutoCommit,
maxConnections: servercfg.DefaultMaxConnections,
queryParallelism: servercfg.DefaultQueryParallelism,
persistenceBehavior: servercfg.DefaultPersistenceBahavior,
dataDir: servercfg.DefaultDataDir,
cfgDir: filepath.Join(servercfg.DefaultDataDir, servercfg.DefaultCfgDir),
privilegeFilePath: filepath.Join(servercfg.DefaultDataDir, servercfg.DefaultCfgDir, servercfg.DefaultPrivilegeFilePath),
Expand Down Expand Up @@ -123,11 +121,7 @@ func NewCommandLineConfig(creds *cli.UserPassword, apr *argparser.ArgParseResult
val := true
config.WithRemotesapiReadOnly(&val)
}

if persistenceBehavior, ok := apr.GetValue(persistenceBehaviorFlag); ok {
config.withPersistenceBehavior(persistenceBehavior)
}


if timeoutStr, ok := apr.GetValue(timeoutFlag); ok {
timeout, err := strconv.ParseUint(timeoutStr, 10, 64)

Expand Down Expand Up @@ -241,11 +235,6 @@ func (cfg *commandLineServerConfig) QueryParallelism() int {
return cfg.queryParallelism
}

// PersistenceBehavior returns whether to autoload persisted server configuration
func (cfg *commandLineServerConfig) PersistenceBehavior() string {
return cfg.persistenceBehavior
}

// TLSKey returns a path to the servers PEM-encoded private TLS key. "" if there is none.
func (cfg *commandLineServerConfig) TLSKey() string {
return cfg.tlsKey
Expand Down Expand Up @@ -420,12 +409,6 @@ func (cfg *commandLineServerConfig) withCfgDir(cfgDir string) *commandLineServer
return cfg
}

// withPersistenceBehavior updates persistence behavior of system globals on server init
func (cfg *commandLineServerConfig) withPersistenceBehavior(persistenceBehavior string) *commandLineServerConfig {
cfg.persistenceBehavior = persistenceBehavior
return cfg
}

// withPrivilegeFilePath updates the path to the file which contains all needed privilege information in the form of a JSON string
func (cfg *commandLineServerConfig) withPrivilegeFilePath(privFilePath string) *commandLineServerConfig {
cfg.privilegeFilePath = privFilePath
Expand Down
15 changes: 3 additions & 12 deletions go/cmd/dolt/commands/sqlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,18 +956,9 @@ func getConfigFromServerConfig(serverConfig servercfg.ServerConfig) (server.Conf
return server.Config{}, err
}

// if persist is 'load' we use currently set persisted global variable,
// else if 'ignore' we set persisted global variable to current value from serverConfig
if serverConfig.PersistenceBehavior() == servercfg.LoadPerisistentGlobals {
serverConf, err = serverConf.NewConfig()
if err != nil {
return server.Config{}, err
}
} else {
err = sql.SystemVariables.SetGlobal("max_connections", serverConfig.MaxConnections())
if err != nil {
return server.Config{}, err
}
serverConf, err = serverConf.NewConfig()
if err != nil {
return server.Config{}, err
}

// Do not set the value of Version. Let it default to what go-mysql-server uses. This should be equivalent
Expand Down
2 changes: 0 additions & 2 deletions go/cmd/dolt/commands/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
configFileFlag = "config"
queryParallelismFlag = "query-parallelism"
maxConnectionsFlag = "max-connections"
persistenceBehaviorFlag = "persistence-behavior"
allowCleartextPasswordsFlag = "allow-cleartext-passwords"
socketFlag = "socket"
remotesapiPortFlag = "remotesapi-port"
Expand Down Expand Up @@ -172,7 +171,6 @@ func (cmd SqlServerCmd) ArgParserWithName(name string) *argparser.ArgParser {
ap.SupportsFlag(noAutoCommitFlag, "", "Set @@autocommit = off for the server.")
ap.SupportsInt(queryParallelismFlag, "", "num-go-routines", "Deprecated, no effect in current versions of Dolt")
ap.SupportsInt(maxConnectionsFlag, "", "max-connections", fmt.Sprintf("Set the number of connections handled by the server. Defaults to `%d`.", serverConfig.MaxConnections()))
ap.SupportsString(persistenceBehaviorFlag, "", "persistence-behavior", fmt.Sprintf("Indicate whether to `load` or `ignore` persisted global variables. Defaults to `%s`.", serverConfig.PersistenceBehavior()))
ap.SupportsString(commands.PrivsFilePathFlag, "", "privilege file", "Path to a file to load and store users and grants. Defaults to `$doltcfg-dir/privileges.db`. Will be created as needed.")
ap.SupportsString(commands.BranchCtrlPathFlag, "", "branch control file", "Path to a file to load and store branch control permissions. Defaults to `$doltcfg-dir/branch_control.db`. Will be created as needed.")
ap.SupportsString(allowCleartextPasswordsFlag, "", "allow-cleartext-passwords", "Allows use of cleartext passwords. Defaults to false.")
Expand Down
8 changes: 0 additions & 8 deletions go/libraries/doltcore/servercfg/serverconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const (
DefaultDoltTransactionCommit = false
DefaultMaxConnections = 100
DefaultQueryParallelism = 0
DefaultPersistenceBahavior = LoadPerisistentGlobals
DefaultDataDir = "."
DefaultCfgDir = ".doltcfg"
DefaultPrivilegeFilePath = "privileges.db"
Expand All @@ -64,10 +63,6 @@ const (
DefaultEncodeLoggedQuery = false
)

const (
IgnorePeristentGlobals = "ignore"
LoadPerisistentGlobals = "load"
)

func ptr[T any](t T) *T {
return &t
Expand Down Expand Up @@ -169,8 +164,6 @@ type ServerConfig interface {
// If true, queries will be logged as base64 encoded strings.
// If false (default behavior), queries will be logged as strings, but newlines and tabs will be replaced with spaces.
ShouldEncodeLoggedQuery() bool
// PersistenceBehavior is "load" if we include persisted system globals on server init
PersistenceBehavior() string
// DisableClientMultiStatements is true if we want the server to not
// process incoming ComQuery packets as if they had multiple queries in
// them, even if the client advertises support for MULTI_STATEMENTS.
Expand Down Expand Up @@ -218,7 +211,6 @@ func DefaultServerConfig() ServerConfig {
BehaviorConfig: BehaviorYAMLConfig{
ReadOnly: ptr(DefaultReadOnly),
AutoCommit: ptr(DefaultAutoCommit),
PersistenceBehavior: ptr(DefaultPersistenceBahavior),
DoltTransactionCommit: ptr(DefaultDoltTransactionCommit),
},
UserConfig: UserYAMLConfig{
Expand Down
45 changes: 18 additions & 27 deletions go/libraries/doltcore/servercfg/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func nillableIntPtr(n int) *int {
type BehaviorYAMLConfig struct {
ReadOnly *bool `yaml:"read_only"`
AutoCommit *bool `yaml:"autocommit"`
// PersistenceBehavior regulates loading persisted system variable configuration.
PersistenceBehavior *string `yaml:"persistence_behavior"`
// PersistenceBehavior is unused, but still present to prevent breaking any YAML configs that still use it.
PersistenceBehavior *string `yaml:"persistence_behavior,omitempty"`
// Disable processing CLIENT_MULTI_STATEMENTS support on the
// sql server. Dolt's handling of CLIENT_MULTI_STATEMENTS is currently
// broken. If a client advertises to support it (mysql cli client
Expand Down Expand Up @@ -174,34 +174,33 @@ func YamlConfigFromFile(fs filesys.Filesys, path string) (ServerConfig, error) {
}

func ServerConfigAsYAMLConfig(cfg ServerConfig) *YAMLConfig {
systemVars := map[string]interface{}(cfg.SystemVars())
systemVars := cfg.SystemVars()
return &YAMLConfig{
LogLevelStr: ptr(string(cfg.LogLevel())),
MaxQueryLenInLogs: nillableIntPtr(cfg.MaxLoggedQueryLen()),
EncodeLoggedQuery: nillableBoolPtr(cfg.ShouldEncodeLoggedQuery()),
BehaviorConfig: BehaviorYAMLConfig{
ptr(cfg.ReadOnly()),
ptr(cfg.AutoCommit()),
ptr(cfg.PersistenceBehavior()),
ptr(cfg.DisableClientMultiStatements()),
ptr(cfg.DoltTransactionCommit()),
ptr(cfg.EventSchedulerStatus()),
ReadOnly: ptr(cfg.ReadOnly()),
AutoCommit: ptr(cfg.AutoCommit()),
DisableClientMultiStatements: ptr(cfg.DisableClientMultiStatements()),
DoltTransactionCommit: ptr(cfg.DoltTransactionCommit()),
EventSchedulerStatus: ptr(cfg.EventSchedulerStatus()),
},
UserConfig: UserYAMLConfig{
Name: ptr(cfg.User()),
Password: ptr(cfg.Password()),
},
ListenerConfig: ListenerYAMLConfig{
ptr(cfg.Host()),
ptr(cfg.Port()),
ptr(cfg.MaxConnections()),
ptr(cfg.ReadTimeout()),
ptr(cfg.WriteTimeout()),
nillableStrPtr(cfg.TLSKey()),
nillableStrPtr(cfg.TLSCert()),
nillableBoolPtr(cfg.RequireSecureTransport()),
nillableBoolPtr(cfg.AllowCleartextPasswords()),
nillableStrPtr(cfg.Socket()),
HostStr: ptr(cfg.Host()),
PortNumber: ptr(cfg.Port()),
MaxConnections: ptr(cfg.MaxConnections()),
ReadTimeoutMillis: ptr(cfg.ReadTimeout()),
WriteTimeoutMillis: ptr(cfg.WriteTimeout()),
TLSKey: nillableStrPtr(cfg.TLSKey()),
TLSCert: nillableStrPtr(cfg.TLSCert()),
RequireSecureTransport: nillableBoolPtr(cfg.RequireSecureTransport()),
AllowCleartextPasswords: nillableBoolPtr(cfg.AllowCleartextPasswords()),
Socket: nillableStrPtr(cfg.Socket()),
},
PerformanceConfig: PerformanceYAMLConfig{
QueryParallelism: nillableIntPtr(cfg.QueryParallelism()),
Expand Down Expand Up @@ -528,14 +527,6 @@ func (cfg YAMLConfig) ShouldEncodeLoggedQuery() bool {
return *cfg.EncodeLoggedQuery
}

// PersistenceBehavior is "load" if we include persisted system globals on server init
func (cfg YAMLConfig) PersistenceBehavior() string {
if cfg.BehaviorConfig.PersistenceBehavior == nil {
return LoadPerisistentGlobals
}
return *cfg.BehaviorConfig.PersistenceBehavior
}

// DataDir is the path to a directory to use as the data dir, both to create new databases and locate existing ones.
func (cfg YAMLConfig) DataDir() string {
if cfg.DataDirStr != nil {
Expand Down

0 comments on commit 010c325

Please sign in to comment.