NewActiveReplicatorConfig converts an incoming ReplicationCfg to an ActiveReplicatorConfig
(config *ReplicationCfg)
| 557 | |
| 558 | // NewActiveReplicatorConfig converts an incoming ReplicationCfg to an ActiveReplicatorConfig |
| 559 | func (m *sgReplicateManager) NewActiveReplicatorConfig(config *ReplicationCfg) (rc *ActiveReplicatorConfig, err error) { |
| 560 | insecureSkipVerify := false |
| 561 | if m.dbContext.Options.UnsupportedOptions != nil { |
| 562 | insecureSkipVerify = m.dbContext.Options.UnsupportedOptions.SgrTlsSkipVerify |
| 563 | } |
| 564 | |
| 565 | activeDB := &Database{DatabaseContext: m.dbContext} |
| 566 | if config.RunAs != "" { |
| 567 | user, err := m.dbContext.Authenticator(m.loggingCtx).GetUser(config.RunAs) |
| 568 | if err != nil { |
| 569 | return nil, err |
| 570 | } |
| 571 | activeDB.SetUser(user) |
| 572 | } |
| 573 | |
| 574 | rc = &ActiveReplicatorConfig{ |
| 575 | ID: config.ID, |
| 576 | Continuous: config.Continuous, |
| 577 | ActiveDB: activeDB, |
| 578 | CollectionsEnabled: config.CollectionsEnabled, |
| 579 | CollectionsLocal: config.CollectionsLocal, |
| 580 | CollectionsRemote: config.CollectionsRemote, |
| 581 | PurgeOnRemoval: config.PurgeOnRemoval, |
| 582 | DeltasEnabled: config.DeltaSyncEnabled, |
| 583 | InsecureSkipVerify: insecureSkipVerify, |
| 584 | CheckpointInterval: m.CheckpointInterval, |
| 585 | RunAs: config.RunAs, |
| 586 | } |
| 587 | |
| 588 | rc.MaxReconnectInterval = defaultMaxReconnectInterval |
| 589 | if config.MaxBackoff != 0 { |
| 590 | rc.MaxReconnectInterval = time.Duration(config.MaxBackoff) * time.Minute |
| 591 | } |
| 592 | |
| 593 | // If maxBackoff is zero, retry up to ~MaxReconnectInterval and then give up. |
| 594 | // If non-zero, reconnect is indefinite. |
| 595 | if config.MaxBackoff == 0 { |
| 596 | rc.TotalReconnectTimeout = rc.MaxReconnectInterval * 2 |
| 597 | } |
| 598 | |
| 599 | rc.ChangesBatchSize = defaultChangesBatchSize |
| 600 | if config.BatchSize > 0 { |
| 601 | rc.ChangesBatchSize = uint16(config.BatchSize) |
| 602 | } |
| 603 | |
| 604 | // Channel filter processing |
| 605 | if config.Filter == base.ByChannelFilter { |
| 606 | rc.Filter = base.ByChannelFilter |
| 607 | if err := rc.setFilterChannels(config); err != nil { |
| 608 | return nil, err |
| 609 | } |
| 610 | } |
| 611 | rc.Direction = config.Direction |
| 612 | |
| 613 | // Set conflict resolver for pull replications. Currently, at this point we don't know if the replication will |
| 614 | // be sub-protocol version 4 or < 4 so we must set both conflict resolver functions. In addition, we must have |
| 615 | // both available for the possibility of replicating a document that exists both side fo the replication already |
| 616 | // but both are legacy pre upgrades docs without HLV. |