@powersync/service-module-mongodb-storage 0.25.0 → 0.26.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/CHANGELOG.md +27 -0
- package/dist/storage/MongoBucketStorage.d.ts +6 -0
- package/dist/storage/MongoBucketStorage.js +8 -29
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +24 -18
- package/dist/storage/implementation/MongoBucketBatch.js +25 -127
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +1 -0
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.js +1 -0
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +9 -2
- package/dist/storage/implementation/MongoSyncRulesLock.js +17 -4
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/OperationBatch.d.ts +10 -3
- package/dist/storage/implementation/OperationBatch.js +22 -13
- package/dist/storage/implementation/OperationBatch.js.map +1 -1
- package/dist/storage/implementation/ReplicationBatchLimits.d.ts +24 -0
- package/dist/storage/implementation/ReplicationBatchLimits.js +25 -0
- package/dist/storage/implementation/ReplicationBatchLimits.js.map +1 -0
- package/dist/storage/implementation/common/BatchOperationBuffer.d.ts +17 -1
- package/dist/storage/implementation/common/BatchOperationBuffer.js +22 -24
- package/dist/storage/implementation/common/BatchOperationBuffer.js.map +1 -1
- package/dist/storage/implementation/common/PersistedBatch.d.ts +2 -0
- package/dist/storage/implementation/common/PreparedPublication.d.ts +17 -9
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +18 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +99 -14
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/PersistedBatchV1.js +1 -1
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -1
- package/dist/storage/implementation/v3/CompactionLease.d.ts +17 -4
- package/dist/storage/implementation/v3/CompactionLease.js +76 -13
- package/dist/storage/implementation/v3/CompactionLease.js.map +1 -1
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +39 -3
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +374 -95
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +5 -3
- package/dist/storage/implementation/v3/MongoCompactorV3.js +169 -82
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +15 -6
- package/dist/storage/implementation/v3/PersistedBatchV3.js +29 -16
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/ReplicationPipelineV3.d.ts +84 -0
- package/dist/storage/implementation/v3/ReplicationPipelineV3.js +187 -0
- package/dist/storage/implementation/v3/ReplicationPipelineV3.js.map +1 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +4 -4
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +4 -4
- package/dist/storage/implementation/v3/chunking.js +7 -3
- package/dist/storage/implementation/v3/chunking.js.map +1 -1
- package/dist/types/types.d.ts +5 -0
- package/dist/types/types.js +4 -0
- package/dist/types/types.js.map +1 -1
- package/dist/utils/collection-sizes.d.ts +9 -0
- package/dist/utils/collection-sizes.js +95 -0
- package/dist/utils/collection-sizes.js.map +1 -0
- package/dist/utils/test-utils.js +1 -0
- package/dist/utils/test-utils.js.map +1 -1
- package/package.json +7 -7
- package/src/storage/MongoBucketStorage.ts +19 -30
- package/src/storage/implementation/MongoBucketBatch.ts +50 -139
- package/src/storage/implementation/MongoStorageProvider.ts +1 -0
- package/src/storage/implementation/MongoSyncBucketStorage.ts +1 -0
- package/src/storage/implementation/MongoSyncRulesLock.ts +18 -4
- package/src/storage/implementation/OperationBatch.ts +23 -15
- package/src/storage/implementation/ReplicationBatchLimits.ts +45 -0
- package/src/storage/implementation/common/BatchOperationBuffer.ts +21 -26
- package/src/storage/implementation/common/PersistedBatch.ts +2 -0
- package/src/storage/implementation/common/PreparedPublication.ts +17 -9
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +135 -17
- package/src/storage/implementation/v1/PersistedBatchV1.ts +2 -1
- package/src/storage/implementation/v3/CompactionLease.ts +91 -15
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +455 -107
- package/src/storage/implementation/v3/MongoCompactorV3.ts +217 -127
- package/src/storage/implementation/v3/PersistedBatchV3.ts +30 -17
- package/src/storage/implementation/v3/ReplicationPipelineV3.ts +220 -0
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +4 -4
- package/src/storage/implementation/v3/chunking.ts +8 -3
- package/src/types/types.ts +7 -0
- package/src/utils/collection-sizes.ts +114 -0
- package/src/utils/test-utils.ts +1 -0
- package/test/src/concurrent_writers.test.ts +22 -15
- package/test/src/helpers/PublicationCommandMonitor.ts +18 -3
- package/test/src/operation_batch.test.ts +207 -0
- package/test/src/prepared_publication.test.ts +210 -7
- package/test/src/replication_batch_config.test.ts +117 -0
- package/test/src/replication_pipeline.test.ts +738 -0
- package/test/src/replication_pipeline_benchmark.test.ts +133 -0
- package/test/src/replication_preparation.test.ts +4 -2
- package/test/src/replication_publication_baseline.test.ts +26 -16
- package/test/src/replication_publication_batching.test.ts +6 -2
- package/test/src/replication_uploads.test.ts +28 -3
- package/test/src/storage.test.ts +24 -5
- package/test/src/storage_compacting.test.ts +269 -47
- package/test/src/storage_metrics.test.ts +88 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { setTimeout } from 'node:timers/promises';
|
|
2
3
|
import { CompactionLeaseLostError } from '../MongoCompactor.js';
|
|
3
4
|
const LEASE_RENEW_INTERVAL_MS = 60 * 1000;
|
|
5
|
+
/**
|
|
6
|
+
* We wrap bulk bucket_state updates in a transaction.
|
|
7
|
+
*
|
|
8
|
+
* This is not needed for consistency purposes. Instead, we use this to deprioritize these updates
|
|
9
|
+
* against replication bucket_state updates. If we update concurrently with replication with individual
|
|
10
|
+
* operations, each operation can race the replication transaction individually, and any operation
|
|
11
|
+
* winning can abort the replication transaction. While if we combine it into a transaction, it gives
|
|
12
|
+
* the replication transaction a fair chance to compete.
|
|
13
|
+
*/
|
|
14
|
+
export function withBucketStateTransaction(collection, write) {
|
|
15
|
+
return collection.db.client.withSession((session) => {
|
|
16
|
+
let retry = false;
|
|
17
|
+
return session.withTransaction(async () => {
|
|
18
|
+
// After a write conflict, give replication time to finish before retrying.
|
|
19
|
+
// The first MongoDB command opens the transaction on the server.
|
|
20
|
+
if (retry) {
|
|
21
|
+
await setTimeout(Math.random() * 150);
|
|
22
|
+
}
|
|
23
|
+
retry = true;
|
|
24
|
+
return write(session);
|
|
25
|
+
}, { readPreference: 'primary', readConcern: { level: 'snapshot' }, writeConcern: { w: 'majority' } });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
4
28
|
/**
|
|
5
29
|
* Filters for buckets that have no lease or an expired lease.
|
|
6
30
|
*/
|
|
@@ -38,6 +62,7 @@ export class CompactionLease {
|
|
|
38
62
|
this.durationMs = durationMs;
|
|
39
63
|
this.startedAt = new Date(state.compact_lease.expires_at.getTime() - durationMs);
|
|
40
64
|
this.lastOp = state.last_op;
|
|
65
|
+
this.startRenewal();
|
|
41
66
|
}
|
|
42
67
|
static async claim(collection, filter, sort, durationMs) {
|
|
43
68
|
const id = new mongo.ObjectId();
|
|
@@ -77,11 +102,58 @@ export class CompactionLease {
|
|
|
77
102
|
throw this.renewalError;
|
|
78
103
|
}
|
|
79
104
|
}
|
|
80
|
-
async
|
|
81
|
-
await this.
|
|
105
|
+
async finalize(fields) {
|
|
106
|
+
await this.throwIfLost();
|
|
107
|
+
this.finalizing = true;
|
|
108
|
+
const result = await this.collection.updateOne(this.filter, [{ $set: fields }, { $unset: 'compact_lease' }]);
|
|
109
|
+
if (result.matchedCount != 1) {
|
|
110
|
+
throw new CompactionLeaseLostError(`Lost compaction lease for bucket ${this.state._id.b}`);
|
|
111
|
+
}
|
|
112
|
+
this.finished = true;
|
|
82
113
|
}
|
|
83
|
-
|
|
84
|
-
|
|
114
|
+
/** Each update publishes and releases only the lease that produced it. */
|
|
115
|
+
static async finalizeBatch(collection, updates, rescheduleFailed) {
|
|
116
|
+
if (updates.length === 0) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
for (const { lease } of updates) {
|
|
120
|
+
lease.finalizing = true;
|
|
121
|
+
}
|
|
122
|
+
let pending = updates;
|
|
123
|
+
while (pending.length > 0) {
|
|
124
|
+
const operations = pending.map(({ lease, fields }) => ({
|
|
125
|
+
updateOne: { filter: lease.filter, update: [{ $set: fields }, { $unset: 'compact_lease' }] }
|
|
126
|
+
}));
|
|
127
|
+
try {
|
|
128
|
+
const result = await withBucketStateTransaction(collection, (session) => collection.bulkWrite(operations, { ordered: false, session }));
|
|
129
|
+
// A miss means another worker owns the bucket. Any remaining leases
|
|
130
|
+
// still owned by this run are released by disposal if publication throws.
|
|
131
|
+
for (const { lease } of pending) {
|
|
132
|
+
lease.finished = true;
|
|
133
|
+
}
|
|
134
|
+
return result.matchedCount;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// A rejected update aborts the transaction. Retry the siblings only
|
|
138
|
+
// when the server identified the invalid updates and the abort is known.
|
|
139
|
+
if (!(error instanceof mongo.MongoBulkWriteError) ||
|
|
140
|
+
error.hasErrorLabel('TransientTransactionError') ||
|
|
141
|
+
!Array.isArray(error.writeErrors) ||
|
|
142
|
+
error.writeErrors.length === 0 ||
|
|
143
|
+
error.result.getWriteConcernError() != null) {
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
const failed = new Set();
|
|
147
|
+
for (const writeError of error.writeErrors) {
|
|
148
|
+
const { lease } = pending[writeError.index];
|
|
149
|
+
failed.add(writeError.index);
|
|
150
|
+
await lease[Symbol.asyncDispose]();
|
|
151
|
+
await rescheduleFailed(lease, writeError);
|
|
152
|
+
}
|
|
153
|
+
pending = pending.filter((_, index) => !failed.has(index));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
85
157
|
}
|
|
86
158
|
async [Symbol.asyncDispose]() {
|
|
87
159
|
if (this.timer != null) {
|
|
@@ -118,14 +190,5 @@ export class CompactionLease {
|
|
|
118
190
|
this.renewalError = undefined;
|
|
119
191
|
}
|
|
120
192
|
}
|
|
121
|
-
async finish(update) {
|
|
122
|
-
await this.throwIfLost();
|
|
123
|
-
this.finalizing = true;
|
|
124
|
-
const result = await this.collection.updateOne(this.filter, update);
|
|
125
|
-
if (result.matchedCount != 1) {
|
|
126
|
-
throw new CompactionLeaseLostError(`Lost compaction lease for bucket ${this.state._id.b}`);
|
|
127
|
-
}
|
|
128
|
-
this.finished = true;
|
|
129
|
-
}
|
|
130
193
|
}
|
|
131
194
|
//# sourceMappingURL=CompactionLease.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompactionLease.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/CompactionLease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,iEAAiE;IACjE,yCAAyC;IACzC,KAAK,EAAE;QACL,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,2BAA2B,EAAE,OAAO,CAAC,EAAE,CAAC;KAC3G;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IAWP;IACR;IACA;IACQ;IAbV,SAAS,CAAO;IAChB,MAAM,CAAe;IAEtB,KAAK,CAA6B;IAClC,eAAe,GAAG,KAAK,CAAC;IACxB,YAAY,CAAU;IACtB,UAAU,GAAG,KAAK,CAAC;IACnB,QAAQ,GAAG,KAAK,CAAC;IAEzB,YACmB,UAAmD,EAC3D,KAA4B,EAC5B,EAAkB,EACV,UAAkB;QAHlB,eAAU,GAAV,UAAU,CAAyC;QAC3D,UAAK,GAAL,KAAK,CAAuB;QAC5B,OAAE,GAAF,EAAE,CAAgB;QACV,eAAU,GAAV,UAAU,CAAQ;QAEnC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,aAAc,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CompactionLease.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/CompactionLease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,UAAmD,EACnD,KAAmD;IAEnD,OAAO,UAAU,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE;QAClD,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,OAAO,OAAO,CAAC,eAAe,CAC5B,KAAK,IAAI,EAAE;YACT,2EAA2E;YAC3E,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C1D;gBACE,IAAI,EAAE;oBACJ,0BAA0B,EAAE;wBAC1B,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;qBAC/E;iBACF;aACF;SACF,CAAC,CAAC;QACH,mEAAmE;QACnE,IAAI,MAAM,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACjD,MAAM,IAAI,wBAAwB,CAAC,oCAAoC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7F,CAAC;QACD,uEAAuE;QACvE,uEAAuE;QACvE,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,YAAY,wBAAwB,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
2
|
import { InternalOpId, storage } from '@powersync/service-core';
|
|
3
|
+
import { EventDefinitionId, HydratedEventDescriptor } from '@powersync/service-sync-rules';
|
|
3
4
|
import { MongoBucketBatch, MongoBucketBatchOptions } from '../MongoBucketBatch.js';
|
|
4
5
|
import { MongoWriteBatch } from '../MongoWriteBatch.js';
|
|
5
6
|
import { SyncRuleDocumentBase } from '../models.js';
|
|
@@ -9,6 +10,12 @@ import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
|
|
|
9
10
|
export declare class MongoBucketBatchV3 extends MongoBucketBatch {
|
|
10
11
|
readonly db: VersionedPowerSyncMongoV3;
|
|
11
12
|
private readonly store;
|
|
13
|
+
private readonly pipeline;
|
|
14
|
+
private enqueuePublication;
|
|
15
|
+
private pendingPublications;
|
|
16
|
+
private pendingInputs;
|
|
17
|
+
/** Owned by the current mutex operation; saves only append to this.batch. */
|
|
18
|
+
private capturedInput;
|
|
12
19
|
/** Avoid repeating idempotent createIndexes calls for every checkpoint flush. */
|
|
13
20
|
private readonly initializedCustomCheckpointEventIds;
|
|
14
21
|
private readonly knownEventIds;
|
|
@@ -16,19 +23,48 @@ export declare class MongoBucketBatchV3 extends MongoBucketBatch {
|
|
|
16
23
|
private needsActivationV3;
|
|
17
24
|
private lastWaitingLogThrottledV3;
|
|
18
25
|
constructor(options: MongoBucketBatchOptions);
|
|
26
|
+
protected getTableEvents(table: storage.SourceTable): {
|
|
27
|
+
event: HydratedEventDescriptor;
|
|
28
|
+
eventId: EventDefinitionId;
|
|
29
|
+
}[];
|
|
30
|
+
save(record: storage.SaveOptions): Promise<storage.FlushedResult | null>;
|
|
31
|
+
commit(lsn: string, options?: storage.BucketBatchCommitOptions): Promise<storage.CheckpointResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Capture this writer's rows/checkpoints and queue preparation under writerMutex.
|
|
34
|
+
* Capture and enqueue happen before yielding, establishing the input's place
|
|
35
|
+
* relative to metadata barriers. Wait for preparation/admission, not necessarily
|
|
36
|
+
* publication. Repairs retain their synchronous flush path.
|
|
37
|
+
*/
|
|
38
|
+
flushBufferedInputToPipeline(): Promise<storage.FlushedResult | null>;
|
|
39
|
+
protected automaticFlush(): Promise<storage.FlushedResult | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Metadata operations capture all live writers before changing shared table state.
|
|
42
|
+
* Explicit flush/commit pass false: they drain admitted work and flush their own
|
|
43
|
+
* input in the callback, without forcing other writers' partial buffers to publish.
|
|
44
|
+
*/
|
|
45
|
+
protected withWriterLock<T>(callback: () => Promise<T>, flushAllWriters?: boolean): Promise<T>;
|
|
46
|
+
private takeBufferedInput;
|
|
47
|
+
/** Only captured batches and metadata operations acquire/trace the writer lock. */
|
|
48
|
+
private withCapturedInputLock;
|
|
49
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
19
50
|
protected createPersistedBatch(writtenSize: number): PersistedBatchV3;
|
|
20
51
|
protected get sourceRecordStore(): SourceRecordStoreV3;
|
|
21
52
|
protected withTransaction<T>(callback: (stream: SyncRuleDocumentBase) => Promise<T>, session?: lib_mongo.mongo.ClientSession): Promise<T>;
|
|
22
|
-
|
|
53
|
+
/** Internal helpers require the public operation to hold the writer mutex. */
|
|
54
|
+
protected flushInternal(options?: storage.BatchBucketFlushOptions): Promise<storage.FlushedResult | null>;
|
|
55
|
+
/** Publish the checkpoint in the final flush transaction, or use the empty-commit path. */
|
|
56
|
+
private flushAndCommit;
|
|
57
|
+
private flushInner;
|
|
23
58
|
private assertPreparationContext;
|
|
24
59
|
/**
|
|
25
|
-
* Internal publisher:
|
|
60
|
+
* Internal publisher: called either by a durable barrier or by the lease FIFO.
|
|
26
61
|
* finish() must only queue writes independent of the final data group, using
|
|
27
62
|
* the fresh fence and planned IDs; it must not execute the supplied batch or
|
|
28
63
|
* read results from unpublished data. Activation and cleanup remain separate.
|
|
29
64
|
*/
|
|
30
65
|
private publishPrepared;
|
|
31
66
|
private prepareRows;
|
|
67
|
+
protected truncateInternal(sourceTables: storage.SourceTable[]): Promise<storage.FlushedResult | null>;
|
|
32
68
|
protected truncateSingleInternal(sourceTable: storage.SourceTable): Promise<InternalOpId>;
|
|
33
69
|
protected persistedOpHead(stream: SyncRuleDocumentBase): InternalOpId;
|
|
34
70
|
protected onReplicationTransactionFlush(writes: MongoWriteBatch, lastOp: InternalOpId): void;
|
|
@@ -51,7 +87,7 @@ export declare class MongoBucketBatchV3 extends MongoBucketBatch {
|
|
|
51
87
|
protected markTableSnapshotRequiredInternal(table: storage.SourceTable): Promise<void>;
|
|
52
88
|
protected markTableSnapshotDoneInternal(tables: storage.SourceTable[], no_checkpoint_before_lsn?: string): Promise<storage.SourceTable[]>;
|
|
53
89
|
private queueCustomWriteCheckpoints;
|
|
54
|
-
protected prepareCustomWriteCheckpoints(): Promise<void>;
|
|
90
|
+
protected prepareCustomWriteCheckpoints(checkpoints: readonly storage.CustomWriteCheckpointOptions[]): Promise<void>;
|
|
55
91
|
private validateCustomCheckpointEventId;
|
|
56
92
|
private batchCreateEventCustomWriteCheckpoints;
|
|
57
93
|
}
|