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

Function replicate

lib/index-browser.js:9729–10264  ·  view source on GitHub ↗
(src, target, opts, returnValue, result)

Source from the content-addressed store, hash-verified

9727}
9728
9729function replicate(src, target, opts, returnValue, result) {
9730 var batches = []; // list of batches to be processed
9731 var currentBatch; // the batch currently being processed
9732 var pendingBatch = {
9733 seq: 0,
9734 changes: [],
9735 docs: []
9736 }; // next batch, not yet ready to be processed
9737 var writingCheckpoint = false; // true while checkpoint is being written
9738 var changesCompleted = false; // true when all changes received
9739 var replicationCompleted = false; // true when replication has completed
9740 // initial_last_seq is the state of the source db before
9741 // replication started, and it is _not_ updated during
9742 // replication or used anywhere else, as opposed to last_seq
9743 var initial_last_seq = 0;
9744 var last_seq = 0;
9745 var continuous = opts.continuous || opts.live || false;
9746 var batch_size = opts.batch_size || 100;
9747 var batches_limit = opts.batches_limit || 10;
9748 var style = opts.style || 'all_docs';
9749 var changesPending = false; // true while src.changes is running
9750 var doc_ids = opts.doc_ids;
9751 var selector = opts.selector;
9752 var repId;
9753 var checkpointer;
9754 var changedDocs = [];
9755 // Like couchdb, every replication gets a unique session id
9756 var session = uuid$1();
9757 var taskId;
9758
9759 result = result || {
9760 ok: true,
9761 start_time: new Date().toISOString(),
9762 docs_read: 0,
9763 docs_written: 0,
9764 doc_write_failures: 0,
9765 errors: []
9766 };
9767
9768 var changesOpts = {};
9769 returnValue.ready(src, target);
9770
9771 function initCheckpointer() {
9772 if (checkpointer) {
9773 return Promise.resolve();
9774 }
9775 return generateReplicationId(src, target, opts).then(function (res) {
9776 repId = res;
9777
9778 var checkpointOpts = {};
9779 if (opts.checkpoint === false) {
9780 checkpointOpts = { writeSourceCheckpoint: false, writeTargetCheckpoint: false };
9781 } else if (opts.checkpoint === 'source') {
9782 checkpointOpts = { writeSourceCheckpoint: true, writeTargetCheckpoint: false };
9783 } else if (opts.checkpoint === 'target') {
9784 checkpointOpts = { writeSourceCheckpoint: false, writeTargetCheckpoint: true };
9785 } else {
9786 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…