@powersync/service-module-mongodb-storage 0.15.3 → 0.16.0

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.
Files changed (204) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +1 -1
  3. package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -1
  4. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +3 -3
  5. package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
  6. package/dist/migrations/db/migrations/1770213298299-storage-version.js.map +1 -1
  7. package/dist/storage/MongoBucketStorage.d.ts +5 -3
  8. package/dist/storage/MongoBucketStorage.js +50 -36
  9. package/dist/storage/MongoBucketStorage.js.map +1 -1
  10. package/dist/storage/MongoReportStorage.js.map +1 -1
  11. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +17 -0
  12. package/dist/storage/implementation/BucketDefinitionMapping.js +58 -0
  13. package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
  14. package/dist/storage/implementation/MongoBucketBatch.d.ts +16 -14
  15. package/dist/storage/implementation/MongoBucketBatch.js +80 -115
  16. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  17. package/dist/storage/implementation/MongoBucketBatchShared.d.ts +5 -0
  18. package/dist/storage/implementation/MongoBucketBatchShared.js +8 -0
  19. package/dist/storage/implementation/MongoBucketBatchShared.js.map +1 -0
  20. package/dist/storage/implementation/MongoChecksums.d.ts +28 -17
  21. package/dist/storage/implementation/MongoChecksums.js +13 -72
  22. package/dist/storage/implementation/MongoChecksums.js.map +1 -1
  23. package/dist/storage/implementation/MongoCompactor.d.ts +98 -58
  24. package/dist/storage/implementation/MongoCompactor.js +229 -296
  25. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  26. package/dist/storage/implementation/MongoParameterCompactor.d.ts +11 -6
  27. package/dist/storage/implementation/MongoParameterCompactor.js +11 -8
  28. package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
  29. package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +14 -0
  30. package/dist/storage/implementation/MongoPersistedSyncRules.js +64 -0
  31. package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
  32. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +3 -0
  33. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +9 -0
  34. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
  35. package/dist/storage/implementation/MongoStorageProvider.js +1 -1
  36. package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
  37. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +49 -30
  38. package/dist/storage/implementation/MongoSyncBucketStorage.js +96 -388
  39. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  40. package/dist/storage/implementation/MongoSyncRulesLock.d.ts +5 -3
  41. package/dist/storage/implementation/MongoSyncRulesLock.js +12 -10
  42. package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
  43. package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -1
  44. package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
  45. package/dist/storage/implementation/OperationBatch.js +1 -1
  46. package/dist/storage/implementation/common/BucketDataDoc.d.ts +35 -0
  47. package/dist/storage/implementation/common/BucketDataDoc.js +2 -0
  48. package/dist/storage/implementation/common/BucketDataDoc.js.map +1 -0
  49. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +13 -0
  50. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +2 -0
  51. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +1 -0
  52. package/dist/storage/implementation/common/PersistedBatch.d.ts +108 -0
  53. package/dist/storage/implementation/common/PersistedBatch.js +237 -0
  54. package/dist/storage/implementation/common/PersistedBatch.js.map +1 -0
  55. package/dist/storage/implementation/common/SingleBucketStore.d.ts +54 -0
  56. package/dist/storage/implementation/common/SingleBucketStore.js +3 -0
  57. package/dist/storage/implementation/common/SingleBucketStore.js.map +1 -0
  58. package/dist/storage/implementation/common/SourceRecordStore.d.ts +36 -0
  59. package/dist/storage/implementation/common/SourceRecordStore.js +2 -0
  60. package/dist/storage/implementation/common/SourceRecordStore.js.map +1 -0
  61. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +27 -0
  62. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +57 -0
  63. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -0
  64. package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +7 -0
  65. package/dist/storage/implementation/createMongoSyncBucketStorage.js +9 -0
  66. package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -0
  67. package/dist/storage/implementation/db.d.ts +34 -34
  68. package/dist/storage/implementation/db.js +78 -98
  69. package/dist/storage/implementation/db.js.map +1 -1
  70. package/dist/storage/implementation/models.d.ts +63 -34
  71. package/dist/storage/implementation/models.js +21 -2
  72. package/dist/storage/implementation/models.js.map +1 -1
  73. package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +13 -0
  74. package/dist/storage/implementation/v1/MongoBucketBatchV1.js +22 -0
  75. package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -0
  76. package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +12 -0
  77. package/dist/storage/implementation/v1/MongoChecksumsV1.js +56 -0
  78. package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -0
  79. package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +23 -0
  80. package/dist/storage/implementation/v1/MongoCompactorV1.js +52 -0
  81. package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -0
  82. package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +9 -0
  83. package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -0
  84. package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -0
  85. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +41 -0
  86. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +283 -0
  87. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -0
  88. package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +26 -0
  89. package/dist/storage/implementation/v1/PersistedBatchV1.js +183 -0
  90. package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -0
  91. package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +18 -0
  92. package/dist/storage/implementation/v1/SingleBucketStoreV1.js +57 -0
  93. package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -0
  94. package/dist/storage/implementation/v1/SourceRecordStoreV1.d.ts +19 -0
  95. package/dist/storage/implementation/v1/SourceRecordStoreV1.js +105 -0
  96. package/dist/storage/implementation/v1/SourceRecordStoreV1.js.map +1 -0
  97. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +12 -0
  98. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +20 -0
  99. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -0
  100. package/dist/storage/implementation/v1/models.d.ts +34 -0
  101. package/dist/storage/implementation/v1/models.js +37 -0
  102. package/dist/storage/implementation/v1/models.js.map +1 -0
  103. package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +13 -0
  104. package/dist/storage/implementation/v3/MongoBucketBatchV3.js +34 -0
  105. package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -0
  106. package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +15 -0
  107. package/dist/storage/implementation/v3/MongoChecksumsV3.js +84 -0
  108. package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -0
  109. package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +23 -0
  110. package/dist/storage/implementation/v3/MongoCompactorV3.js +68 -0
  111. package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -0
  112. package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +9 -0
  113. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +18 -0
  114. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
  115. package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +5 -0
  116. package/dist/storage/implementation/v3/MongoParameterLookupV3.js +9 -0
  117. package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +1 -0
  118. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +41 -0
  119. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +407 -0
  120. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -0
  121. package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +29 -0
  122. package/dist/storage/implementation/v3/PersistedBatchV3.js +259 -0
  123. package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -0
  124. package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +18 -0
  125. package/dist/storage/implementation/v3/SingleBucketStoreV3.js +48 -0
  126. package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -0
  127. package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +22 -0
  128. package/dist/storage/implementation/v3/SourceRecordStoreV3.js +164 -0
  129. package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -0
  130. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +21 -0
  131. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +71 -0
  132. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -0
  133. package/dist/storage/implementation/v3/models.d.ts +43 -0
  134. package/dist/storage/implementation/v3/models.js +34 -0
  135. package/dist/storage/implementation/v3/models.js.map +1 -0
  136. package/dist/storage/storage-index.d.ts +8 -5
  137. package/dist/storage/storage-index.js +8 -5
  138. package/dist/storage/storage-index.js.map +1 -1
  139. package/dist/utils/util.d.ts +11 -4
  140. package/dist/utils/util.js +25 -4
  141. package/dist/utils/util.js.map +1 -1
  142. package/package.json +9 -9
  143. package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +1 -1
  144. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -7
  145. package/src/migrations/db/migrations/1770213298299-storage-version.ts +1 -1
  146. package/src/storage/MongoBucketStorage.ts +97 -62
  147. package/src/storage/MongoReportStorage.ts +2 -2
  148. package/src/storage/implementation/BucketDefinitionMapping.ts +72 -0
  149. package/src/storage/implementation/MongoBucketBatch.ts +110 -144
  150. package/src/storage/implementation/MongoBucketBatchShared.ts +11 -0
  151. package/src/storage/implementation/MongoChecksums.ts +53 -76
  152. package/src/storage/implementation/MongoCompactor.ts +374 -404
  153. package/src/storage/implementation/MongoParameterCompactor.ts +37 -24
  154. package/src/storage/implementation/MongoPersistedSyncRules.ts +76 -0
  155. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +18 -1
  156. package/src/storage/implementation/MongoStorageProvider.ts +1 -1
  157. package/src/storage/implementation/MongoSyncBucketStorage.ts +190 -457
  158. package/src/storage/implementation/MongoSyncRulesLock.ts +12 -14
  159. package/src/storage/implementation/MongoWriteCheckpointAPI.ts +4 -2
  160. package/src/storage/implementation/OperationBatch.ts +1 -1
  161. package/src/storage/implementation/common/BucketDataDoc.ts +37 -0
  162. package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +15 -0
  163. package/src/storage/implementation/common/PersistedBatch.ts +364 -0
  164. package/src/storage/implementation/common/SingleBucketStore.ts +63 -0
  165. package/src/storage/implementation/common/SourceRecordStore.ts +49 -0
  166. package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +80 -0
  167. package/src/storage/implementation/createMongoSyncBucketStorage.ts +25 -0
  168. package/src/storage/implementation/db.ts +107 -128
  169. package/src/storage/implementation/models.ts +84 -38
  170. package/src/storage/implementation/v1/MongoBucketBatchV1.ts +32 -0
  171. package/src/storage/implementation/v1/MongoChecksumsV1.ts +75 -0
  172. package/src/storage/implementation/v1/MongoCompactorV1.ts +93 -0
  173. package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +26 -0
  174. package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +448 -0
  175. package/src/storage/implementation/v1/PersistedBatchV1.ts +230 -0
  176. package/src/storage/implementation/v1/SingleBucketStoreV1.ts +74 -0
  177. package/src/storage/implementation/v1/SourceRecordStoreV1.ts +156 -0
  178. package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +28 -0
  179. package/src/storage/implementation/v1/models.ts +84 -0
  180. package/src/storage/implementation/v3/MongoBucketBatchV3.ts +44 -0
  181. package/src/storage/implementation/v3/MongoChecksumsV3.ts +120 -0
  182. package/src/storage/implementation/v3/MongoCompactorV3.ts +107 -0
  183. package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +24 -0
  184. package/src/storage/implementation/v3/MongoParameterLookupV3.ts +12 -0
  185. package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +550 -0
  186. package/src/storage/implementation/v3/PersistedBatchV3.ts +318 -0
  187. package/src/storage/implementation/v3/SingleBucketStoreV3.ts +68 -0
  188. package/src/storage/implementation/v3/SourceRecordStoreV3.ts +226 -0
  189. package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +112 -0
  190. package/src/storage/implementation/v3/models.ts +96 -0
  191. package/src/storage/storage-index.ts +8 -5
  192. package/src/utils/util.ts +36 -7
  193. package/test/src/__snapshots__/storage_sync.test.ts.snap +282 -0
  194. package/test/src/connection-report-storage.test.ts +3 -3
  195. package/test/src/setup.ts +1 -1
  196. package/test/src/storage.test.ts +2 -2
  197. package/test/src/storage_compacting.test.ts +57 -29
  198. package/test/src/storage_sync.test.ts +351 -5
  199. package/test/tsconfig.json +0 -1
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/dist/storage/implementation/PersistedBatch.d.ts +0 -71
  202. package/dist/storage/implementation/PersistedBatch.js +0 -354
  203. package/dist/storage/implementation/PersistedBatch.js.map +0 -1
  204. package/src/storage/implementation/PersistedBatch.ts +0 -432
