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

Function replicate

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

Source from the content-addressed store, hash-verified

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