MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / NewActiveReplicator

Function NewActiveReplicator

db/active_replicator.go:36–66  ·  view source on GitHub ↗

NewActiveReplicator returns a bidirectional active replicator for the given config.

(ctx context.Context, config *ActiveReplicatorConfig)

Source from the content-addressed store, hash-verified

34
35// NewActiveReplicator returns a bidirectional active replicator for the given config.
36func NewActiveReplicator(ctx context.Context, config *ActiveReplicatorConfig) (*ActiveReplicator, error) {
37 ar := &ActiveReplicator{
38 ID: config.ID,
39 config: config,
40 }
41
42 if pushReplication := config.Direction == ActiveReplicatorTypePush || config.Direction == ActiveReplicatorTypePushAndPull; pushReplication {
43 var err error
44 ar.Push, err = NewPushReplicator(ctx, config)
45 if err != nil {
46 return nil, err
47 }
48 if ar.config.onComplete != nil {
49 ar.Push.onReplicatorComplete = ar._onReplicationComplete
50 }
51 }
52
53 if pullReplication := config.Direction == ActiveReplicatorTypePull || config.Direction == ActiveReplicatorTypePushAndPull; pullReplication {
54 var err error
55 ar.Pull, err = NewPullReplicator(ctx, config)
56 if err != nil {
57 return nil, err
58 }
59 if ar.config.onComplete != nil {
60 ar.Pull.onReplicatorComplete = ar._onReplicationComplete
61 }
62 }
63
64 base.InfofCtx(ctx, base.KeyReplicate, "Created active replicator ID:%s", config.ID)
65 return ar, nil
66}
67
68func (ar *ActiveReplicator) Start(ctx context.Context) error {
69

Calls 3

InfofCtxFunction · 0.92
NewPushReplicatorFunction · 0.85
NewPullReplicatorFunction · 0.85