@vrtmrz/livesync-commonlib 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/LSError.d.ts +13 -0
- package/dist/common/LSError.js +19 -1
- package/dist/diagnostics/local.d.ts +7 -2
- package/dist/interfaces/DatabaseFileAccess.d.ts +20 -4
- package/dist/interfaces/FileHandler.d.ts +67 -1
- package/dist/interfaces/FileHandler.js +16 -0
- package/dist/interfaces/StorageEventManager.d.ts +7 -0
- package/dist/managers/ChunkFetcher.d.ts +16 -0
- package/dist/managers/ChunkFetcher.js +190 -112
- package/dist/managers/EntryManager/EntryManager.d.ts +7 -0
- package/dist/managers/EntryManager/EntryManager.js +6 -0
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +9 -5
- package/dist/managers/EntryManager/EntryManagerImpls.js +103 -76
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +7 -3
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +83 -16
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +3 -2
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +38 -36
- package/dist/managers/LayeredChunkManager/types.d.ts +15 -1
- package/dist/managers/LayeredChunkManager.d.ts +4 -0
- package/dist/managers/LayeredChunkManager.js +19 -6
- package/dist/managers/LiveSyncManagers.d.ts +2 -0
- package/dist/managers/LiveSyncManagers.js +6 -0
- package/dist/managers/StorageEventManager.d.ts +22 -0
- package/dist/managers/StorageEventManager.js +48 -1
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +32 -0
- package/dist/pouchdb/LiveSyncLocalDB.js +72 -18
- package/dist/pouchdb/LocalDatabaseReadScope.d.ts +24 -0
- package/dist/pouchdb/LocalDatabaseReadScope.js +62 -0
- package/dist/pouchdb/encryption.policy.js +2 -1
- package/dist/pouchdb/pathIdentityCompatibility.d.ts +6 -2
- package/dist/pouchdb/pathIdentityCompatibility.js +15 -10
- package/dist/replication/UnsupportedEncryptedDocumentFormatError.d.ts +13 -0
- package/dist/replication/UnsupportedEncryptedDocumentFormatError.js +28 -0
- package/dist/replication/contentRead.d.ts +3 -0
- package/dist/replication/contentRead.js +4 -0
- package/dist/replication/couchdb/LiveSyncReplicator.d.ts +11 -2
- package/dist/replication/couchdb/LiveSyncReplicator.js +207 -131
- package/dist/replication/index.d.ts +6 -1
- package/dist/replication/index.js +20 -1
- package/dist/serviceFeatures/offlineScanner/files.d.ts +1 -1
- package/dist/serviceFeatures/offlineScanner/files.js +27 -7
- package/dist/serviceFeatures/offlineScanner/scan.d.ts +5 -1
- package/dist/serviceFeatures/offlineScanner/scan.js +2 -1
- package/dist/serviceFeatures/offlineScanner.d.ts +1 -1
- package/dist/serviceFeatures/offlineScanner.js +10 -2
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +13 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +190 -123
- package/dist/serviceModules/ServiceFileHandlerBase/deletion.js +17 -7
- package/dist/serviceModules/ServiceFileHandlerBase/events.d.ts +3 -2
- package/dist/serviceModules/ServiceFileHandlerBase/events.js +9 -9
- package/dist/serviceModules/ServiceFileHandlerBase/protection.js +24 -9
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.d.ts +10 -0
- package/dist/serviceModules/ServiceFileHandlerBase/provenance.js +28 -4
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.d.ts +11 -5
- package/dist/serviceModules/ServiceFileHandlerBase/reflection.js +144 -58
- package/dist/serviceModules/ServiceFileHandlerBase/saving.js +16 -2
- package/dist/serviceModules/ServiceFileHandlerBase/scanning.js +1 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +7 -2
- package/dist/serviceModules/ServiceFileHandlerBase.js +13 -4
- package/dist/services/base/ControlService.js +1 -5
- package/dist/services/base/DatabaseEventService.d.ts +3 -0
- package/dist/services/base/DatabaseEventService.js +3 -0
- package/dist/services/base/DatabaseService.d.ts +15 -0
- package/dist/services/base/DatabaseService.js +85 -4
- package/dist/services/base/IService.d.ts +18 -1
- package/dist/services/base/KeyValueDBService.d.ts +5 -4
- package/dist/services/base/KeyValueDBService.js +46 -48
- package/dist/services/base/ReplicationService.d.ts +4 -1
- package/dist/services/base/ReplicationService.js +8 -1
- package/dist/services/base/VaultScanResult.d.ts +5 -0
- package/dist/services/lib/HandlerUtils.d.ts +40 -5
- package/dist/services/lib/HandlerUtils.js +52 -4
- package/docs/development.md +8 -0
- package/docs/offline-scanner.md +57 -3
- package/docs/releasing.md +43 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
getUnencryptedContentRejection,
|
|
4
4
|
isUnencryptedContentRejectedError
|
|
5
5
|
} from "../UnencryptedContentRejectedError.js";
|
|
6
|
+
import { UnsupportedEncryptedDocumentFormatError } from "../UnsupportedEncryptedDocumentFormatError.js";
|
|
6
7
|
import { observeReplicationProgress } from "./replicationProgress.js";
|
|
7
8
|
import {
|
|
8
9
|
VER,
|
|
@@ -27,13 +28,13 @@ import {
|
|
|
27
28
|
arrayToChunkedArray,
|
|
28
29
|
parseHeaderValues
|
|
29
30
|
} from "../../common/utils.js";
|
|
30
|
-
import { Logger } from "../../common/logger.js";
|
|
31
31
|
import { checkRemoteVersion, countCompromisedChunks, declareRemoteFeatures } from "../../pouchdb/negotiation.js";
|
|
32
32
|
import { requiredRemoteFeatures, usesEncryptedInternalMetadata } from "../../pouchdb/remoteFeatureCompatibility.js";
|
|
33
33
|
import { assessRemoteDocumentIds } from "../../pouchdb/remoteIdCompatibility.js";
|
|
34
34
|
import { isErrorOfMissingDoc } from "../../pouchdb/utils_couchdb.js";
|
|
35
35
|
import { preprocessOutgoing } from "../../pouchdb/encryption.js";
|
|
36
36
|
import { prepareInitialFetchFastForward } from "./fastForward.js";
|
|
37
|
+
import { ContentReadError, LiveSyncError, RemoteRequestError } from "../../common/LSError.js";
|
|
37
38
|
import { ensureDatabaseIsCompatible, getEffectiveTweakValues } from "../../pouchdb/LiveSyncDBFunctions.js";
|
|
38
39
|
import {
|
|
39
40
|
LiveSyncAbstractReplicator
|
|
@@ -80,12 +81,12 @@ class OneShotConnectivityPreflightTimeoutError extends Error {
|
|
|
80
81
|
this.name = "OneShotConnectivityPreflightTimeoutError";
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
async function* genReplication(s, signal) {
|
|
84
|
+
async function* genReplication(s, signal, log) {
|
|
84
85
|
const inbox = new StreamInbox({ capacity: 1e4 });
|
|
85
86
|
const push = function(e) {
|
|
86
87
|
if (signal.aborted || inbox.isClosed) return;
|
|
87
88
|
if (inbox.post(e)) return;
|
|
88
|
-
|
|
89
|
+
log(`Replication event queue is full: ${e[0]}`, LOG_LEVEL_VERBOSE);
|
|
89
90
|
if (e[0] === "error" || e[0] === "denied") {
|
|
90
91
|
inbox.error(e[1]);
|
|
91
92
|
} else if (e[0] === "complete" || e[0] === "finally") {
|
|
@@ -101,7 +102,8 @@ async function* genReplication(s, signal) {
|
|
|
101
102
|
const requestSource = s.pull ?? s;
|
|
102
103
|
let policyFailureReported = false;
|
|
103
104
|
const onRequestError = (error) => {
|
|
104
|
-
if (policyFailureReported
|
|
105
|
+
if (policyFailureReported) return;
|
|
106
|
+
if (!isUnencryptedContentRejectedError(error) && !UnsupportedEncryptedDocumentFormatError.findIn(error)) return;
|
|
105
107
|
policyFailureReported = true;
|
|
106
108
|
push(["error", error]);
|
|
107
109
|
};
|
|
@@ -118,7 +120,7 @@ async function* genReplication(s, signal) {
|
|
|
118
120
|
}
|
|
119
121
|
} catch (ex) {
|
|
120
122
|
if (ex instanceof Error && ex.name == "AbortError") {
|
|
121
|
-
|
|
123
|
+
log(`Replication aborted`, LOG_LEVEL_VERBOSE);
|
|
122
124
|
} else {
|
|
123
125
|
throw ex;
|
|
124
126
|
}
|
|
@@ -162,6 +164,9 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
162
164
|
super(env);
|
|
163
165
|
this.env = env;
|
|
164
166
|
}
|
|
167
|
+
log(message, level = LOG_LEVEL_INFO, key = "") {
|
|
168
|
+
this.env.services.API.addLog(message, level, key);
|
|
169
|
+
}
|
|
165
170
|
/** Own the checkpoint handoff for one fresh, suspended Fast Fetch only. */
|
|
166
171
|
createInitialFetchFastForwardResource(setting) {
|
|
167
172
|
const snapshot = { ...setting };
|
|
@@ -236,7 +241,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
236
241
|
}
|
|
237
242
|
return downloadedSyncParams;
|
|
238
243
|
} catch (ex) {
|
|
239
|
-
|
|
244
|
+
this.log(`Could not retrieve remote sync parameters`, LOG_LEVEL_INFO);
|
|
240
245
|
throw SyncParamsFetchError.fromError(ex);
|
|
241
246
|
}
|
|
242
247
|
}
|
|
@@ -249,7 +254,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
249
254
|
throw new SyncParamsUpdateError(`Could not store remote sync parameters: ${JSON.stringify(ret)}`);
|
|
250
255
|
}
|
|
251
256
|
} catch (ex) {
|
|
252
|
-
|
|
257
|
+
this.log(`Could not store remote sync parameters`, LOG_LEVEL_INFO);
|
|
253
258
|
throw SyncParamsUpdateError.fromError(ex);
|
|
254
259
|
}
|
|
255
260
|
}
|
|
@@ -263,7 +268,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
263
268
|
return await manager.getPBKDF2Salt(refresh);
|
|
264
269
|
}
|
|
265
270
|
async migrate(from, to) {
|
|
266
|
-
|
|
271
|
+
this.log(`Database updated from ${from} to ${to}`, LOG_LEVEL_NOTICE);
|
|
267
272
|
return Promise.resolve(true);
|
|
268
273
|
}
|
|
269
274
|
/** Abort only the active controller; internal transitions must not await their own task. */
|
|
@@ -325,6 +330,9 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
325
330
|
if (result === ONE_SHOT_REPLICATION_ALREADY_RUNNING) {
|
|
326
331
|
return replicationBlocked("replication-in-progress");
|
|
327
332
|
}
|
|
333
|
+
if (result instanceof UnsupportedEncryptedDocumentFormatError) {
|
|
334
|
+
return replicationFailed(result);
|
|
335
|
+
}
|
|
328
336
|
return outcomeFromFiniteOpenReplication(result, centralCompatibilityRecoveryHint(decision));
|
|
329
337
|
} catch (error) {
|
|
330
338
|
return replicationFailed(error, centralCompatibilityRecoveryHint(decision));
|
|
@@ -333,7 +341,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
333
341
|
replicationActivated(showResult) {
|
|
334
342
|
this.syncStatus = "CONNECTED";
|
|
335
343
|
this.updateInfo();
|
|
336
|
-
|
|
344
|
+
this.log("Replication activated", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "sync");
|
|
337
345
|
}
|
|
338
346
|
async replicationChangeDetected(e, showResult, docSentOnStart, docArrivedOnStart) {
|
|
339
347
|
try {
|
|
@@ -350,7 +358,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
350
358
|
const lastSyncPushSeq = this.lastSyncPushSeq;
|
|
351
359
|
const pushLast = lastSyncPushSeq == 0 ? "" : lastSyncPushSeq >= maxPushSeq ? " (LIVE)" : ` (${maxPushSeq - lastSyncPushSeq})`;
|
|
352
360
|
const pullLast = lastSyncPullSeq == 0 ? "" : lastSyncPullSeq >= maxPullSeq ? " (LIVE)" : ` (${maxPullSeq - lastSyncPullSeq})`;
|
|
353
|
-
|
|
361
|
+
this.log(
|
|
354
362
|
`\u2191${this.docSent - docSentOnStart}${pushLast} \u2193${this.docArrived - docArrivedOnStart}${pullLast}`,
|
|
355
363
|
LOG_LEVEL_NOTICE,
|
|
356
364
|
"sync"
|
|
@@ -358,47 +366,78 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
358
366
|
}
|
|
359
367
|
this.updateInfo();
|
|
360
368
|
} catch (ex) {
|
|
361
|
-
|
|
362
|
-
|
|
369
|
+
this.log("Replication callback error", LOG_LEVEL_NOTICE, "sync");
|
|
370
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
363
371
|
}
|
|
364
372
|
}
|
|
365
373
|
replicationCompleted(showResult) {
|
|
366
374
|
this.syncStatus = "COMPLETED";
|
|
367
375
|
this.updateInfo();
|
|
368
|
-
|
|
376
|
+
this.log("Replication completed", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, showResult ? "sync" : "");
|
|
369
377
|
this.abortController();
|
|
370
378
|
}
|
|
371
379
|
replicationDenied(e) {
|
|
372
380
|
this.syncStatus = "ERRORED";
|
|
373
381
|
this.updateInfo();
|
|
374
382
|
this.abortController();
|
|
375
|
-
|
|
376
|
-
|
|
383
|
+
this.log("Replication denied", LOG_LEVEL_NOTICE, "sync");
|
|
384
|
+
this.log(e, LOG_LEVEL_VERBOSE);
|
|
385
|
+
}
|
|
386
|
+
/** Ask the current owner to inspect ambiguous managed-operation failures without joining its drain. */
|
|
387
|
+
requestCurrentDatabaseInspection(error, database) {
|
|
388
|
+
if (error instanceof RemoteRequestError || error instanceof ContentReadError && !error.failure.resources.includes("local-database")) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const service = this.env.services.database;
|
|
392
|
+
if (!database || service?.localDatabaseDirect !== database || !service.onLocalDatabaseError) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
void Promise.resolve().then(() => {
|
|
396
|
+
if (service.localDatabaseDirect === database) {
|
|
397
|
+
return service.onLocalDatabaseError(database, error);
|
|
398
|
+
}
|
|
399
|
+
}).catch((failure) => {
|
|
400
|
+
this.log("Could not request current database inspection after replication failed.", LOG_LEVEL_VERBOSE);
|
|
401
|
+
this.log(failure, LOG_LEVEL_VERBOSE);
|
|
402
|
+
});
|
|
377
403
|
}
|
|
378
|
-
|
|
404
|
+
/** Report only the captured local read; recovery must not join the operation it drains. */
|
|
405
|
+
async readLocalDatabase(database, operation) {
|
|
406
|
+
try {
|
|
407
|
+
return await database.readFromDatabase(operation);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
if (!isErrorOfMissingDoc(error)) this.requestCurrentDatabaseInspection(error, database);
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
replicationErrored(e, database) {
|
|
379
414
|
this.syncStatus = "ERRORED";
|
|
380
415
|
this.abortController();
|
|
381
416
|
this.updateInfo();
|
|
382
417
|
if (isUnencryptedContentRejectedError(e)) {
|
|
383
|
-
|
|
418
|
+
this.log(getUnencryptedContentRejectionMessage("replication"), LOG_LEVEL_NOTICE, "sync");
|
|
384
419
|
const rejection = getUnencryptedContentRejection(e);
|
|
385
420
|
if (rejection) {
|
|
386
|
-
|
|
421
|
+
this.log(
|
|
387
422
|
`CouchDB replication rejected ${rejection.contentKind}: ${rejection.documentId}`,
|
|
388
423
|
LOG_LEVEL_VERBOSE
|
|
389
424
|
);
|
|
390
425
|
}
|
|
391
426
|
return;
|
|
392
427
|
}
|
|
393
|
-
|
|
394
|
-
|
|
428
|
+
if (!(e instanceof UnsupportedEncryptedDocumentFormatError)) {
|
|
429
|
+
this.requestCurrentDatabaseInspection(e, database);
|
|
430
|
+
}
|
|
431
|
+
this.log("Replication error", LOG_LEVEL_NOTICE, "sync");
|
|
432
|
+
this.log(e, LOG_LEVEL_VERBOSE);
|
|
395
433
|
}
|
|
396
434
|
replicationPaused() {
|
|
397
435
|
this.syncStatus = "PAUSED";
|
|
398
436
|
this.updateInfo();
|
|
399
|
-
|
|
437
|
+
this.log("Replication paused", LOG_LEVEL_VERBOSE, "sync");
|
|
400
438
|
}
|
|
401
439
|
async processSync(syncHandler, showResult, docSentOnStart, docArrivedOnStart, syncMode, retrying, reportCancelledAsDone = true) {
|
|
440
|
+
const databaseOwner = this.env.services.database?.localDatabaseDirect;
|
|
402
441
|
const controller = new AbortController();
|
|
403
442
|
if (this.controller) {
|
|
404
443
|
this.controller.abort();
|
|
@@ -415,12 +454,12 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
415
454
|
this.updateInfo();
|
|
416
455
|
}
|
|
417
456
|
);
|
|
418
|
-
const gen = genReplication(syncHandler, controller.signal);
|
|
457
|
+
const gen = genReplication(syncHandler, controller.signal, this.log.bind(this));
|
|
419
458
|
try {
|
|
420
459
|
for await (const [type, e] of gen) {
|
|
421
460
|
const releaser = await globalConcurrencyController.tryAcquire(1, REPLICATION_BUSY_TIMEOUT);
|
|
422
461
|
if (releaser === false) {
|
|
423
|
-
|
|
462
|
+
this.log("Replication stopped for busy.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "sync");
|
|
424
463
|
return "FAILED";
|
|
425
464
|
}
|
|
426
465
|
releaser();
|
|
@@ -469,13 +508,15 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
469
508
|
case "denied":
|
|
470
509
|
this.replicationDenied(e);
|
|
471
510
|
return "FAILED";
|
|
472
|
-
case "error":
|
|
473
|
-
|
|
511
|
+
case "error": {
|
|
512
|
+
const unsupportedFormat = UnsupportedEncryptedDocumentFormatError.findIn(e);
|
|
513
|
+
this.replicationErrored(unsupportedFormat ?? e, databaseOwner);
|
|
514
|
+
if (unsupportedFormat) return unsupportedFormat;
|
|
474
515
|
if (isUnencryptedContentRejectedError(e)) return "FAILED";
|
|
475
|
-
|
|
516
|
+
this.log("Replication stopped.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "sync");
|
|
476
517
|
if (this.env.services.remote.hadLastPostFailedBySize) {
|
|
477
518
|
if (e && e.status == 413) {
|
|
478
|
-
|
|
519
|
+
this.log(
|
|
479
520
|
`Something went wrong during synchronisation. Please check the log!`,
|
|
480
521
|
LOG_LEVEL_NOTICE
|
|
481
522
|
);
|
|
@@ -483,17 +524,18 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
483
524
|
}
|
|
484
525
|
return "NEED_RETRY";
|
|
485
526
|
} else {
|
|
486
|
-
|
|
487
|
-
|
|
527
|
+
this.log("Replication error", LOG_LEVEL_NOTICE, "sync");
|
|
528
|
+
this.log(e, LOG_LEVEL_VERBOSE);
|
|
488
529
|
}
|
|
489
530
|
return "FAILED";
|
|
531
|
+
}
|
|
490
532
|
case "paused":
|
|
491
533
|
this.replicationPaused();
|
|
492
534
|
break;
|
|
493
535
|
case "finally":
|
|
494
536
|
break;
|
|
495
537
|
default:
|
|
496
|
-
|
|
538
|
+
this.log(`Unexpected synchronization status:${JSON.stringify(e)}`);
|
|
497
539
|
}
|
|
498
540
|
}
|
|
499
541
|
if (reportCancelledAsDone) {
|
|
@@ -501,12 +543,14 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
501
543
|
}
|
|
502
544
|
return "CANCELLED";
|
|
503
545
|
} catch (ex) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
546
|
+
const unsupportedFormat = UnsupportedEncryptedDocumentFormatError.findIn(ex);
|
|
547
|
+
if (unsupportedFormat || isUnencryptedContentRejectedError(ex)) {
|
|
548
|
+
this.replicationErrored(unsupportedFormat ?? ex, databaseOwner);
|
|
549
|
+
return unsupportedFormat ?? "FAILED";
|
|
507
550
|
}
|
|
508
|
-
|
|
509
|
-
|
|
551
|
+
this.requestCurrentDatabaseInspection(ex, databaseOwner);
|
|
552
|
+
this.log(`Unexpected synchronization exception`);
|
|
553
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
510
554
|
return "FAILED";
|
|
511
555
|
} finally {
|
|
512
556
|
progress.dispose();
|
|
@@ -553,7 +597,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
553
597
|
}
|
|
554
598
|
maxSeq = seq;
|
|
555
599
|
}
|
|
556
|
-
|
|
600
|
+
this.log(`Updating max seq on chunk to ${maxSeq}`, LOG_LEVEL_VERBOSE);
|
|
557
601
|
newMax.maxSeq = maxSeq;
|
|
558
602
|
const previous_max_seq_on_chunk = await wrapException(() => localDB.get(newMax._id));
|
|
559
603
|
if (previous_max_seq_on_chunk instanceof Error) {
|
|
@@ -575,7 +619,7 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
575
619
|
if (!remoteDB) {
|
|
576
620
|
const d = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
577
621
|
if (typeof d === "string") {
|
|
578
|
-
|
|
622
|
+
this.log(
|
|
579
623
|
this.translate("liveSyncReplicator.couldNotConnectToRemoteDb", { d }),
|
|
580
624
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
581
625
|
"fetch"
|
|
@@ -587,12 +631,13 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
587
631
|
const connectivity = await this.checkReplicationConnectivity(setting, false, false, false, false);
|
|
588
632
|
if (connectivity === false) return false;
|
|
589
633
|
await this.closeRemoteConnection(connectivity);
|
|
590
|
-
|
|
634
|
+
this.log(`Bulk sending chunks to remote database...`, showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "fetch");
|
|
591
635
|
const remoteMilestone = await remoteDB.get(MILESTONE_DOCID);
|
|
592
636
|
const remoteID = remoteMilestone?.created ?? 0;
|
|
593
|
-
const
|
|
637
|
+
const localOwner = this.env.services.database.localDatabase;
|
|
638
|
+
const localDB = localOwner.localDatabase;
|
|
594
639
|
const te = new TextEncoder();
|
|
595
|
-
|
|
640
|
+
this.log(
|
|
596
641
|
this.translate("liveSyncReplicator.checkingLastSyncPoint"),
|
|
597
642
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
598
643
|
"fetch"
|
|
@@ -644,13 +689,13 @@ class LiveSyncCouchDBReplicator extends LiveSyncAbstractReplicator {
|
|
|
644
689
|
let sendingDocs = 0;
|
|
645
690
|
let sentDocsCount = 0;
|
|
646
691
|
const sendChunks = async (bulkDocs, bulkDocsSize, seq2) => {
|
|
647
|
-
|
|
692
|
+
this.log(
|
|
648
693
|
`Sending ${bulkDocs.length} (${bulkDocsSize} => ${sizeToHumanReadable(bulkDocsSize)} in plain) chunks to remote database...`,
|
|
649
694
|
LOG_LEVEL_VERBOSE
|
|
650
695
|
);
|
|
651
696
|
const releaser = await semaphore.acquire(1);
|
|
652
697
|
sendingDocs += bulkDocs.length;
|
|
653
|
-
|
|
698
|
+
this.log(
|
|
654
699
|
`\u2191 Uploading chunks
|
|
655
700
|
${sendingDocs}/(${sentDocsCount} done)`,
|
|
656
701
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
@@ -663,15 +708,15 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
663
708
|
uploadBulkDocs.forEach((e) => sentMap[idSeqMap[e._id]] = true);
|
|
664
709
|
await this.updateMaxTransferredSeqOnChunks(localDB, remoteID, sentMap);
|
|
665
710
|
sentDocsCount += bulkDocs.length;
|
|
666
|
-
|
|
711
|
+
this.log(
|
|
667
712
|
`\u2191 Uploading chunks
|
|
668
713
|
${sendingDocs}/(${sentDocsCount} done)`,
|
|
669
714
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
670
715
|
"send"
|
|
671
716
|
);
|
|
672
717
|
} catch (ex) {
|
|
673
|
-
|
|
674
|
-
|
|
718
|
+
this.log("Bulk sending failed.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "send");
|
|
719
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
675
720
|
return false;
|
|
676
721
|
} finally {
|
|
677
722
|
releaser();
|
|
@@ -709,8 +754,8 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
709
754
|
try {
|
|
710
755
|
return await e;
|
|
711
756
|
} catch (ex) {
|
|
712
|
-
|
|
713
|
-
|
|
757
|
+
this.log("Bulk sending failed.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "send");
|
|
758
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
714
759
|
return false;
|
|
715
760
|
}
|
|
716
761
|
})
|
|
@@ -732,7 +777,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
732
777
|
recordCompatibilityDecision,
|
|
733
778
|
cancellationRequested
|
|
734
779
|
);
|
|
735
|
-
return result ===
|
|
780
|
+
return result === true;
|
|
736
781
|
}
|
|
737
782
|
/**
|
|
738
783
|
* Run one finite CouchDB transfer and close its owned remote connection.
|
|
@@ -762,15 +807,16 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
762
807
|
return false;
|
|
763
808
|
}
|
|
764
809
|
if (this.controller) {
|
|
765
|
-
|
|
810
|
+
this.log(
|
|
766
811
|
this.translate("liveSyncReplicator.replicationInProgress"),
|
|
767
812
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
768
813
|
"sync"
|
|
769
814
|
);
|
|
770
815
|
return false;
|
|
771
816
|
}
|
|
772
|
-
const
|
|
773
|
-
|
|
817
|
+
const localOwner = this.env.services.database.localDatabase;
|
|
818
|
+
const localDB = localOwner.localDatabase;
|
|
819
|
+
this.log(this.translate("liveSyncReplicator.oneShotSyncBegin", { syncMode }));
|
|
774
820
|
const ret = await this.checkOneShotReplicationConnectivity(
|
|
775
821
|
setting,
|
|
776
822
|
false,
|
|
@@ -780,7 +826,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
780
826
|
);
|
|
781
827
|
if (ret === false) {
|
|
782
828
|
if (!cancellationRequested()) {
|
|
783
|
-
|
|
829
|
+
this.log(
|
|
784
830
|
this.translate("liveSyncReplicator.couldNotConnectToServer"),
|
|
785
831
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
786
832
|
"sync"
|
|
@@ -794,12 +840,16 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
794
840
|
return false;
|
|
795
841
|
}
|
|
796
842
|
this.maxPullSeq = Number(`${ret.info.update_seq}`.split("-")[0]);
|
|
797
|
-
this.maxPushSeq = Number(
|
|
843
|
+
this.maxPushSeq = Number(
|
|
844
|
+
`${(await this.readLocalDatabase(localOwner, (pouch) => pouch.info())).update_seq}`.split(
|
|
845
|
+
"-"
|
|
846
|
+
)[0]
|
|
847
|
+
);
|
|
798
848
|
if (cancellationRequested()) {
|
|
799
849
|
return false;
|
|
800
850
|
}
|
|
801
851
|
if (showResult) {
|
|
802
|
-
|
|
852
|
+
this.log(this.translate("liveSyncReplicator.checkingLastSyncPoint"), LOG_LEVEL_NOTICE, "sync");
|
|
803
853
|
}
|
|
804
854
|
this.syncStatus = "STARTED";
|
|
805
855
|
this.updateInfo();
|
|
@@ -829,12 +879,15 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
829
879
|
return false;
|
|
830
880
|
}
|
|
831
881
|
if (syncResult == "DONE") {
|
|
882
|
+
if (syncMode !== "pushOnly") {
|
|
883
|
+
await this.notifyFiniteReplicationCompleted();
|
|
884
|
+
}
|
|
832
885
|
return true;
|
|
833
886
|
}
|
|
834
|
-
if (syncResult
|
|
835
|
-
return
|
|
887
|
+
if (syncResult instanceof UnsupportedEncryptedDocumentFormatError) {
|
|
888
|
+
return syncResult;
|
|
836
889
|
}
|
|
837
|
-
if (syncResult == "FAILED") {
|
|
890
|
+
if (syncResult == "CANCELLED" || syncResult == "FAILED") {
|
|
838
891
|
return false;
|
|
839
892
|
}
|
|
840
893
|
if (syncResult == "NEED_RESURRECT") {
|
|
@@ -854,13 +907,13 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
854
907
|
tempSetting.batch_size = Math.ceil(tempSetting.batch_size / 2) + 2;
|
|
855
908
|
tempSetting.batches_limit = Math.ceil(tempSetting.batches_limit / 2) + 2;
|
|
856
909
|
if (tempSetting.batch_size <= 5 && tempSetting.batches_limit <= 5) {
|
|
857
|
-
|
|
910
|
+
this.log(
|
|
858
911
|
this.translate("liveSyncReplicator.cantReplicateLowerValue"),
|
|
859
912
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO
|
|
860
913
|
);
|
|
861
914
|
return false;
|
|
862
915
|
} else {
|
|
863
|
-
|
|
916
|
+
this.log(
|
|
864
917
|
this.translate("liveSyncReplicator.retryLowerBatchSize", {
|
|
865
918
|
batch_size: tempSetting.batch_size.toString(),
|
|
866
919
|
batches_limit: tempSetting.batches_limit.toString()
|
|
@@ -892,10 +945,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
892
945
|
if (!ownsSharedAttempt) {
|
|
893
946
|
return ONE_SHOT_REPLICATION_ALREADY_RUNNING;
|
|
894
947
|
}
|
|
895
|
-
|
|
896
|
-
return next;
|
|
897
|
-
}
|
|
898
|
-
return await next();
|
|
948
|
+
return typeof next === "function" ? await next() : next;
|
|
899
949
|
}
|
|
900
950
|
async checkOneShotReplicationConnectivity(setting, skipCheck, showResult, ignoreCleanLock, recordCompatibilityDecision) {
|
|
901
951
|
if (setting.useRequestAPI) {
|
|
@@ -939,8 +989,20 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
939
989
|
try {
|
|
940
990
|
await connection.close();
|
|
941
991
|
} catch (ex) {
|
|
942
|
-
|
|
943
|
-
|
|
992
|
+
this.log("Failed to close remote database.", LOG_LEVEL_INFO, "sync");
|
|
993
|
+
this.log(ex, LOG_LEVEL_VERBOSE, "sync");
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
async notifyFiniteReplicationCompleted() {
|
|
997
|
+
const handler = this.env.services.replication?.onFiniteReplicationCompleted;
|
|
998
|
+
if (typeof handler !== "function") {
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
try {
|
|
1002
|
+
await handler();
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
this.log("A finite-replication completion observer failed.", LOG_LEVEL_VERBOSE, "sync");
|
|
1005
|
+
this.log(error, LOG_LEVEL_VERBOSE, "sync");
|
|
944
1006
|
}
|
|
945
1007
|
}
|
|
946
1008
|
async withRemoteConnection(connection, task) {
|
|
@@ -966,21 +1028,21 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
966
1028
|
if (!connectionOptions?.signal?.aborted || !(connectionOptions.signal.reason instanceof OneShotConnectivityPreflightTimeoutError)) {
|
|
967
1029
|
return false;
|
|
968
1030
|
}
|
|
969
|
-
|
|
1031
|
+
this.log("The remote connectivity check timed out.", showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO, "sync");
|
|
970
1032
|
if (error !== void 0) {
|
|
971
|
-
|
|
1033
|
+
this.log(error, LOG_LEVEL_VERBOSE, "sync");
|
|
972
1034
|
}
|
|
973
1035
|
return true;
|
|
974
1036
|
}
|
|
975
1037
|
async checkReplicationConnectivity(setting, keepAlive, skipCheck, showResult, ignoreCleanLock = false, connectionOptions, recordCompatibilityDecision) {
|
|
976
1038
|
recordCompatibilityDecision?.(CENTRAL_COMPATIBILITY_NOT_ASSESSED);
|
|
977
1039
|
if (setting.versionUpFlash != "") {
|
|
978
|
-
|
|
1040
|
+
this.log(this.translate("Replicator.Message.VersionUpFlash"), LOG_LEVEL_NOTICE);
|
|
979
1041
|
return false;
|
|
980
1042
|
}
|
|
981
1043
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
982
1044
|
if (this.controller) {
|
|
983
|
-
|
|
1045
|
+
this.log("Another replication running.");
|
|
984
1046
|
return false;
|
|
985
1047
|
}
|
|
986
1048
|
let dbRet;
|
|
@@ -1002,7 +1064,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1002
1064
|
if (this.reportConnectivityPreflightTimeout(connectionOptions, showResult)) {
|
|
1003
1065
|
return false;
|
|
1004
1066
|
}
|
|
1005
|
-
|
|
1067
|
+
this.log(
|
|
1006
1068
|
this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }),
|
|
1007
1069
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO
|
|
1008
1070
|
);
|
|
@@ -1012,12 +1074,18 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1012
1074
|
try {
|
|
1013
1075
|
try {
|
|
1014
1076
|
await assertDatabasePathIdentity(dbRet.db, setting);
|
|
1015
|
-
|
|
1077
|
+
const localOwner = this.env.services.database.localDatabase;
|
|
1078
|
+
await assertDatabasePathIdentity(
|
|
1079
|
+
localOwner.localDatabase,
|
|
1080
|
+
setting,
|
|
1081
|
+
false,
|
|
1082
|
+
(operation) => this.readLocalDatabase(localOwner, () => operation())
|
|
1083
|
+
);
|
|
1016
1084
|
} catch (error) {
|
|
1017
1085
|
recordCompatibilityDecision?.(
|
|
1018
1086
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.INCOMPATIBLE_VERSION)
|
|
1019
1087
|
);
|
|
1020
|
-
|
|
1088
|
+
this.log(error, LOG_LEVEL_NOTICE);
|
|
1021
1089
|
return false;
|
|
1022
1090
|
}
|
|
1023
1091
|
if (!skipCheck) {
|
|
@@ -1035,17 +1103,17 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1035
1103
|
recordCompatibilityDecision?.(
|
|
1036
1104
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.ID_DERIVATION_MISMATCH)
|
|
1037
1105
|
);
|
|
1038
|
-
|
|
1106
|
+
this.log("The remote document IDs do not match the configured ID key.", LOG_LEVEL_NOTICE);
|
|
1039
1107
|
return false;
|
|
1040
1108
|
}
|
|
1041
1109
|
if (idCompatibility === "unverified" && setting.idDerivationVersion === 1 && setting.usePathObfuscation) {
|
|
1042
|
-
|
|
1110
|
+
this.log("No remote document was available to verify the configured ID key.", LOG_LEVEL_INFO);
|
|
1043
1111
|
}
|
|
1044
1112
|
if (!await checkRemoteVersion(dbRet.db, this.migrate.bind(this), VER)) {
|
|
1045
1113
|
recordCompatibilityDecision?.(
|
|
1046
1114
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.INCOMPATIBLE_VERSION)
|
|
1047
1115
|
);
|
|
1048
|
-
|
|
1116
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1049
1117
|
return false;
|
|
1050
1118
|
}
|
|
1051
1119
|
const progress = `${dbRet.info.update_seq}`;
|
|
@@ -1072,7 +1140,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1072
1140
|
recordCompatibilityDecision?.(
|
|
1073
1141
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.INCOMPATIBLE_VERSION)
|
|
1074
1142
|
);
|
|
1075
|
-
|
|
1143
|
+
this.log(
|
|
1076
1144
|
"The remote database has no compatibility with the running version. Please upgrade the plugin.",
|
|
1077
1145
|
LOG_LEVEL_NOTICE
|
|
1078
1146
|
);
|
|
@@ -1081,7 +1149,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1081
1149
|
recordCompatibilityDecision?.(
|
|
1082
1150
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.NODE_LOCKED)
|
|
1083
1151
|
);
|
|
1084
|
-
|
|
1152
|
+
this.log(
|
|
1085
1153
|
"The remote database has been rebuilt or corrupted since we have synchronized last time. Fetch rebuilt DB, explicit unlocking or chunk clean-up is required.",
|
|
1086
1154
|
LOG_LEVEL_NOTICE
|
|
1087
1155
|
);
|
|
@@ -1097,7 +1165,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1097
1165
|
recordCompatibilityDecision?.(
|
|
1098
1166
|
centralCompatibilityRejected(CENTRAL_COMPATIBILITY_REJECTION_REASONS.NODE_CLEANED)
|
|
1099
1167
|
);
|
|
1100
|
-
|
|
1168
|
+
this.log(
|
|
1101
1169
|
"The remote database has been cleaned up. Fetch rebuilt DB, explicit unlocking or chunk clean-up is required.",
|
|
1102
1170
|
LOG_LEVEL_NOTICE
|
|
1103
1171
|
);
|
|
@@ -1120,7 +1188,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1120
1188
|
tweakAssessment
|
|
1121
1189
|
)
|
|
1122
1190
|
);
|
|
1123
|
-
|
|
1191
|
+
this.log(this.translate("liveSyncReplicator.mismatchedTweakDetected"), LOG_LEVEL_NOTICE);
|
|
1124
1192
|
this.tweakSettingsMismatched = true;
|
|
1125
1193
|
this.preferredTweakValue = ensure[1];
|
|
1126
1194
|
return false;
|
|
@@ -1197,15 +1265,16 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1197
1265
|
async runContinuousReplication(setting, showResult, retrying) {
|
|
1198
1266
|
const next = await shareRunningResult("continuousReplication", async () => {
|
|
1199
1267
|
if (this.continuousStopRequested || this.controller) {
|
|
1200
|
-
|
|
1268
|
+
this.log(
|
|
1201
1269
|
this.translate("liveSyncReplicator.replicationInProgress"),
|
|
1202
1270
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO
|
|
1203
1271
|
);
|
|
1204
1272
|
return false;
|
|
1205
1273
|
}
|
|
1206
1274
|
this.publishPreparationPhase("catch-up");
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1275
|
+
const localOwner = this.env.services.database.localDatabase;
|
|
1276
|
+
const localDB = localOwner.localDatabase;
|
|
1277
|
+
this.log(this.translate("liveSyncReplicator.beforeLiveSync"));
|
|
1209
1278
|
const caughtUp = await this.env.services.replicator.runFiniteReplicationActivity(
|
|
1210
1279
|
() => this.openOneShotReplication(
|
|
1211
1280
|
setting,
|
|
@@ -1220,14 +1289,14 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1220
1289
|
);
|
|
1221
1290
|
if (caughtUp && !this.continuousStopRequested) {
|
|
1222
1291
|
this.publishPreparationPhase("continuous");
|
|
1223
|
-
|
|
1292
|
+
this.log(this.translate("liveSyncReplicator.liveSyncBegin"));
|
|
1224
1293
|
const ret = await this.checkReplicationConnectivity(setting, true, false, showResult);
|
|
1225
1294
|
if (ret === false || this.continuousStopRequested) {
|
|
1226
1295
|
if (ret !== false) {
|
|
1227
1296
|
await this.closeRemoteConnection(ret);
|
|
1228
1297
|
}
|
|
1229
1298
|
if (ret === false && !this.continuousStopRequested) {
|
|
1230
|
-
|
|
1299
|
+
this.log(
|
|
1231
1300
|
this.translate("liveSyncReplicator.couldNotConnectToServer"),
|
|
1232
1301
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO
|
|
1233
1302
|
);
|
|
@@ -1235,7 +1304,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1235
1304
|
return false;
|
|
1236
1305
|
}
|
|
1237
1306
|
if (showResult) {
|
|
1238
|
-
|
|
1307
|
+
this.log(this.translate("liveSyncReplicator.checkingLastSyncPoint"), LOG_LEVEL_NOTICE, "sync");
|
|
1239
1308
|
}
|
|
1240
1309
|
const { db, syncOption } = ret;
|
|
1241
1310
|
try {
|
|
@@ -1244,7 +1313,11 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1244
1313
|
}
|
|
1245
1314
|
this.syncStatus = "STARTED";
|
|
1246
1315
|
this.maxPullSeq = Number(`${ret.info.update_seq}`.split("-")[0]);
|
|
1247
|
-
this.maxPushSeq = Number(
|
|
1316
|
+
this.maxPushSeq = Number(
|
|
1317
|
+
`${(await this.readLocalDatabase(localOwner, (pouch) => pouch.info())).update_seq}`.split(
|
|
1318
|
+
"-"
|
|
1319
|
+
)[0]
|
|
1320
|
+
);
|
|
1248
1321
|
if (this.continuousStopRequested) {
|
|
1249
1322
|
return false;
|
|
1250
1323
|
}
|
|
@@ -1293,13 +1366,13 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1293
1366
|
tempSetting.batch_size = Math.ceil(tempSetting.batch_size / 2) + 2;
|
|
1294
1367
|
tempSetting.batches_limit = Math.ceil(tempSetting.batches_limit / 2) + 2;
|
|
1295
1368
|
if (tempSetting.batch_size <= 5 && tempSetting.batches_limit <= 5) {
|
|
1296
|
-
|
|
1369
|
+
this.log(
|
|
1297
1370
|
this.translate("liveSyncReplicator.cantReplicateLowerValue"),
|
|
1298
1371
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO
|
|
1299
1372
|
);
|
|
1300
1373
|
return false;
|
|
1301
1374
|
} else {
|
|
1302
|
-
|
|
1375
|
+
this.log(
|
|
1303
1376
|
this.translate("liveSyncReplicator.retryLowerBatchSize", {
|
|
1304
1377
|
batch_size: tempSetting.batch_size.toString(),
|
|
1305
1378
|
batches_limit: tempSetting.batches_limit.toString()
|
|
@@ -1332,7 +1405,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1332
1405
|
return stopped;
|
|
1333
1406
|
}
|
|
1334
1407
|
this.syncStatus = "CLOSED";
|
|
1335
|
-
|
|
1408
|
+
this.log(this.translate("liveSyncReplicator.replicationClosed"));
|
|
1336
1409
|
this.updateInfo();
|
|
1337
1410
|
return stopped;
|
|
1338
1411
|
}
|
|
@@ -1344,10 +1417,10 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1344
1417
|
}
|
|
1345
1418
|
try {
|
|
1346
1419
|
await con.db.destroy();
|
|
1347
|
-
|
|
1420
|
+
this.log(this.translate("liveSyncReplicator.remoteDbDestroyed"), LOG_LEVEL_NOTICE);
|
|
1348
1421
|
} catch (ex) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1422
|
+
this.log(this.translate("liveSyncReplicator.remoteDbDestroyError"), LOG_LEVEL_NOTICE);
|
|
1423
|
+
this.log(ex, LOG_LEVEL_NOTICE);
|
|
1351
1424
|
throw ex;
|
|
1352
1425
|
} finally {
|
|
1353
1426
|
await this.closeRemoteConnection(con);
|
|
@@ -1365,18 +1438,18 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1365
1438
|
if (!await this.ensurePBKDF2Salt(setting, true, false)) {
|
|
1366
1439
|
throw new Error("Could not ensure PBKDF2 salt (Security Seed)");
|
|
1367
1440
|
}
|
|
1368
|
-
|
|
1441
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCreatedOrConnected"), LOG_LEVEL_NOTICE);
|
|
1369
1442
|
}
|
|
1370
1443
|
async markRemoteLocked(setting, locked, lockByClean) {
|
|
1371
1444
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1372
1445
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1373
1446
|
if (typeof dbRet === "string") {
|
|
1374
|
-
|
|
1447
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1375
1448
|
throw new Error(dbRet);
|
|
1376
1449
|
}
|
|
1377
1450
|
await this.withRemoteConnection(dbRet, async (db) => {
|
|
1378
1451
|
if (!await checkRemoteVersion(db, this.migrate.bind(this), VER)) {
|
|
1379
|
-
|
|
1452
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1380
1453
|
throw new Error("The remote database version is not compatible");
|
|
1381
1454
|
}
|
|
1382
1455
|
const defInitPoint = {
|
|
@@ -1399,9 +1472,9 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1399
1472
|
remoteMilestone.locked = locked;
|
|
1400
1473
|
remoteMilestone.cleaned = remoteMilestone.cleaned || lockByClean;
|
|
1401
1474
|
if (locked) {
|
|
1402
|
-
|
|
1475
|
+
this.log(this.translate("liveSyncReplicator.lockRemoteDb"), LOG_LEVEL_NOTICE);
|
|
1403
1476
|
} else {
|
|
1404
|
-
|
|
1477
|
+
this.log(this.translate("liveSyncReplicator.unlockRemoteDb"), LOG_LEVEL_NOTICE);
|
|
1405
1478
|
}
|
|
1406
1479
|
const result = await db.put(remoteMilestone);
|
|
1407
1480
|
if (!result.ok) {
|
|
@@ -1413,12 +1486,12 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1413
1486
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1414
1487
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1415
1488
|
if (typeof dbRet === "string") {
|
|
1416
|
-
|
|
1489
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1417
1490
|
throw new Error(dbRet);
|
|
1418
1491
|
}
|
|
1419
1492
|
await this.withRemoteConnection(dbRet, async (db) => {
|
|
1420
1493
|
if (!await checkRemoteVersion(db, this.migrate.bind(this), VER)) {
|
|
1421
|
-
|
|
1494
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1422
1495
|
throw new Error("The remote database version is not compatible");
|
|
1423
1496
|
}
|
|
1424
1497
|
const defInitPoint = {
|
|
@@ -1437,12 +1510,12 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1437
1510
|
};
|
|
1438
1511
|
remoteMilestone.node_chunk_info = { ...defInitPoint.node_chunk_info, ...remoteMilestone.node_chunk_info };
|
|
1439
1512
|
remoteMilestone.accepted_nodes = Array.from(/* @__PURE__ */ new Set([...remoteMilestone.accepted_nodes, this.nodeid]));
|
|
1440
|
-
|
|
1513
|
+
this.log(this.translate("liveSyncReplicator.markDeviceResolved"), LOG_LEVEL_NOTICE);
|
|
1441
1514
|
const result = await db.put(remoteMilestone);
|
|
1442
1515
|
if (result.ok) {
|
|
1443
|
-
|
|
1516
|
+
this.log(this.translate("liveSyncReplicator.remoteDbMarkedResolved"), LOG_LEVEL_VERBOSE);
|
|
1444
1517
|
} else {
|
|
1445
|
-
|
|
1518
|
+
this.log(this.translate("liveSyncReplicator.couldNotMarkResolveRemoteDb"), LOG_LEVEL_NOTICE);
|
|
1446
1519
|
throw new Error("Could not mark the remote database as resolved");
|
|
1447
1520
|
}
|
|
1448
1521
|
});
|
|
@@ -1548,25 +1621,28 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1548
1621
|
async fetchRemoteChunks(missingChunks, showResult, setting = this.currentSettings) {
|
|
1549
1622
|
const ret = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), false, true);
|
|
1550
1623
|
if (typeof ret === "string") {
|
|
1551
|
-
|
|
1624
|
+
this.log(
|
|
1552
1625
|
`${this.translate("liveSyncReplicator.couldNotConnectToServer")} ${ret} `,
|
|
1553
1626
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
1554
1627
|
"fetch"
|
|
1555
1628
|
);
|
|
1556
|
-
|
|
1629
|
+
throw new RemoteRequestError(ret);
|
|
1557
1630
|
}
|
|
1558
1631
|
return await this.withRemoteConnection(ret, async (db) => {
|
|
1559
|
-
|
|
1632
|
+
const compatible = await checkRemoteVersion(db, this.migrate.bind(this), VER);
|
|
1633
|
+
if (!compatible) {
|
|
1634
|
+
throw new RemoteRequestError("Remote database version is incompatible");
|
|
1635
|
+
}
|
|
1560
1636
|
const remoteChunks = await db.allDocs({ keys: missingChunks, include_docs: true });
|
|
1561
1637
|
const errorRows = remoteChunks.rows.filter((e) => "error" in e);
|
|
1562
1638
|
if (errorRows.length > 0) {
|
|
1563
|
-
|
|
1639
|
+
this.log(
|
|
1564
1640
|
`Some requested chunks were not found in the remote database.`,
|
|
1565
1641
|
showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
|
|
1566
1642
|
"fetch"
|
|
1567
1643
|
);
|
|
1568
|
-
|
|
1569
|
-
|
|
1644
|
+
this.log(`Requested chunks: ${missingChunks.join(",")}`, LOG_LEVEL_VERBOSE);
|
|
1645
|
+
this.log(
|
|
1570
1646
|
`Error chunks: ${errorRows.map((e) => e.key).join(",")}`,
|
|
1571
1647
|
LOG_LEVEL_VERBOSE
|
|
1572
1648
|
);
|
|
@@ -1577,7 +1653,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1577
1653
|
async tryConnectRemote(setting, showResult = true) {
|
|
1578
1654
|
const db = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1579
1655
|
if (typeof db === "string") {
|
|
1580
|
-
|
|
1656
|
+
this.log(
|
|
1581
1657
|
this.translate("liveSyncReplicator.couldNotConnectTo", {
|
|
1582
1658
|
uri: setting.couchDB_URI,
|
|
1583
1659
|
name: setting.couchDB_DBNAME,
|
|
@@ -1588,7 +1664,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1588
1664
|
return false;
|
|
1589
1665
|
}
|
|
1590
1666
|
return await this.withRemoteConnection(db, async () => {
|
|
1591
|
-
|
|
1667
|
+
this.log(`Connected to ${db.info.db_name} successfully`, LOG_LEVEL_NOTICE);
|
|
1592
1668
|
return true;
|
|
1593
1669
|
});
|
|
1594
1670
|
}
|
|
@@ -1596,21 +1672,21 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1596
1672
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1597
1673
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1598
1674
|
if (typeof dbRet === "string") {
|
|
1599
|
-
|
|
1675
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1600
1676
|
return;
|
|
1601
1677
|
}
|
|
1602
1678
|
await this.withRemoteConnection(dbRet, async (db) => {
|
|
1603
1679
|
if (!await checkRemoteVersion(db, this.migrate.bind(this), VER)) {
|
|
1604
|
-
|
|
1680
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1605
1681
|
return;
|
|
1606
1682
|
}
|
|
1607
1683
|
try {
|
|
1608
1684
|
const remoteMilestone = await db.get(MILESTONE_DOCID);
|
|
1609
1685
|
remoteMilestone.tweak_values = {};
|
|
1610
1686
|
await db.put(remoteMilestone);
|
|
1611
|
-
|
|
1687
|
+
this.log(`tweak values on the remote database have been cleared`, LOG_LEVEL_VERBOSE);
|
|
1612
1688
|
} catch (ex) {
|
|
1613
|
-
|
|
1689
|
+
this.log(`Could not retrieve remote milestone`, LOG_LEVEL_NOTICE);
|
|
1614
1690
|
throw ex;
|
|
1615
1691
|
}
|
|
1616
1692
|
});
|
|
@@ -1619,21 +1695,21 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1619
1695
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1620
1696
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1621
1697
|
if (typeof dbRet === "string") {
|
|
1622
|
-
|
|
1698
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1623
1699
|
throw new Error(dbRet);
|
|
1624
1700
|
}
|
|
1625
1701
|
await this.withRemoteConnection(dbRet, async (db) => {
|
|
1626
1702
|
if (!await checkRemoteVersion(db, this.migrate.bind(this), VER)) {
|
|
1627
|
-
|
|
1703
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1628
1704
|
throw new Error("The remote database version is not compatible");
|
|
1629
1705
|
}
|
|
1630
1706
|
try {
|
|
1631
1707
|
const remoteMilestone = await db.get(MILESTONE_DOCID);
|
|
1632
1708
|
remoteMilestone.tweak_values[DEVICE_ID_PREFERRED] = getEffectiveTweakValues(setting);
|
|
1633
1709
|
await db.put(remoteMilestone);
|
|
1634
|
-
|
|
1710
|
+
this.log(`Preferred tweak values has been registered`, LOG_LEVEL_VERBOSE);
|
|
1635
1711
|
} catch (ex) {
|
|
1636
|
-
|
|
1712
|
+
this.log(`Could not retrieve remote milestone`, LOG_LEVEL_NOTICE);
|
|
1637
1713
|
throw ex;
|
|
1638
1714
|
}
|
|
1639
1715
|
});
|
|
@@ -1644,15 +1720,15 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1644
1720
|
try {
|
|
1645
1721
|
dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1646
1722
|
} catch (ex) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1723
|
+
this.log(`Could not connect to the remote database`, LOG_LEVEL_NOTICE);
|
|
1724
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
1649
1725
|
return {
|
|
1650
1726
|
status: RemotePreferredTweakStatuses.UNAVAILABLE,
|
|
1651
1727
|
error: ex
|
|
1652
1728
|
};
|
|
1653
1729
|
}
|
|
1654
1730
|
if (typeof dbRet === "string") {
|
|
1655
|
-
|
|
1731
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1656
1732
|
return {
|
|
1657
1733
|
status: RemotePreferredTweakStatuses.UNAVAILABLE,
|
|
1658
1734
|
error: new Error(dbRet)
|
|
@@ -1662,15 +1738,15 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1662
1738
|
try {
|
|
1663
1739
|
if (!await checkRemoteVersion(db, this.migrate.bind(this), VER)) {
|
|
1664
1740
|
const error = new Error("The remote database version is not compatible");
|
|
1665
|
-
|
|
1741
|
+
this.log(this.translate("liveSyncReplicator.remoteDbCorrupted"), LOG_LEVEL_NOTICE);
|
|
1666
1742
|
return {
|
|
1667
1743
|
status: RemotePreferredTweakStatuses.UNAVAILABLE,
|
|
1668
1744
|
error
|
|
1669
1745
|
};
|
|
1670
1746
|
}
|
|
1671
1747
|
} catch (ex) {
|
|
1672
|
-
|
|
1673
|
-
|
|
1748
|
+
this.log(`Could not check the remote database version`, LOG_LEVEL_NOTICE);
|
|
1749
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
1674
1750
|
return {
|
|
1675
1751
|
status: RemotePreferredTweakStatuses.UNAVAILABLE,
|
|
1676
1752
|
error: ex
|
|
@@ -1702,8 +1778,8 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1702
1778
|
reason: RemotePreferredTweakNotConfiguredReasons.MILESTONE_MISSING
|
|
1703
1779
|
};
|
|
1704
1780
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1781
|
+
this.log(`Could not retrieve remote milestone`, LOG_LEVEL_NOTICE);
|
|
1782
|
+
this.log(ex, LOG_LEVEL_VERBOSE);
|
|
1707
1783
|
return {
|
|
1708
1784
|
status: RemotePreferredTweakStatuses.UNAVAILABLE,
|
|
1709
1785
|
error: ex
|
|
@@ -1715,7 +1791,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1715
1791
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1716
1792
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1717
1793
|
if (typeof dbRet === "string") {
|
|
1718
|
-
|
|
1794
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1719
1795
|
return false;
|
|
1720
1796
|
}
|
|
1721
1797
|
return await this.withRemoteConnection(dbRet, async (db) => (await db.compact({ interval: 1e3 })).ok);
|
|
@@ -1724,7 +1800,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1724
1800
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1725
1801
|
if (typeof dbRet === "string") {
|
|
1726
1802
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1727
|
-
|
|
1803
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1728
1804
|
return false;
|
|
1729
1805
|
}
|
|
1730
1806
|
return await this.withRemoteConnection(dbRet, async (db) => {
|
|
@@ -1739,7 +1815,7 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1739
1815
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1740
1816
|
if (typeof dbRet === "string") {
|
|
1741
1817
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1742
|
-
|
|
1818
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1743
1819
|
return false;
|
|
1744
1820
|
}
|
|
1745
1821
|
return await this.withRemoteConnection(dbRet, countCompromisedChunks);
|
|
@@ -1819,13 +1895,13 @@ ${sendingDocs}/(${sentDocsCount} done)`,
|
|
|
1819
1895
|
const dbRet = await this.connectRemoteCouchDBWithSetting(setting, this.isMobile(), true);
|
|
1820
1896
|
if (typeof dbRet === "string") {
|
|
1821
1897
|
const uri = setting.couchDB_URI.replace(/\/+$/, "") + (setting.couchDB_DBNAME == "" ? "" : "/" + setting.couchDB_DBNAME);
|
|
1822
|
-
|
|
1898
|
+
this.log(this.translate("liveSyncReplicator.couldNotConnectToURI", { uri, dbRet }), LOG_LEVEL_NOTICE);
|
|
1823
1899
|
return false;
|
|
1824
1900
|
}
|
|
1825
1901
|
return await this.withRemoteConnection(dbRet, async (db) => {
|
|
1826
1902
|
const milestoneDoc = await db.get(MILESTONE_DOCID);
|
|
1827
1903
|
if (!milestoneDoc) {
|
|
1828
|
-
|
|
1904
|
+
this.log("Could not retrieve remote milestone", LOG_LEVEL_NOTICE);
|
|
1829
1905
|
return false;
|
|
1830
1906
|
}
|
|
1831
1907
|
const nodeInfo = milestoneDoc.node_info;
|