Start starts the replicator, setting the state to ReplicationStateStarting and starting the status reporter.
(ctx context.Context)
| 142 | |
| 143 | // Start starts the replicator, setting the state to ReplicationStateStarting and starting the status reporter. |
| 144 | func (arc *activeReplicatorCommon) Start(ctx context.Context) error { |
| 145 | arc.lock.Lock() |
| 146 | defer arc.lock.Unlock() |
| 147 | |
| 148 | if arc.ctx != nil && arc.ctx.Err() == nil { |
| 149 | return fmt.Errorf("Replicator is already running") |
| 150 | } |
| 151 | |
| 152 | arc.setState(ReplicationStateStarting) |
| 153 | logCtx := base.CorrelationIDLogCtx(ctx, |
| 154 | arc.config.ID+"-"+string(arc.direction)) |
| 155 | arc.ctx, arc.ctxCancel = context.WithCancel(logCtx) |
| 156 | |
| 157 | arc.startStatusReporter(arc.ctx) |
| 158 | |
| 159 | err := arc.replicatorConnectFn() |
| 160 | if err != nil { |
| 161 | arc.setError(err) |
| 162 | base.WarnfCtx(arc.ctx, "Couldn't connect: %s", err) |
| 163 | if errors.Is(err, fatalReplicatorConnectError) { |
| 164 | base.WarnfCtx(arc.ctx, "Stopping replication connection attempt") |
| 165 | defer arc.ctxCancel() |
| 166 | } else { |
| 167 | base.InfofCtx(arc.ctx, base.KeyReplicate, "Attempting to reconnect in background: %v", err) |
| 168 | arc.reconnect() |
| 169 | } |
| 170 | } |
| 171 | arc._publishStatus() |
| 172 | return err |
| 173 | } |
| 174 | |
| 175 | // initCheckpointer starts a checkpointer. The remoteCheckpoints are only for collections and indexed by the blip collectionIdx. If using default collection only, replicationCheckpoints is an empty array. |
| 176 | func (arc *activeReplicatorCommon) _initCheckpointer(remoteCheckpoints []replicationCheckpoint) error { |
nothing calls this directly
no test coverage detected