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

Function startReplication

server/server.go:230–271  ·  view source on GitHub ↗

startReplication begins the background thread that replicates from Postgres, if one is configured.

(cfg *servercfg.DoltgresConfig, ssCfg doltservercfg.ServerConfig)

Source from the content-addressed store, hash-verified

228
229// startReplication begins the background thread that replicates from Postgres, if one is configured.
230func startReplication(cfg *servercfg.DoltgresConfig, ssCfg doltservercfg.ServerConfig) (*logrepl.LogicalReplicator, error) {
231 if cfg.PostgresReplicationConfig == nil {
232 return nil, nil
233 } else if cfg.PostgresReplicationConfig.PostgresDatabase == nil || *cfg.PostgresReplicationConfig.PostgresDatabase == "" {
234 return nil, errors.Errorf("postgres replication database must be specified and not empty for replication")
235 } else if cfg.PostgresReplicationConfig.PostgresUser == nil || *cfg.PostgresReplicationConfig.PostgresUser == "" {
236 return nil, errors.Errorf("postgres replication user must be specified and not empty for replication")
237 } else if cfg.PostgresReplicationConfig.PostgresPassword == nil || *cfg.PostgresReplicationConfig.PostgresPassword == "" {
238 return nil, errors.Errorf("postgres replication password must be specified and not empty for replication")
239 } else if cfg.PostgresReplicationConfig.PostgresPort == nil || *cfg.PostgresReplicationConfig.PostgresPort == 0 {
240 return nil, errors.Errorf("postgres replication port must be specified and non-zero for replication")
241 } else if cfg.PostgresReplicationConfig.SlotName == nil || *cfg.PostgresReplicationConfig.SlotName == "" {
242 return nil, errors.Errorf("postgres replication slot name must be specified and not empty for replication")
243 }
244
245 walFilePath := filepath.Join(ssCfg.CfgDir(), "pg_wal_location")
246 primaryDns := fmt.Sprintf(
247 "postgres://%s:%s@%s:%d/%s",
248 *cfg.PostgresReplicationConfig.PostgresUser,
249 *cfg.PostgresReplicationConfig.PostgresPassword,
250 *cfg.PostgresReplicationConfig.PostgresServerAddress,
251 *cfg.PostgresReplicationConfig.PostgresPort,
252 *cfg.PostgresReplicationConfig.PostgresDatabase,
253 )
254
255 replicationDns := fmt.Sprintf(
256 "postgres://%s:%s@localhost:%d/%s",
257 ssCfg.User(),
258 ssCfg.Password(),
259 ssCfg.Port(),
260 "postgres", // TODO: this needs to come from config
261 )
262
263 replicator, err := logrepl.NewLogicalReplicator(walFilePath, primaryDns, replicationDns)
264 if err != nil {
265 return nil, err
266 }
267
268 cli.Println("Starting replication")
269 go replicator.StartReplication(*cfg.PostgresReplicationConfig.SlotName)
270 return replicator, nil
271}
272
273// configCliContext is a minimal implementation of CliContext that only supports Config()
274type configCliContext struct {

Callers 1

runServerFunction · 0.85

Calls 7

StartReplicationMethod · 0.95
NewLogicalReplicatorFunction · 0.92
CfgDirMethod · 0.80
UserMethod · 0.80
PortMethod · 0.80
ErrorfMethod · 0.65
PasswordMethod · 0.45

Tested by

no test coverage detected