Categorygithub.com/couchbaselabs/sg-replicate
modulepackage
0.0.0-20200807125530-6fb5493d6168
Repository: https://github.com/couchbaselabs/sg-replicate.git
Documentation: pkg.go.dev

# README

Join the chat at https://gitter.im/couchbase/mobile Build Status GoDoc Coverage Status Go Report Card codebeat badge

sg-replicate is a tool that can drive a replication between Sync Gateway instances.

It was created because the Sync Gateway can only serve as a passive replication target, but it does not offer a mechanism to drive a replication. This tool attempts to fill that gap.

architecture

Sync Gateway integration

sg-replicate has been integrated into Sync Gateway itself, and that is probably how you want to use it, unless you have a specific need to run it standalone. See the documentation on Sync Gateway Replications for usage instructions.

Quickstart - build from source

Note: there is no need to clone this repo, because the go get command below will take care of that for you

  • Install Go and define $GOPATH environment variable (eg, export GOPATH=~/gocode)
  • $ go get -u -v github.com/couchbaselabs/sg-replicate/... -- clones this repo and all source dependencies into $GOPATH/src
  • $ cd ${GOPATH}/src/github.com/couchbaselabs/sg-replicate/cli
  • $ cp config.json.example config.json
  • Customize config.json to contain the server URLs of your source and target server.
  • Build and run:
$ go build && ./cli

Notes on command behavior:

  • If you have any continuous replications, the command will block indefinitely, and only exit if there is a non-recoverable error with a continuous replication.
  • If you only have oneshot replications defined, the command will exit once they have all completed.

Features

  • Json configuration file to specify replications
  • Supports multiple replications running concurrently
  • Can run both OneShot and Continuous replications
  • Does not store anything persistently
  • Stateless -- can be interrupted/restarted anytime without negative side effects.
  • Filter replications using channels.

Documentation

GoDoc

Sample Configuration

{
    "changes_feed_limit": 50,
    "continuous_retry_time_ms": 15000,
    "replications":{
        "db-local":{
            "source_url": "http://localhost:4985",
            "source_db": "db",
            "target_db": "db-copy",
            "lifecycle": "oneshot"
        },
        "grocery-sync-local":{
            "source_url": "http://localhost:4985",
            "target_url": "http://sync.couchbasecloud.com",
            "source_db": "grocery-sync",
            "target_db": "grocery-sync",
            "lifecycle": "continuous",
            "channels": ["lists", "items"]
        }
    }
}

Configuration fields

  • changes_feed_limit -- the number of changes to fetch in each "batch". Setting this to a larger value will increase memory consumption.
  • continuous_retry_time_ms -- the amount of time to wait (in milliseconds) after an aborted replication before retrying. (only applicable to continuous replications)
  • replications -- a "map" of replications, where each replication has a unique name. they will be run in the order given in this file.
  • source_url -- url of source sync gateway, without the db name in the url. Can point to admin port (:4985) or user port (:4984), but be aware if you point it to the user port, you will probably need to set a username/pass in the url and will only replicate docs visible to that user.
  • source_db -- the source db to pull from.
  • target_url -- url of target sync gateway, without the db name in the url. If omitted, it will be assumed that it's the same as the source_url See source_url for discussion of which port to use.
  • target_db -- the target db to push to.
  • channels -- the set of channels that replication should be restricted to.
  • disabled -- is this replication currently disabled? (true | false)
  • lifecycle -- possible values: oneshot or continuous.
    • oneshot replications will be run inline (synchronously), and it will not start the following replications until the oneshot replication completes.
    • continuous replications are started in parallel with other continuous replications, and run indefinitely until they have a non-recoverable error.

Filing Issues

Please file issues in the Sync Gateway issue tracker. sg-replicate is now an officially supported component of Sync Gateway.

Todo

  • Logs are difficult to disentangle when multiple replications are running -- workaround: use separate instances and separate config files for each replication
  • Clean up API to only expose what's necessary
  • Attachments handling should be made to be more efficient. Currently, attachment data is temporarily stored in memory before it is pushed to the target server.
  • targetCheckpointAddress needs to take more things into account when generating checkpoint address.

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Read the documents from the _bulk_get response.
Run a one-shot replication synchronously (eg, block until finished).
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
the replication aborted due to some error or unexpected event.
after replication.Start() is called, this will be emitted.
the replication stopped due to being cancelled by client.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
the replication finished "naturally", eg, successfully.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AtomicBool is a a boolean that can be atomically set and read, that satisfies the Var interface.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Wraps a Replication (which should be renamed to "OneShotReplication") and drives it, creating a "pseudo-continuous replication".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ReplicationStats stores values for the given replication.
No description provided by the author

# Interfaces

No description provided by the author
Interface for interacting with either Replication or ContinuousReplication.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
A function that takes a Document as a parameter and returns a boolean value.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author