(ctx context.Context, config *ActiveReplicatorConfig, direction ActiveReplicatorDirection)
| 83 | } |
| 84 | |
| 85 | func newActiveReplicatorCommon(ctx context.Context, config *ActiveReplicatorConfig, direction ActiveReplicatorDirection) (*activeReplicatorCommon, error) { |
| 86 | |
| 87 | var replicationStats *BlipSyncStats |
| 88 | var checkpointID string |
| 89 | switch direction { |
| 90 | case ActiveReplicatorTypePush: |
| 91 | replicationStats = BlipSyncStatsForSGRPush(config.ReplicationStatsMap) |
| 92 | checkpointID = PushCheckpointID(config.ID) |
| 93 | case ActiveReplicatorTypePull: |
| 94 | replicationStats = BlipSyncStatsForSGRPull(config.ReplicationStatsMap) |
| 95 | checkpointID = PullCheckpointID(config.ID) |
| 96 | default: |
| 97 | return nil, fmt.Errorf("Invalid replicator direction: %v", direction) |
| 98 | } |
| 99 | |
| 100 | if config.CheckpointInterval == 0 { |
| 101 | config.CheckpointInterval = DefaultCheckpointInterval |
| 102 | } |
| 103 | |
| 104 | initialStatus, err := LoadReplicationStatus(ctx, config.ActiveDB.DatabaseContext, config.ID) |
| 105 | if err != nil { |
| 106 | // Not finding an initialStatus isn't fatal, but we should at least log that we'll reset stats when we do... |
| 107 | base.InfofCtx(ctx, base.KeyReplicate, "Couldn't load initial replication status for %q: %v - stats will be reset", config.ID, err) |
| 108 | } |
| 109 | |
| 110 | checkpointID = config.checkpointPrefix + checkpointID |
| 111 | |
| 112 | metakeys := base.DefaultMetadataKeys |
| 113 | if config.ActiveDB != nil { |
| 114 | metakeys = config.ActiveDB.MetadataKeys |
| 115 | } |
| 116 | |
| 117 | arc := activeReplicatorCommon{ |
| 118 | config: config, |
| 119 | state: ReplicationStateStopped, |
| 120 | replicationStats: replicationStats, |
| 121 | CheckpointID: checkpointID, |
| 122 | initialStatus: initialStatus, |
| 123 | statusKey: metakeys.ReplicationStatusKey(checkpointID), |
| 124 | direction: direction, |
| 125 | } |
| 126 | |
| 127 | if config.CollectionsEnabled { |
| 128 | arc.namedCollections = make(map[base.ScopeAndCollectionName]*activeReplicatorCollection) |
| 129 | } else { |
| 130 | defaultDatabaseCollection, err := config.ActiveDB.GetDefaultDatabaseCollection() |
| 131 | if err != nil { |
| 132 | return nil, err |
| 133 | } |
| 134 | arc.defaultCollection = &activeReplicatorCollection{ |
| 135 | metadataStore: config.ActiveDB.MetadataStore, |
| 136 | collectionDataStore: defaultDatabaseCollection.dataStore, |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return &arc, nil |
| 141 | } |
| 142 |
no test coverage detected