mvcc-api 1.2.10 → 1.2.11

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.
@@ -163,6 +163,45 @@ var MVCCTransaction = class {
163
163
  }
164
164
  return { success: true, created, updated, deleted };
165
165
  }
166
+ /**
167
+ * Cleans up both deletedCache and versionIndex based on minActiveVersion.
168
+ * Root transactions call this after commit to reclaim memory.
169
+ */
170
+ _cleanupDeletedCache() {
171
+ if (this.deletedCache.size === 0 && this.versionIndex.size === 0) return;
172
+ let minActiveVersion = this.version;
173
+ if (this.activeTransactions.size > 0) {
174
+ for (const tx of this.activeTransactions) {
175
+ if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
176
+ minActiveVersion = tx.snapshotVersion;
177
+ }
178
+ }
179
+ }
180
+ if (this.deletedCache.size > 0) {
181
+ for (const [key, cachedList] of this.deletedCache) {
182
+ const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
183
+ if (remaining.length === 0) {
184
+ this.deletedCache.delete(key);
185
+ } else {
186
+ this.deletedCache.set(key, remaining);
187
+ }
188
+ }
189
+ }
190
+ if (this.versionIndex.size > 0) {
191
+ for (const [key, versions] of this.versionIndex) {
192
+ let latestInSnapshotIdx = -1;
193
+ for (let i = versions.length - 1; i >= 0; i--) {
194
+ if (versions[i].version <= minActiveVersion) {
195
+ latestInSnapshotIdx = i;
196
+ break;
197
+ }
198
+ }
199
+ if (latestInSnapshotIdx > 0) {
200
+ versions.splice(0, latestInSnapshotIdx);
201
+ }
202
+ }
203
+ }
204
+ }
166
205
  };
167
206
 
168
207
  // src/core/sync/Strategy.ts
@@ -506,25 +545,6 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
506
545
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
507
546
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
508
547
  }
509
- _cleanupDeletedCache() {
510
- if (this.deletedCache.size === 0) return;
511
- let minActiveVersion = this.version;
512
- if (this.activeTransactions.size > 0) {
513
- for (const tx of this.activeTransactions) {
514
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
515
- minActiveVersion = tx.snapshotVersion;
516
- }
517
- }
518
- }
519
- for (const [key, cachedList] of this.deletedCache) {
520
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
521
- if (remaining.length === 0) {
522
- this.deletedCache.delete(key);
523
- } else {
524
- this.deletedCache.set(key, remaining);
525
- }
526
- }
527
- }
528
548
  };
529
549
 
530
550
  // src/core/async/Strategy.ts
@@ -1139,23 +1159,4 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
1139
1159
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
1140
1160
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
1141
1161
  }
1142
- _cleanupDeletedCache() {
1143
- if (this.deletedCache.size === 0) return;
1144
- let minActiveVersion = this.version;
1145
- if (this.activeTransactions.size > 0) {
1146
- for (const tx of this.activeTransactions) {
1147
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
1148
- minActiveVersion = tx.snapshotVersion;
1149
- }
1150
- }
1151
- }
1152
- for (const [key, cachedList] of this.deletedCache) {
1153
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
1154
- if (remaining.length === 0) {
1155
- this.deletedCache.delete(key);
1156
- } else {
1157
- this.deletedCache.set(key, remaining);
1158
- }
1159
- }
1160
- }
1161
1162
  };
@@ -132,6 +132,45 @@ var MVCCTransaction = class {
132
132
  }
133
133
  return { success: true, created, updated, deleted };
134
134
  }
135
+ /**
136
+ * Cleans up both deletedCache and versionIndex based on minActiveVersion.
137
+ * Root transactions call this after commit to reclaim memory.
138
+ */
139
+ _cleanupDeletedCache() {
140
+ if (this.deletedCache.size === 0 && this.versionIndex.size === 0) return;
141
+ let minActiveVersion = this.version;
142
+ if (this.activeTransactions.size > 0) {
143
+ for (const tx of this.activeTransactions) {
144
+ if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
145
+ minActiveVersion = tx.snapshotVersion;
146
+ }
147
+ }
148
+ }
149
+ if (this.deletedCache.size > 0) {
150
+ for (const [key, cachedList] of this.deletedCache) {
151
+ const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
152
+ if (remaining.length === 0) {
153
+ this.deletedCache.delete(key);
154
+ } else {
155
+ this.deletedCache.set(key, remaining);
156
+ }
157
+ }
158
+ }
159
+ if (this.versionIndex.size > 0) {
160
+ for (const [key, versions] of this.versionIndex) {
161
+ let latestInSnapshotIdx = -1;
162
+ for (let i = versions.length - 1; i >= 0; i--) {
163
+ if (versions[i].version <= minActiveVersion) {
164
+ latestInSnapshotIdx = i;
165
+ break;
166
+ }
167
+ }
168
+ if (latestInSnapshotIdx > 0) {
169
+ versions.splice(0, latestInSnapshotIdx);
170
+ }
171
+ }
172
+ }
173
+ }
135
174
  };
136
175
 
137
176
  // src/core/sync/Strategy.ts
@@ -475,25 +514,6 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
475
514
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
476
515
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
477
516
  }
478
- _cleanupDeletedCache() {
479
- if (this.deletedCache.size === 0) return;
480
- let minActiveVersion = this.version;
481
- if (this.activeTransactions.size > 0) {
482
- for (const tx of this.activeTransactions) {
483
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
484
- minActiveVersion = tx.snapshotVersion;
485
- }
486
- }
487
- }
488
- for (const [key, cachedList] of this.deletedCache) {
489
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
490
- if (remaining.length === 0) {
491
- this.deletedCache.delete(key);
492
- } else {
493
- this.deletedCache.set(key, remaining);
494
- }
495
- }
496
- }
497
517
  };
498
518
 
499
519
  // src/core/async/Strategy.ts
@@ -1108,25 +1128,6 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
1108
1128
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
1109
1129
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
1110
1130
  }
1111
- _cleanupDeletedCache() {
1112
- if (this.deletedCache.size === 0) return;
1113
- let minActiveVersion = this.version;
1114
- if (this.activeTransactions.size > 0) {
1115
- for (const tx of this.activeTransactions) {
1116
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
1117
- minActiveVersion = tx.snapshotVersion;
1118
- }
1119
- }
1120
- }
1121
- for (const [key, cachedList] of this.deletedCache) {
1122
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
1123
- if (remaining.length === 0) {
1124
- this.deletedCache.delete(key);
1125
- } else {
1126
- this.deletedCache.set(key, remaining);
1127
- }
1128
- }
1129
- }
1130
1131
  };
1131
1132
  export {
1132
1133
  AsyncMVCCStrategy,
@@ -17,5 +17,4 @@ export declare class AsyncMVCCTransaction<S extends AsyncMVCCStrategy<K, T>, K,
17
17
  _diskRead(key: K, snapshotVersion: number): Promise<T | null>;
18
18
  _diskExists(key: K, snapshotVersion: number): Promise<boolean>;
19
19
  _diskDelete(key: K, snapshotVersion: number): Promise<void>;
20
- _cleanupDeletedCache(): void;
21
20
  }
@@ -120,4 +120,9 @@ export declare abstract class MVCCTransaction<S extends MVCCStrategy<K, T>, K, T
120
120
  * @param snapshotLocalVersion The local version within the parent's buffer to read at.
121
121
  */
122
122
  abstract _readSnapshot(key: K, snapshotVersion: number, snapshotLocalVersion?: number): Deferred<T | null>;
123
+ /**
124
+ * Cleans up both deletedCache and versionIndex based on minActiveVersion.
125
+ * Root transactions call this after commit to reclaim memory.
126
+ */
127
+ protected _cleanupDeletedCache(): void;
123
128
  }
@@ -15,5 +15,4 @@ export declare class SyncMVCCTransaction<S extends SyncMVCCStrategy<K, T>, K, T>
15
15
  _diskRead(key: K, snapshotVersion: number): T | null;
16
16
  _diskExists(key: K, snapshotVersion: number): boolean;
17
17
  _diskDelete(key: K, snapshotVersion: number): void;
18
- _cleanupDeletedCache(): void;
19
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mvcc-api",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "Multiversion Concurrency Control (MVCC) API for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",