MCPcopy Create free account
hub / github.com/dolthub/doltgresql / runServer

Function runServer

server/server.go:90–196  ·  view source on GitHub ↗

runServer starts the server based on the given args, using the provided file system as the backing store. The returned WaitGroup may be used to wait for the server to close.

(ctx context.Context, cfg *servercfg.DoltgresConfig, dEnv *env.DoltEnv, protocolListenerFactory server.ProtocolListenerFunc)

Source from the content-addressed store, hash-verified

88// runServer starts the server based on the given args, using the provided file system as the backing store.
89// The returned WaitGroup may be used to wait for the server to close.
90func runServer(ctx context.Context, cfg *servercfg.DoltgresConfig, dEnv *env.DoltEnv, protocolListenerFactory server.ProtocolListenerFunc) (*svcs.Controller, error) {
91 initialization.Initialize(dEnv, cfg)
92
93 if dEnv.HasDoltDataDir() {
94 cwd, _ := dEnv.FS.Abs(".")
95 return nil, errors.Errorf("Cannot start a server within a directory containing a Dolt or Doltgres database. "+
96 "To use the current directory (%s) as a database, start the server from the parent directory.", cwd)
97 }
98
99 defer tempfiles.MovableTempFileProvider.Clean()
100
101 sql.SystemVariables.SetGlobal(sql.NewContext(ctx), dsess.DoltStatsEnabled, false)
102
103 err := dsess.InitPersistedSystemVars(dEnv)
104 if err != nil {
105 return nil, errors.Errorf("failed to load persisted system variables: %w", err)
106 }
107
108 ssCfg := cfg.ToSqlServerConfig()
109 // The sql context can't be passed in because doesn't exist yet.
110 // But since it's only needed to read from the db and the db doesn't exist yet either, this is safe.
111 err = doltservercfg.ApplySystemVariables(nil, ssCfg, sql.SystemVariables)
112 if err != nil {
113 return nil, err
114 }
115
116 tlsConfig, err := doltservercfg.LoadTLSConfig(ssCfg)
117 if err != nil {
118 return nil, err
119 }
120
121 if tlsConfig != nil && len(tlsConfig.Certificates) > 0 {
122 certificate = tlsConfig.Certificates[0]
123 }
124
125 // We need a username and password for many SQL commands, so set defaults if they don't exist
126 user, _ := auth.GetSuperUserAndPassword()
127 dEnv.Config.SetFailsafes(map[string]string{
128 config.UserNameKey: user,
129 config.UserEmailKey: fmt.Sprintf(DefUserEmailFmt, user),
130 })
131
132 // Reload the dolt environment with the correct data dir that was specified in the configuration.
133 // This initial dEnv instance is loaded for the current working directory.
134 dataDirFs, err := dEnv.FS.WithWorkingDir(ssCfg.DataDir())
135 if err != nil {
136 return nil, err
137 }
138 dEnv = env.Load(ctx, dEnv.GetUserHomeDir, dataDirFs, doltdb.LocalDirDoltDB, dEnv.Version)
139
140 // Determine whether we need to initialize the default database
141 initializeDefaultDatabase := true
142 mrEnv, err := env.MultiEnvForDirectory(ctx, dataDirFs, dEnv)
143 if err != nil {
144 return nil, err
145 }
146 mrEnv.Iter(func(_ string, _ *env.DoltEnv) (stop bool, err error) {
147 initializeDefaultDatabase = false

Callers 2

RunOnDiskFunction · 0.70
RunInMemoryFunction · 0.70

Calls 11

InitializeFunction · 0.92
GetSuperUserAndPasswordFunction · 0.92
createDefaultDatabaseFunction · 0.85
startReplicationFunction · 0.85
ToSqlServerConfigMethod · 0.80
DataDirMethod · 0.80
StartMethod · 0.80
ErrorfMethod · 0.65
NewContextMethod · 0.65
IterMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected