@powersync/service-module-mongodb-storage 0.12.13 → 0.12.14
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/CHANGELOG.md +15 -0
- package/dist/storage/MongoBucketStorage.js +1 -0
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +3 -0
- package/dist/storage/implementation/MongoBucketBatch.js +29 -2
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +2 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.js +2 -2
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +6 -1
- package/dist/storage/implementation/PersistedBatch.js +7 -0
- package/dist/storage/implementation/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +1 -0
- package/package.json +6 -6
- package/src/storage/MongoBucketStorage.ts +1 -0
- package/src/storage/implementation/MongoBucketBatch.ts +37 -2
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +2 -0
- package/src/storage/implementation/MongoSyncBucketStorage.ts +2 -3
- package/src/storage/implementation/PersistedBatch.ts +9 -0
- package/src/storage/implementation/models.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -82,6 +82,7 @@ export class MongoBucketBatch
|
|
|
82
82
|
private batch: OperationBatch | null = null;
|
|
83
83
|
private write_checkpoint_batch: storage.CustomWriteCheckpointOptions[] = [];
|
|
84
84
|
private markRecordUnavailable: BucketStorageMarkRecordUnavailable | undefined;
|
|
85
|
+
private clearedError = false;
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* Last LSN received associated with a checkpoint.
|
|
@@ -146,6 +147,10 @@ export class MongoBucketBatch
|
|
|
146
147
|
return this.last_checkpoint_lsn;
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
get noCheckpointBeforeLsn() {
|
|
151
|
+
return this.no_checkpoint_before_lsn;
|
|
152
|
+
}
|
|
153
|
+
|
|
149
154
|
async flush(options?: storage.BatchBucketFlushOptions): Promise<storage.FlushedResult | null> {
|
|
150
155
|
let result: storage.FlushedResult | null = null;
|
|
151
156
|
// One flush may be split over multiple transactions.
|
|
@@ -243,6 +248,8 @@ export class MongoBucketBatch
|
|
|
243
248
|
let resumeBatch: OperationBatch | null = null;
|
|
244
249
|
let transactionSize = 0;
|
|
245
250
|
|
|
251
|
+
let didFlush = false;
|
|
252
|
+
|
|
246
253
|
// Now batch according to the sizes
|
|
247
254
|
// This is a single batch if storeCurrentData == false
|
|
248
255
|
for await (let b of batch.batched(sizes)) {
|
|
@@ -292,7 +299,8 @@ export class MongoBucketBatch
|
|
|
292
299
|
if (persistedBatch!.shouldFlushTransaction()) {
|
|
293
300
|
// Transaction is getting big.
|
|
294
301
|
// Flush, and resume in a new transaction.
|
|
295
|
-
await persistedBatch!.flush(this.db, this.session, options);
|
|
302
|
+
const { flushedAny } = await persistedBatch!.flush(this.db, this.session, options);
|
|
303
|
+
didFlush ||= flushedAny;
|
|
296
304
|
persistedBatch = null;
|
|
297
305
|
// Computing our current progress is a little tricky here, since
|
|
298
306
|
// we're stopping in the middle of a batch.
|
|
@@ -303,10 +311,15 @@ export class MongoBucketBatch
|
|
|
303
311
|
|
|
304
312
|
if (persistedBatch) {
|
|
305
313
|
transactionSize = persistedBatch.currentSize;
|
|
306
|
-
await persistedBatch.flush(this.db, this.session, options);
|
|
314
|
+
const { flushedAny } = await persistedBatch.flush(this.db, this.session, options);
|
|
315
|
+
didFlush ||= flushedAny;
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
318
|
|
|
319
|
+
if (didFlush) {
|
|
320
|
+
await this.clearError();
|
|
321
|
+
}
|
|
322
|
+
|
|
310
323
|
return resumeBatch?.hasData() ? resumeBatch : null;
|
|
311
324
|
}
|
|
312
325
|
|
|
@@ -714,6 +727,7 @@ export class MongoBucketBatch
|
|
|
714
727
|
last_keepalive_ts: now,
|
|
715
728
|
snapshot_done: true,
|
|
716
729
|
last_fatal_error: null,
|
|
730
|
+
last_fatal_error_ts: null,
|
|
717
731
|
keepalive_op: null
|
|
718
732
|
};
|
|
719
733
|
|
|
@@ -848,6 +862,7 @@ export class MongoBucketBatch
|
|
|
848
862
|
last_checkpoint_lsn: lsn,
|
|
849
863
|
snapshot_done: true,
|
|
850
864
|
last_fatal_error: null,
|
|
865
|
+
last_fatal_error_ts: null,
|
|
851
866
|
last_keepalive_ts: new Date()
|
|
852
867
|
},
|
|
853
868
|
$unset: { snapshot_lsn: 1 }
|
|
@@ -1075,6 +1090,26 @@ export class MongoBucketBatch
|
|
|
1075
1090
|
});
|
|
1076
1091
|
}
|
|
1077
1092
|
|
|
1093
|
+
protected async clearError(): Promise<void> {
|
|
1094
|
+
// No need to clear an error more than once per batch, since an error would always result in restarting the batch.
|
|
1095
|
+
if (this.clearedError) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
await this.db.sync_rules.updateOne(
|
|
1100
|
+
{
|
|
1101
|
+
_id: this.group_id
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
$set: {
|
|
1105
|
+
last_fatal_error: null,
|
|
1106
|
+
last_fatal_error_ts: null
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1110
|
+
this.clearedError = true;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1078
1113
|
/**
|
|
1079
1114
|
* Gets relevant {@link SqlEventDescriptor}s for the given {@link SourceTable}
|
|
1080
1115
|
*/
|
|
@@ -13,6 +13,7 @@ export class MongoPersistedSyncRulesContent implements storage.PersistedSyncRule
|
|
|
13
13
|
public readonly sync_rules_content: string;
|
|
14
14
|
public readonly last_checkpoint_lsn: string | null;
|
|
15
15
|
public readonly last_fatal_error: string | null;
|
|
16
|
+
public readonly last_fatal_error_ts: Date | null;
|
|
16
17
|
public readonly last_keepalive_ts: Date | null;
|
|
17
18
|
public readonly last_checkpoint_ts: Date | null;
|
|
18
19
|
public readonly active: boolean;
|
|
@@ -29,6 +30,7 @@ export class MongoPersistedSyncRulesContent implements storage.PersistedSyncRule
|
|
|
29
30
|
// Handle legacy values
|
|
30
31
|
this.slot_name = doc.slot_name ?? `powersync_${this.id}`;
|
|
31
32
|
this.last_fatal_error = doc.last_fatal_error;
|
|
33
|
+
this.last_fatal_error_ts = doc.last_fatal_error_ts;
|
|
32
34
|
this.last_checkpoint_ts = doc.last_checkpoint_ts;
|
|
33
35
|
this.last_keepalive_ts = doc.last_keepalive_ts;
|
|
34
36
|
this.active = doc.state == 'ACTIVE';
|
|
@@ -39,7 +39,6 @@ import { MongoParameterCompactor } from './MongoParameterCompactor.js';
|
|
|
39
39
|
import { MongoWriteCheckpointAPI } from './MongoWriteCheckpointAPI.js';
|
|
40
40
|
import { idPrefixFilter, mapOpEntry, readSingleBatch, setSessionSnapshotTime } from '../../utils/util.js';
|
|
41
41
|
|
|
42
|
-
|
|
43
42
|
export interface MongoSyncBucketStorageOptions {
|
|
44
43
|
checksumOptions?: MongoChecksumOptions;
|
|
45
44
|
}
|
|
@@ -648,11 +647,11 @@ export class MongoSyncBucketStorage
|
|
|
648
647
|
},
|
|
649
648
|
{
|
|
650
649
|
$set: {
|
|
651
|
-
last_fatal_error: message
|
|
650
|
+
last_fatal_error: message,
|
|
651
|
+
last_fatal_error_ts: new Date()
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
);
|
|
655
|
-
await this.db.notifyCheckpoint();
|
|
656
655
|
}
|
|
657
656
|
|
|
658
657
|
async compact(options?: storage.CompactOptions) {
|
|
@@ -351,12 +351,21 @@ export class PersistedBatch {
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
const stats = {
|
|
355
|
+
bucketDataCount: this.bucketData.length,
|
|
356
|
+
parameterDataCount: this.bucketParameters.length,
|
|
357
|
+
currentDataCount: this.currentData.length,
|
|
358
|
+
flushedAny: flushedSomething
|
|
359
|
+
};
|
|
360
|
+
|
|
354
361
|
this.bucketData = [];
|
|
355
362
|
this.bucketParameters = [];
|
|
356
363
|
this.currentData = [];
|
|
357
364
|
this.bucketStates.clear();
|
|
358
365
|
this.currentSize = 0;
|
|
359
366
|
this.debugLastOpId = null;
|
|
367
|
+
|
|
368
|
+
return stats;
|
|
360
369
|
}
|
|
361
370
|
|
|
362
371
|
private getBucketStateUpdates(): mongo.AnyBulkWriteOperation<BucketStateDocument>[] {
|