MCPcopy Index your code
hub / github.com/apache/pouchdb / replicate

Function replicate

lib/index.es.js:9758–10293  ·  view source on GitHub ↗
(src, target, opts, returnValue, result)

Source from the content-addressed store, hash-verified

9756}
9757
9758function replicate(src, target, opts, returnValue, result) {
9759 var batches = []; // list of batches to be processed
9760 var currentBatch; // the batch currently being processed
9761 var pendingBatch = {
9762 seq: 0,
9763 changes: [],
9764 docs: []
9765 }; // next batch, not yet ready to be processed
9766 var writingCheckpoint = false; // true while checkpoint is being written
9767 var changesCompleted = false; // true when all changes received
9768 var replicationCompleted = false; // true when replication has completed
9769 // initial_last_seq is the state of the source db before
9770 // replication started, and it is _not_ updated during
9771 // replication or used anywhere else, as opposed to last_seq
9772 var initial_last_seq = 0;
9773 var last_seq = 0;
9774 var continuous = opts.continuous || opts.live || false;
9775 var batch_size = opts.batch_size || 100;
9776 var batches_limit = opts.batches_limit || 10;
9777 var style = opts.style || 'all_docs';
9778 var changesPending = false; // true while src.changes is running
9779 var doc_ids = opts.doc_ids;
9780 var selector = opts.selector;
9781 var repId;
9782 var checkpointer;
9783 var changedDocs = [];
9784 // Like couchdb, every replication gets a unique session id
9785 var session = uuid();
9786 var taskId;
9787
9788 result = result || {
9789 ok: true,
9790 start_time: new Date().toISOString(),
9791 docs_read: 0,
9792 docs_written: 0,
9793 doc_write_failures: 0,
9794 errors: []
9795 };
9796
9797 var changesOpts = {};
9798 returnValue.ready(src, target);
9799
9800 function initCheckpointer() {
9801 if (checkpointer) {
9802 return Promise.resolve();
9803 }
9804 return generateReplicationId(src, target, opts).then(function (res$$1) {
9805 repId = res$$1;
9806
9807 var checkpointOpts = {};
9808 if (opts.checkpoint === false) {
9809 checkpointOpts = { writeSourceCheckpoint: false, writeTargetCheckpoint: false };
9810 } else if (opts.checkpoint === 'source') {
9811 checkpointOpts = { writeSourceCheckpoint: true, writeTargetCheckpoint: false };
9812 } else if (opts.checkpoint === 'target') {
9813 checkpointOpts = { writeSourceCheckpoint: false, writeTargetCheckpoint: true };
9814 } else {
9815 checkpointOpts = { writeSourceCheckpoint: true, writeTargetCheckpoint: true };

Callers 2

completeReplicationFunction · 0.70
replicateWrapperFunction · 0.70

Calls 5

completeReplicationFunction · 0.70
startChangesFunction · 0.70
initCheckpointerFunction · 0.70
readyMethod · 0.45
writeCheckpointMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…