@@ -1,71 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { EvaluatedParameters, EvaluatedRow } from '@powersync/service-sync-rules';
3
- import * as bson from 'bson';
4
- import { Logger } from '@powersync/lib-services-framework';
5
- import { InternalOpId, storage } from '@powersync/service-core';
6
- import { MongoIdSequence } from './MongoIdSequence.js';
7
- import { VersionedPowerSyncMongo } from './db.js';
8
- import { BucketDataDocument, BucketParameterDocument, CurrentBucket, CurrentDataDocument, SourceKey } from './models.js';
9
- /**
10
- * Keeps track of bulkwrite operations within a transaction.
11
- *
12
- * There may be multiple of these batches per transaction, but it may not span
13
- * multiple transactions.
14
- */
15
- export declare class PersistedBatch {
16
- private db;
17
- private group_id;
18
- logger: Logger;
19
- bucketData: mongo.AnyBulkWriteOperation<BucketDataDocument>[];
20
- bucketParameters: mongo.AnyBulkWriteOperation<BucketParameterDocument>[];
21
- currentData: mongo.AnyBulkWriteOperation<CurrentDataDocument>[];
22
- bucketStates: Map<string, BucketStateUpdate>;
23
- /**
24
- * For debug logging only.
25
- */
26
- debugLastOpId: InternalOpId | null;
27
- /**
28
- * Very rough estimate of transaction size.
29
- */
30
- currentSize: number;
31
- constructor(db: VersionedPowerSyncMongo, group_id: number, writtenSize: number, options?: {
32
- logger?: Logger;
33
- });
34
- private incrementBucket;
35
- saveBucketData(options: {
36
- op_seq: MongoIdSequence;
37
- sourceKey: storage.ReplicaId;
38
- table: storage.SourceTable;
39
- evaluated: EvaluatedRow[];
40
- before_buckets: CurrentBucket[];
41
- }): void;
42
- saveParameterData(data: {
43
- op_seq: MongoIdSequence;
44
- sourceKey: storage.ReplicaId;
45
- sourceTable: storage.SourceTable;
46
- evaluated: EvaluatedParameters[];
47
- existing_lookups: bson.Binary[];
48
- }): void;
49
- hardDeleteCurrentData(id: SourceKey): void;
50
- /**
51
- * Mark a current_data document as soft deleted, to delete on the next commit.
52
- *
53
- * If softDeleteCurrentData is not enabled, this falls back to a hard delete.
54
- */
55
- softDeleteCurrentData(id: SourceKey, checkpointGreaterThan: bigint): void;
56
- upsertCurrentData(id: SourceKey, values: Partial<CurrentDataDocument>): void;
57
- shouldFlushTransaction(): boolean;
58
- flush(session: mongo.ClientSession, options?: storage.BucketBatchCommitOptions): Promise<{
59
- bucketDataCount: number;
60
- parameterDataCount: number;
61
- currentDataCount: number;
62
- flushedAny: boolean;
63
- }>;
64
- private getBucketStateUpdates;
65
- }
66
- interface BucketStateUpdate {
67
- lastOp: InternalOpId;
68
- incrementCount: number;
69
- incrementBytes: number;
70
- }
71
- export {};
@@ -1,354 +0,0 @@
1
- import { JSONBig } from '@powersync/service-jsonbig';
2
- import { logger as defaultLogger } from '@powersync/lib-services-framework';
3
- import { storage, utils } from '@powersync/service-core';
4
- import { currentBucketKey, EMPTY_DATA, MAX_ROW_SIZE } from './MongoBucketBatch.js';
5
- import { mongoTableId, replicaIdToSubkey } from '../../utils/util.js';
6
- /**
7
- * Maximum size of operations we write in a single transaction.
8
- *
9
- * It's tricky to find the exact limit, but from experience, over 100MB
10
- * can cause an error:
11
- * > transaction is too large and will not fit in the storage engine cache
12
- *
13
- * Additionally, unbounded size here can balloon our memory usage in some edge
14
- * cases.
15
- *
16
- * When we reach this threshold, we commit the transaction and start a new one.
17
- */
18
- const MAX_TRANSACTION_BATCH_SIZE = 30_000_000;
19
- /**
20
- * Limit number of documents to write in a single transaction.
21
- *
22
- * This has an effect on error message size in some cases.
23
- */
24
- const MAX_TRANSACTION_DOC_COUNT = 2_000;
25
- /**
26
- * Keeps track of bulkwrite operations within a transaction.
27
- *
28
- * There may be multiple of these batches per transaction, but it may not span
29
- * multiple transactions.
30
- */
31
- export class PersistedBatch {
32
- db;
33
- group_id;
34
- logger;
35
- bucketData = [];
36
- bucketParameters = [];
37
- currentData = [];
38
- bucketStates = new Map();
39
- /**
40
- * For debug logging only.
41
- */
42
- debugLastOpId = null;
43
- /**
44
- * Very rough estimate of transaction size.
45
- */
46
- currentSize = 0;
47
- constructor(db, group_id, writtenSize, options) {
48
- this.db = db;
49
- this.group_id = group_id;
50
- this.currentSize = writtenSize;
51
- this.logger = options?.logger ?? defaultLogger;
52
- }
53
- incrementBucket(bucket, op_id, bytes) {
54
- let existingState = this.bucketStates.get(bucket);
55
- if (existingState) {
56
- existingState.lastOp = op_id;
57
- existingState.incrementCount += 1;
58
- existingState.incrementBytes += bytes;
59
- }
60
- else {
61
- this.bucketStates.set(bucket, {
62
- lastOp: op_id,
63
- incrementCount: 1,
64
- incrementBytes: bytes
65
- });
66
- }
67
- }
68
- saveBucketData(options) {
69
- const remaining_buckets = new Map();
70
- for (let b of options.before_buckets) {
71
- const key = currentBucketKey(b);
72
- remaining_buckets.set(key, b);
73
- }
74
- const dchecksum = BigInt(utils.hashDelete(replicaIdToSubkey(options.table.id, options.sourceKey)));
75
- for (const k of options.evaluated) {
76
- const key = currentBucketKey(k);
77
- // INSERT
78
- const recordData = JSONBig.stringify(k.data);
79
- const checksum = utils.hashData(k.table, k.id, recordData);
80
- if (recordData.length > MAX_ROW_SIZE) {
81
- // In many cases, the raw data size would have been too large already. But there are cases where
82
- // the BSON size is small enough, but the JSON size is too large.
83
- // In these cases, we can't store the data, so we skip it, or generate a REMOVE operation if the row
84
- // was synced previously.
85
- this.logger.error(`Row ${key} too large: ${recordData.length} bytes. Removing.`);
86
- continue;
87
- }
88
- remaining_buckets.delete(key);
89
- const byteEstimate = recordData.length + 200;
90
- this.currentSize += byteEstimate;
91
- const op_id = options.op_seq.next();
92
- this.debugLastOpId = op_id;
93
- this.bucketData.push({
94
- insertOne: {
95
- document: {
96
- _id: {
97
- g: this.group_id,
98
- b: k.bucket,
99
- o: op_id
100
- },
101
- op: 'PUT',
102
- source_table: mongoTableId(options.table.id),
103
- source_key: options.sourceKey,
104
- table: k.table,
105
- row_id: k.id,
106
- checksum: BigInt(checksum),
107
- data: recordData
108
- }
109
- }
110
- });
111
- this.incrementBucket(k.bucket, op_id, byteEstimate);
112
- }
113
- for (let bd of remaining_buckets.values()) {
114
- // REMOVE
115
- const op_id = options.op_seq.next();
116
- this.debugLastOpId = op_id;
117
- this.bucketData.push({
118
- insertOne: {
119
- document: {
120
- _id: {
121
- g: this.group_id,
122
- b: bd.bucket,
123
- o: op_id
124
- },
125
- op: 'REMOVE',
126
- source_table: mongoTableId(options.table.id),
127
- source_key: options.sourceKey,
128
- table: bd.table,
129
- row_id: bd.id,
130
- checksum: dchecksum,
131
- data: null
132
- }
133
- }
134
- });
135
- this.currentSize += 200;
136
- this.incrementBucket(bd.bucket, op_id, 200);
137
- }
138
- }
139
- saveParameterData(data) {
140
- // This is similar to saving bucket data.
141
- // A key difference is that we don't need to keep the history intact.
142
- // We do need to keep track of recent history though - enough that we can get consistent data for any specific checkpoint.
143
- // Instead of storing per bucket id, we store per "lookup".
144
- // A key difference is that we don't need to store or keep track of anything per-bucket - the entire record is
145
- // either persisted or removed.
146
- // We also don't need to keep history intact.
147
- const { sourceTable, sourceKey, evaluated } = data;
148
- const remaining_lookups = new Map();
149
- for (let l of data.existing_lookups) {
150
- remaining_lookups.set(l.toString('base64'), l);
151
- }
152
- // 1. Insert new entries
153
- for (let result of evaluated) {
154
- const binLookup = storage.serializeLookup(result.lookup);
155
- const hex = binLookup.toString('base64');
156
- remaining_lookups.delete(hex);
157
- const op_id = data.op_seq.next();
158
- this.debugLastOpId = op_id;
159
- this.bucketParameters.push({
160
- insertOne: {
161
- document: {
162
- _id: op_id,
163
- key: {
164
- g: this.group_id,
165
- t: mongoTableId(sourceTable.id),
166
- k: sourceKey
167
- },
168
- lookup: binLookup,
169
- bucket_parameters: result.bucketParameters
170
- }
171
- }
172
- });
173
- this.currentSize += 200;
174
- }
175
- // 2. "REMOVE" entries for any lookup not touched.
176
- for (let lookup of remaining_lookups.values()) {
177
- const op_id = data.op_seq.next();
178
- this.debugLastOpId = op_id;
179
- this.bucketParameters.push({
180
- insertOne: {
181
- document: {
182
- _id: op_id,
183
- key: {
184
- g: this.group_id,
185
- t: mongoTableId(sourceTable.id),
186
- k: sourceKey
187
- },
188
- lookup: lookup,
189
- bucket_parameters: []
190
- }
191
- }
192
- });
193
- this.currentSize += 200;
194
- }
195
- }
196
- hardDeleteCurrentData(id) {
197
- const op = {
198
- deleteOne: {
199
- filter: { _id: id }
200
- }
201
- };
202
- this.currentData.push(op);
203
- this.currentSize += 50;
204
- }
205
- /**
206
- * Mark a current_data document as soft deleted, to delete on the next commit.
207
- *
208
- * If softDeleteCurrentData is not enabled, this falls back to a hard delete.
209
- */
210
- softDeleteCurrentData(id, checkpointGreaterThan) {
211
- if (!this.db.storageConfig.softDeleteCurrentData) {
212
- this.hardDeleteCurrentData(id);
213
- return;
214
- }
215
- const op = {
216
- updateOne: {
217
- filter: { _id: id },
218
- update: {
219
- $set: {
220
- data: EMPTY_DATA,
221
- buckets: [],
222
- lookups: [],
223
- pending_delete: checkpointGreaterThan
224
- }
225
- },
226
- upsert: true
227
- }
228
- };
229
- this.currentData.push(op);
230
- this.currentSize += 50;
231
- }
232
- upsertCurrentData(id, values) {
233
- const op = {
234
- updateOne: {
235
- filter: { _id: id },
236
- update: {
237
- $set: values,
238
- $unset: { pending_delete: 1 }
239
- },
240
- upsert: true
241
- }
242
- };
243
- this.currentData.push(op);
244
- this.currentSize += (values.data?.length() ?? 0) + 100;
245
- }
246
- shouldFlushTransaction() {
247
- return (this.currentSize >= MAX_TRANSACTION_BATCH_SIZE ||
248
- this.bucketData.length >= MAX_TRANSACTION_DOC_COUNT ||
249
- this.currentData.length >= MAX_TRANSACTION_DOC_COUNT ||
250
- this.bucketParameters.length >= MAX_TRANSACTION_DOC_COUNT);
251
- }
252
- async flush(session, options) {
253
- const db = this.db;
254
- const startAt = performance.now();
255
- let flushedSomething = false;
256
- if (this.bucketData.length > 0) {
257
- flushedSomething = true;
258
- await db.bucket_data.bulkWrite(this.bucketData, {
259
- session,
260
- // inserts only - order doesn't matter
261
- ordered: false
262
- });
263
- }
264
- if (this.bucketParameters.length > 0) {
265
- flushedSomething = true;
266
- await db.bucket_parameters.bulkWrite(this.bucketParameters, {
267
- session,
268
- // inserts only - order doesn't matter
269
- ordered: false
270
- });
271
- }
272
- if (this.currentData.length > 0) {
273
- flushedSomething = true;
274
- await db.common_current_data.bulkWrite(this.currentData, {
275
- session,
276
- // may update and delete data within the same batch - order matters
277
- ordered: true
278
- });
279
- }
280
- if (this.bucketStates.size > 0) {
281
- flushedSomething = true;
282
- await db.bucket_state.bulkWrite(this.getBucketStateUpdates(), {
283
- session,
284
- // Per-bucket operation - order doesn't matter
285
- ordered: false
286
- });
287
- }
288
- if (flushedSomething) {
289
- const duration = Math.round(performance.now() - startAt);
290
- if (options?.oldestUncommittedChange != null) {
291
- const replicationLag = Math.round((Date.now() - options.oldestUncommittedChange.getTime()) / 1000);
292
- this.logger.info(`Flushed ${this.bucketData.length} + ${this.bucketParameters.length} + ${this.currentData.length} updates, ${Math.round(this.currentSize / 1024)}kb in ${duration}ms. Last op_id: ${this.debugLastOpId}. Replication lag: ${replicationLag}s`, {
293
- flushed: {
294
- duration: duration,
295
- size: this.currentSize,
296
- bucket_data_count: this.bucketData.length,
297
- parameter_data_count: this.bucketParameters.length,
298
- current_data_count: this.currentData.length,
299
- replication_lag_seconds: replicationLag
300
- }
301
- });
302
- }
303
- else {
304
- this.logger.info(`Flushed ${this.bucketData.length} + ${this.bucketParameters.length} + ${this.currentData.length} updates, ${Math.round(this.currentSize / 1024)}kb in ${duration}ms. Last op_id: ${this.debugLastOpId}`, {
305
- flushed: {
306
- duration: duration,
307
- size: this.currentSize,
308
- bucket_data_count: this.bucketData.length,
309
- parameter_data_count: this.bucketParameters.length,
310
- current_data_count: this.currentData.length
311
- }
312
- });
313
- }
314
- }
315
- const stats = {
316
- bucketDataCount: this.bucketData.length,
317
- parameterDataCount: this.bucketParameters.length,
318
- currentDataCount: this.currentData.length,
319
- flushedAny: flushedSomething
320
- };
321
- this.bucketData = [];
322
- this.bucketParameters = [];
323
- this.currentData = [];
324
- this.bucketStates.clear();
325
- this.currentSize = 0;
326
- this.debugLastOpId = null;
327
- return stats;
328
- }
329
- getBucketStateUpdates() {
330
- return Array.from(this.bucketStates.entries()).map(([bucket, state]) => {
331
- return {
332
- updateOne: {
333
- filter: {
334
- _id: {
335
- g: this.group_id,
336
- b: bucket
337
- }
338
- },
339
- update: {
340
- $set: {
341
- last_op: state.lastOp
342
- },
343
- $inc: {
344
- 'estimate_since_compact.count': state.incrementCount,
345
- 'estimate_since_compact.bytes': state.incrementBytes
346
- }
347
- },
348
- upsert: true
349
- }
350
- };
351
- });
352
- }
353
- }
354
- //# sourceMappingURL=PersistedBatch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersistedBatch.js","sourceRoot":"","sources":["../../../src/storage/implementation/PersistedBatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAIrD,OAAO,EAAU,MAAM,IAAI,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAgB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWnF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,0BAA0B,GAAG,UAAU,CAAC;AAE9C;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAExC;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAkBf;IACA;IAlBV,MAAM,CAAS;IACf,UAAU,GAAsD,EAAE,CAAC;IACnE,gBAAgB,GAA2D,EAAE,CAAC;IAC9E,WAAW,GAAuD,EAAE,CAAC;IACrE,YAAY,GAAmC,IAAI,GAAG,EAAE,CAAC;IAEzD;;OAEG;IACH,aAAa,GAAwB,IAAI,CAAC;IAE1C;;OAEG;IACH,WAAW,GAAG,CAAC,CAAC;IAEhB,YACU,EAA2B,EAC3B,QAA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