couch-continuum
Advanced tools
Comparing version 2.3.0 to 2.3.1
68
index.js
@@ -28,2 +28,6 @@ const assert = require('assert').strict | ||
const displayUrl = (url) => { | ||
return url.host + url.pathname | ||
} | ||
module.exports = | ||
@@ -196,4 +200,4 @@ class CouchContinuum { | ||
replicateSecurity: this.replicateSecurity, | ||
source: `${this.source.host}${this.source.pathname}`, | ||
target: `${this.target.host}${this.target.pathname}`, | ||
source: `${displayUrl(this.source)}`, | ||
target: `${displayUrl(this.target)}`, | ||
url: this.url.host | ||
@@ -244,11 +248,15 @@ }, undefined, 2)}`) | ||
const timer = setInterval(async () => { | ||
const { doc_count: latest } = await request({ | ||
url: target.href, | ||
json: true | ||
}) | ||
const delta = latest - current | ||
bar.tick(delta) | ||
current = latest | ||
if (bar.complete) clearInterval(timer) | ||
// TODO catch errors produced by this loop | ||
try { | ||
const { doc_count: latest } = await request({ | ||
url: target.href, | ||
json: true | ||
}) | ||
const delta = latest - current | ||
bar.tick(delta) | ||
current = latest | ||
if (bar.complete) clearInterval(timer) | ||
} catch (e) { | ||
clearTimeout(timer) | ||
throw e | ||
} | ||
}, this.interval) | ||
@@ -260,2 +268,3 @@ await request({ | ||
}) | ||
await this._waitForCompletion({ source, target }) | ||
// copy security object over | ||
@@ -278,2 +287,29 @@ if (this.replicateSecurity) { | ||
async _waitForCompletion ({ source, target }) { | ||
const srcName = `/${source.pathname.slice(1)}/` | ||
const tgtName = `/${target.pathname.slice(1)}/` | ||
const isUs = (task) => { | ||
return task.source?.includes(srcName) && | ||
task.target?.includes(tgtName) && | ||
task.missing_revisions_found > task.docs_written | ||
} | ||
while (true) { | ||
const tasks = await request({ | ||
url: `${this.url.href}_active_tasks`, | ||
json: true | ||
}) | ||
if (tasks.some(isUs)) { | ||
await this._sleep(1000) | ||
} else { | ||
return | ||
} | ||
} | ||
} | ||
_sleep (msecs) { | ||
return new Promise((resolve) => setTimeout(resolve, msecs)) | ||
} | ||
async _verifyReplica () { | ||
@@ -344,3 +380,3 @@ const { doc_count: docCount1 } = await request({ | ||
async createReplica () { | ||
log(`Creating replica ${this.target.host}${this.target.pathname}...`) | ||
log(`Creating replica ${displayUrl(this.target)}...`) | ||
log('[0/5] Checking if primary is in use...') | ||
@@ -353,3 +389,3 @@ if (this.allowReplications) { | ||
const lastSeq1 = await this._getUpdateSeq(this.source.href) | ||
log(`[1/5] Creating replica db: ${this.target.host}${this.target.pathname}`) | ||
log(`[1/5] Creating replica db: ${displayUrl(this.target)}`) | ||
await this._createDb(this.target.href) | ||
@@ -371,3 +407,3 @@ log('[2/5] Beginning replication of primary to replica...') | ||
const lastSeq2 = await this._getUpdateSeq(this.source.href) | ||
assert(lastSeq1 <= lastSeq2, `${this.source.host}${this.source.pathname} is still receiving updates. Exiting...`) | ||
assert(lastSeq1 <= lastSeq2, `${displayUrl(this.source)} is still receiving updates. Exiting...`) | ||
log('[4/5] Verifying primary and replica match...') | ||
@@ -379,3 +415,3 @@ await this._verifyReplica() | ||
async replacePrimary () { | ||
log(`Replacing primary ${this.source.host}${this.source.pathname} using ${this.target.host}${this.target.pathname}...`) | ||
log(`Replacing primary ${displayUrl(this.source)} using ${displayUrl(this.target)}...`) | ||
log('[0/8] Checking if primary is in use...') | ||
@@ -396,3 +432,3 @@ if (this.allowReplications) { | ||
// out the rapid recreation. | ||
console.log(`[${name}] Recreating primary ${this.source.host}${this.source.pathname}`) | ||
console.log(`[${name}] Recreating primary ${displayUrl(this.source)}`) | ||
const text = `[${name}] (:bar) :percent :etas` | ||
@@ -399,0 +435,0 @@ const bar = new ProgressBar(text, { |
{ | ||
"name": "couch-continuum", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Tool for migrating CouchDB databases to new configuration values.", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"dependency-check": "^4.1.0", | ||
"mocha": "^8.0.1", | ||
"mocha": "^10.2.0", | ||
"standard": "^14.3.4" | ||
@@ -24,0 +24,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
56277
13
996
0