Complete gracefully shuts down a replication, waiting for all in-flight revisions to be processed before stopping the replication
()
| 125 | // Complete gracefully shuts down a replication, waiting for all in-flight revisions to be processed |
| 126 | // before stopping the replication |
| 127 | func (apr *ActivePullReplicator) Complete() { |
| 128 | base.TracefCtx(apr.ctx, base.KeyReplicate, "ActivePullReplicator.Complete()") |
| 129 | apr.lock.Lock() |
| 130 | _ = apr.forEachCollection(func(c *activeReplicatorCollection) error { |
| 131 | base.TracefCtx(apr.ctx, base.KeyReplicate, "Before calling waitForExpectedSequences in Complete()") |
| 132 | if err := c.Checkpointer.waitForExpectedSequences(); err != nil { |
| 133 | base.InfofCtx(apr.ctx, base.KeyReplicate, "Couldn't drain replication %s - stopping anyway: %v", apr.config.ID, err) |
| 134 | } |
| 135 | base.TracefCtx(apr.ctx, base.KeyReplicate, "After calling waitForExpectedSequences in Complete()") |
| 136 | return nil |
| 137 | }) |
| 138 | |
| 139 | apr._stop() |
| 140 | |
| 141 | base.TracefCtx(apr.ctx, base.KeyReplicate, "Calling disconnect from Complete() in active replicator pull") |
| 142 | stopErr := apr._disconnect() |
| 143 | if stopErr != nil { |
| 144 | base.InfofCtx(apr.ctx, base.KeyReplicate, "Error attempting to stop replication %s: %v", apr.config.ID, stopErr) |
| 145 | } |
| 146 | apr.setState(ReplicationStateStopped) |
| 147 | |
| 148 | // unlock the replication before triggering callback, in case callback attempts to access replication information |
| 149 | // from the replicator |
| 150 | onCompleteCallback := apr.onReplicatorComplete |
| 151 | |
| 152 | apr._publishStatus() |
| 153 | apr.lock.Unlock() |
| 154 | |
| 155 | if onCompleteCallback != nil { |
| 156 | onCompleteCallback() |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // _getStatus returns current replicator status. Requires holding ActivePullReplicator.lock as a read lock. |
| 161 | func (apr *ActivePullReplicator) _getStatus() *ReplicationStatus { |
no test coverage detected