axiodb 12.10.26 → 13.0.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.
- package/README.md +15 -45
- package/lib/Helper/DocumentLoader.helper.d.ts +1 -1
- package/lib/Helper/DocumentLoader.helper.js +3 -3
- package/lib/Helper/DocumentLoader.helper.js.map +1 -1
- package/lib/Helper/SortedIndexValues.helper.d.ts +45 -0
- package/lib/Helper/SortedIndexValues.helper.js +105 -0
- package/lib/Helper/SortedIndexValues.helper.js.map +1 -0
- package/lib/Services/Aggregation/Aggregation.Operation.d.ts +3 -8
- package/lib/Services/Aggregation/Aggregation.Operation.js +4 -11
- package/lib/Services/Aggregation/Aggregation.Operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Create.operation.js +14 -2
- package/lib/Services/CRUD Operation/Create.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Delete.operation.d.ts +3 -7
- package/lib/Services/CRUD Operation/Delete.operation.js +37 -24
- package/lib/Services/CRUD Operation/Delete.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Reader.operation.d.ts +3 -8
- package/lib/Services/CRUD Operation/Reader.operation.js +8 -12
- package/lib/Services/CRUD Operation/Reader.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Update.operation.d.ts +3 -18
- package/lib/Services/CRUD Operation/Update.operation.js +68 -50
- package/lib/Services/CRUD Operation/Update.operation.js.map +1 -1
- package/lib/Services/Collection/collection.operation.d.ts +14 -7
- package/lib/Services/Collection/collection.operation.js +52 -53
- package/lib/Services/Collection/collection.operation.js.map +1 -1
- package/lib/Services/Database/database.operation.d.ts +1 -3
- package/lib/Services/Database/database.operation.js +14 -59
- package/lib/Services/Database/database.operation.js.map +1 -1
- package/lib/Services/Index/DeleteIndex.service.js +11 -1
- package/lib/Services/Index/DeleteIndex.service.js.map +1 -1
- package/lib/Services/Index/Index.service.js +1 -0
- package/lib/Services/Index/Index.service.js.map +1 -1
- package/lib/Services/Index/IndexCache.service.d.ts +39 -12
- package/lib/Services/Index/IndexCache.service.js +64 -24
- package/lib/Services/Index/IndexCache.service.js.map +1 -1
- package/lib/Services/Index/InsertIndex.service.js +13 -1
- package/lib/Services/Index/InsertIndex.service.js.map +1 -1
- package/lib/Services/Index/ReadIndex.service.d.ts +31 -0
- package/lib/Services/Index/ReadIndex.service.js +50 -1
- package/lib/Services/Index/ReadIndex.service.js.map +1 -1
- package/lib/Services/Transaction/LockManager.service.d.ts +6 -1
- package/lib/Services/Transaction/LockManager.service.js +36 -26
- package/lib/Services/Transaction/LockManager.service.js.map +1 -1
- package/lib/Services/Transaction/Session.service.d.ts +1 -3
- package/lib/Services/Transaction/Session.service.js +2 -4
- package/lib/Services/Transaction/Session.service.js.map +1 -1
- package/lib/Services/Transaction/Transaction.service.d.ts +1 -4
- package/lib/Services/Transaction/Transaction.service.js +26 -24
- package/lib/Services/Transaction/Transaction.service.js.map +1 -1
- package/lib/Services/Transaction/TransactionIndexManager.service.d.ts +2 -4
- package/lib/Services/Transaction/TransactionIndexManager.service.js +48 -32
- package/lib/Services/Transaction/TransactionIndexManager.service.js.map +1 -1
- package/lib/Services/Transaction/TransactionRegistry.service.js +3 -3
- package/lib/Services/Transaction/TransactionRegistry.service.js.map +1 -1
- package/lib/Services/Transaction/WriteAheadLog.service.d.ts +1 -3
- package/lib/Services/Transaction/WriteAheadLog.service.js +4 -21
- package/lib/Services/Transaction/WriteAheadLog.service.js.map +1 -1
- package/lib/client/DatabaseProxy.d.ts +1 -1
- package/lib/client/DatabaseProxy.js +1 -3
- package/lib/client/DatabaseProxy.js.map +1 -1
- package/lib/config/DB.d.ts +0 -3
- package/lib/config/DB.js +0 -2
- package/lib/config/DB.js.map +1 -1
- package/lib/engine/Filesystem/FileManager.d.ts +9 -0
- package/lib/engine/Filesystem/FileManager.js +70 -1
- package/lib/engine/Filesystem/FileManager.js.map +1 -1
- package/lib/engine/node/WorkerForDataLoad.engine.js +8 -26
- package/lib/engine/node/WorkerForDataLoad.engine.js.map +1 -1
- package/lib/server/controller/Collections/Collection.controller.js +2 -2
- package/lib/server/controller/Collections/Collection.controller.js.map +1 -1
- package/lib/server/public/AxioControl/.vite/manifest.json +2 -2
- package/lib/server/public/AxioControl/assets/index-05O5admf.css +1 -0
- package/lib/server/public/AxioControl/assets/{index-DyJg6FRw.js → index-Ddne1B8d.js} +11 -11
- package/lib/server/public/AxioControl/index.html +2 -2
- package/lib/server/public/AxioControl/sw.js +1 -1
- package/lib/tcp/handler/handlers/Collection.handler.js +2 -2
- package/lib/tcp/handler/handlers/Collection.handler.js.map +1 -1
- package/lib/utility/BufferLoaderWithWorker.utils.d.ts +1 -3
- package/lib/utility/BufferLoaderWithWorker.utils.js +8 -32
- package/lib/utility/BufferLoaderWithWorker.utils.js.map +1 -1
- package/package.json +1 -3
- package/lib/Helper/Crypto.helper.d.ts +0 -14
- package/lib/Helper/Crypto.helper.js +0 -55
- package/lib/Helper/Crypto.helper.js.map +0 -1
- package/lib/Helper/CryptoGraphy.helper.d.ts +0 -15
- package/lib/Helper/CryptoGraphy.helper.js +0 -52
- package/lib/Helper/CryptoGraphy.helper.js.map +0 -1
- package/lib/server/public/AxioControl/assets/index-D3V1EZ2f.css +0 -1
|
@@ -6,6 +6,13 @@ interface IndexData {
|
|
|
6
6
|
indexEntries: {
|
|
7
7
|
[value: string]: string[];
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Sorted, de-duplicated numeric values for this field - enables O(log U + M)
|
|
11
|
+
* range queries ($gt/$gte/$lt/$lte) instead of a full collection scan.
|
|
12
|
+
* Optional for backward compatibility with indexes written before range
|
|
13
|
+
* support existed; those are lazily backfilled on first insert/delete.
|
|
14
|
+
*/
|
|
15
|
+
sortedValues?: number[];
|
|
9
16
|
}
|
|
10
17
|
/**
|
|
11
18
|
* In-memory cache for index data
|
|
@@ -19,23 +26,44 @@ interface IndexData {
|
|
|
19
26
|
*
|
|
20
27
|
* @example
|
|
21
28
|
* ```typescript
|
|
22
|
-
* const indexCache =
|
|
29
|
+
* const indexCache = IndexCache.getInstance('/path/to/collection');
|
|
23
30
|
* await indexCache.loadAllIndexes(); // Eager load
|
|
24
31
|
* const indexData = await indexCache.getIndex('email'); // O(1) memory access
|
|
25
32
|
* ```
|
|
26
33
|
*/
|
|
27
34
|
export declare class IndexCache {
|
|
35
|
+
private static instances;
|
|
28
36
|
private cache;
|
|
29
37
|
private readonly indexFolderPath;
|
|
30
38
|
private readonly indexMetaPath;
|
|
31
39
|
private readonly fileManager;
|
|
32
40
|
private readonly converter;
|
|
33
|
-
private
|
|
41
|
+
private lockChains;
|
|
34
42
|
private cleanupInterval;
|
|
35
43
|
private static readonly MIN_TTL_MS;
|
|
36
44
|
private static readonly MAX_TTL_MS;
|
|
37
45
|
private static readonly CLEANUP_INTERVAL_MS;
|
|
38
|
-
constructor(
|
|
46
|
+
private constructor();
|
|
47
|
+
/**
|
|
48
|
+
* Returns the shared IndexCache for a collection path, creating it on first use.
|
|
49
|
+
* All index services (Insert/Read/Delete/Collection) must go through this instead of
|
|
50
|
+
* constructing their own instance, otherwise locking and caching are per-call and
|
|
51
|
+
* provide no real coordination.
|
|
52
|
+
*
|
|
53
|
+
* @param collectionPath - Absolute path of the collection this cache belongs to
|
|
54
|
+
*/
|
|
55
|
+
static getInstance(collectionPath: string): IndexCache;
|
|
56
|
+
/**
|
|
57
|
+
* Releases the shared IndexCache for a collection path (e.g. when the collection
|
|
58
|
+
* itself is deleted), stopping its cleanup timer and dropping it from the registry.
|
|
59
|
+
*
|
|
60
|
+
* @param collectionPath - Absolute path of the collection whose cache should be released
|
|
61
|
+
*/
|
|
62
|
+
static releaseInstance(collectionPath: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Stops the cleanup timer and clears cached state. Called via releaseInstance().
|
|
65
|
+
*/
|
|
66
|
+
dispose(): void;
|
|
39
67
|
/**
|
|
40
68
|
* Generates a random TTL between 5-15 minutes
|
|
41
69
|
* Randomization prevents cache stampede (thundering herd problem)
|
|
@@ -91,20 +119,19 @@ export declare class IndexCache {
|
|
|
91
119
|
*/
|
|
92
120
|
invalidateAll(): Promise<void>;
|
|
93
121
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
122
|
+
* Acquires a per-field mutex, queuing behind any in-flight holder for the same key.
|
|
123
|
+
*
|
|
124
|
+
* Implemented as a chained promise queue: each call captures the current tail of the
|
|
125
|
+
* chain, awaits it (so it truly blocks until every earlier holder has released), then
|
|
126
|
+
* appends its own pending promise as the new tail. The caller MUST invoke the returned
|
|
127
|
+
* release function exactly once (typically in a `finally` block) to hand the lock to
|
|
128
|
+
* the next queued waiter.
|
|
96
129
|
*
|
|
97
130
|
* @param key - The lock key (typically field name)
|
|
131
|
+
* @returns A release function that unblocks the next waiter for this key
|
|
98
132
|
* @private
|
|
99
133
|
*/
|
|
100
134
|
private acquireLock;
|
|
101
|
-
/**
|
|
102
|
-
* Releases the lock for a specific key
|
|
103
|
-
*
|
|
104
|
-
* @param key - The lock key to release
|
|
105
|
-
* @private
|
|
106
|
-
*/
|
|
107
|
-
private releaseLock;
|
|
108
135
|
/**
|
|
109
136
|
* Gets current cache statistics for monitoring
|
|
110
137
|
*
|
|
@@ -30,7 +30,7 @@ const Converter_helper_1 = __importDefault(require("../../Helper/Converter.helpe
|
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```typescript
|
|
33
|
-
* const indexCache =
|
|
33
|
+
* const indexCache = IndexCache.getInstance('/path/to/collection');
|
|
34
34
|
* await indexCache.loadAllIndexes(); // Eager load
|
|
35
35
|
* const indexData = await indexCache.getIndex('email'); // O(1) memory access
|
|
36
36
|
* ```
|
|
@@ -43,9 +43,49 @@ class IndexCache {
|
|
|
43
43
|
this.indexMetaPath = `${this.indexFolderPath}/index.meta.json`;
|
|
44
44
|
this.fileManager = new FileManager_1.default();
|
|
45
45
|
this.converter = new Converter_helper_1.default();
|
|
46
|
-
this.
|
|
46
|
+
this.lockChains = new Map();
|
|
47
47
|
this.startCleanupInterval();
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the shared IndexCache for a collection path, creating it on first use.
|
|
51
|
+
* All index services (Insert/Read/Delete/Collection) must go through this instead of
|
|
52
|
+
* constructing their own instance, otherwise locking and caching are per-call and
|
|
53
|
+
* provide no real coordination.
|
|
54
|
+
*
|
|
55
|
+
* @param collectionPath - Absolute path of the collection this cache belongs to
|
|
56
|
+
*/
|
|
57
|
+
static getInstance(collectionPath) {
|
|
58
|
+
let instance = IndexCache.instances.get(collectionPath);
|
|
59
|
+
if (!instance) {
|
|
60
|
+
instance = new IndexCache(collectionPath);
|
|
61
|
+
IndexCache.instances.set(collectionPath, instance);
|
|
62
|
+
}
|
|
63
|
+
return instance;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Releases the shared IndexCache for a collection path (e.g. when the collection
|
|
67
|
+
* itself is deleted), stopping its cleanup timer and dropping it from the registry.
|
|
68
|
+
*
|
|
69
|
+
* @param collectionPath - Absolute path of the collection whose cache should be released
|
|
70
|
+
*/
|
|
71
|
+
static releaseInstance(collectionPath) {
|
|
72
|
+
const instance = IndexCache.instances.get(collectionPath);
|
|
73
|
+
if (instance) {
|
|
74
|
+
instance.dispose();
|
|
75
|
+
IndexCache.instances.delete(collectionPath);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Stops the cleanup timer and clears cached state. Called via releaseInstance().
|
|
80
|
+
*/
|
|
81
|
+
dispose() {
|
|
82
|
+
if (this.cleanupInterval) {
|
|
83
|
+
clearInterval(this.cleanupInterval);
|
|
84
|
+
this.cleanupInterval = null;
|
|
85
|
+
}
|
|
86
|
+
this.cache.clear();
|
|
87
|
+
this.lockChains.clear();
|
|
88
|
+
}
|
|
49
89
|
/**
|
|
50
90
|
* Generates a random TTL between 5-15 minutes
|
|
51
91
|
* Randomization prevents cache stampede (thundering herd problem)
|
|
@@ -193,7 +233,7 @@ class IndexCache {
|
|
|
193
233
|
updateIndex(fieldName, indexData) {
|
|
194
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
235
|
// Acquire lock for this field to prevent concurrent writes
|
|
196
|
-
yield this.acquireLock(fieldName);
|
|
236
|
+
const release = yield this.acquireLock(fieldName);
|
|
197
237
|
try {
|
|
198
238
|
const indexPath = `${this.indexFolderPath}/${fieldName}${Keys_1.General.DBMS_File_EXT}`;
|
|
199
239
|
// Write to disk first for durability (disk = source of truth)
|
|
@@ -211,7 +251,7 @@ class IndexCache {
|
|
|
211
251
|
return true;
|
|
212
252
|
}
|
|
213
253
|
finally {
|
|
214
|
-
|
|
254
|
+
release();
|
|
215
255
|
}
|
|
216
256
|
});
|
|
217
257
|
}
|
|
@@ -237,35 +277,31 @@ class IndexCache {
|
|
|
237
277
|
});
|
|
238
278
|
}
|
|
239
279
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
280
|
+
* Acquires a per-field mutex, queuing behind any in-flight holder for the same key.
|
|
281
|
+
*
|
|
282
|
+
* Implemented as a chained promise queue: each call captures the current tail of the
|
|
283
|
+
* chain, awaits it (so it truly blocks until every earlier holder has released), then
|
|
284
|
+
* appends its own pending promise as the new tail. The caller MUST invoke the returned
|
|
285
|
+
* release function exactly once (typically in a `finally` block) to hand the lock to
|
|
286
|
+
* the next queued waiter.
|
|
242
287
|
*
|
|
243
288
|
* @param key - The lock key (typically field name)
|
|
289
|
+
* @returns A release function that unblocks the next waiter for this key
|
|
244
290
|
* @private
|
|
245
291
|
*/
|
|
246
292
|
acquireLock(key) {
|
|
247
293
|
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
let releaseFn;
|
|
254
|
-
const lockPromise = new Promise((resolve) => {
|
|
255
|
-
releaseFn = resolve;
|
|
294
|
+
var _a;
|
|
295
|
+
const previousTail = (_a = this.lockChains.get(key)) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
296
|
+
let release;
|
|
297
|
+
const currentLock = new Promise((resolve) => {
|
|
298
|
+
release = resolve;
|
|
256
299
|
});
|
|
257
|
-
this.
|
|
300
|
+
this.lockChains.set(key, previousTail.then(() => currentLock));
|
|
301
|
+
yield previousTail;
|
|
302
|
+
return release;
|
|
258
303
|
});
|
|
259
304
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Releases the lock for a specific key
|
|
262
|
-
*
|
|
263
|
-
* @param key - The lock key to release
|
|
264
|
-
* @private
|
|
265
|
-
*/
|
|
266
|
-
releaseLock(key) {
|
|
267
|
-
this.locks.delete(key);
|
|
268
|
-
}
|
|
269
305
|
/**
|
|
270
306
|
* Gets current cache statistics for monitoring
|
|
271
307
|
*
|
|
@@ -279,6 +315,10 @@ class IndexCache {
|
|
|
279
315
|
}
|
|
280
316
|
}
|
|
281
317
|
exports.IndexCache = IndexCache;
|
|
318
|
+
// One IndexCache per collection path - shared across Insert/Read/Delete/Collection
|
|
319
|
+
// so the lock and the memory cache actually serialize/coordinate across operations
|
|
320
|
+
// instead of each call site racing on its own private state.
|
|
321
|
+
IndexCache.instances = new Map();
|
|
282
322
|
// TTL constants (5-15 minutes in milliseconds)
|
|
283
323
|
IndexCache.MIN_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
284
324
|
IndexCache.MAX_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexCache.service.js","sourceRoot":"","sources":["../../../source/Services/Index/IndexCache.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,uDAAuD;AACvD,iDAAiD;AACjD,sFAA8D;AAC9D,qFAAsD;
|
|
1
|
+
{"version":3,"file":"IndexCache.service.js","sourceRoot":"","sources":["../../../source/Services/Index/IndexCache.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,uDAAuD;AACvD,iDAAiD;AACjD,sFAA8D;AAC9D,qFAAsD;AA2BtD;;;;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AAI,AAAZ,CAAa,CAAC,uBAAuB"}
|
|
@@ -8,15 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
16
|
const Keys_1 = require("../../config/Keys/Keys");
|
|
14
17
|
const Index_service_1 = require("./Index.service");
|
|
15
18
|
const IndexCache_service_1 = require("./IndexCache.service");
|
|
19
|
+
const SortedIndexValues_helper_1 = __importDefault(require("../../Helper/SortedIndexValues.helper"));
|
|
16
20
|
class InsertIndex extends Index_service_1.IndexManager {
|
|
17
21
|
constructor(path) {
|
|
18
22
|
super(path);
|
|
19
|
-
this.indexCache =
|
|
23
|
+
this.indexCache = IndexCache_service_1.IndexCache.getInstance(path);
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Inserts a document identifier into one or more index files as defined by the global index meta.
|
|
@@ -75,6 +79,10 @@ class InsertIndex extends Index_service_1.IndexManager {
|
|
|
75
79
|
continue;
|
|
76
80
|
}
|
|
77
81
|
const fieldValue = document[indexName];
|
|
82
|
+
// Lazily backfill sortedValues for indexes written before range support existed
|
|
83
|
+
if (!indexData.sortedValues) {
|
|
84
|
+
indexData.sortedValues = SortedIndexValues_helper_1.default.backfillFromKeys(Object.keys(indexData.indexEntries));
|
|
85
|
+
}
|
|
78
86
|
// Add document to index entries
|
|
79
87
|
const alreadyhave = Object.keys(indexData.indexEntries).some(keys => keys == fieldValue);
|
|
80
88
|
if (alreadyhave) {
|
|
@@ -82,6 +90,10 @@ class InsertIndex extends Index_service_1.IndexManager {
|
|
|
82
90
|
}
|
|
83
91
|
else {
|
|
84
92
|
indexData.indexEntries[fieldValue] = [documentFileName];
|
|
93
|
+
const numericValue = Number(fieldValue);
|
|
94
|
+
if (!Number.isNaN(numericValue)) {
|
|
95
|
+
SortedIndexValues_helper_1.default.insertSorted(indexData.sortedValues, numericValue);
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
98
|
// Update both memory cache and disk atomically
|
|
87
99
|
const updateSuccess = yield this.indexCache.updateIndex(indexName, indexData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InsertIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/InsertIndex.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InsertIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/InsertIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,iDAAiD;AACjD,mDAA+C;AAC/C,6DAAkD;AAClD,qGAAsE;AAEtE,iBAAiC,SAAQ,4BAAY;IAGnD,YAAa,IAAY;QACvB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,+BAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BC;IACY,aAAa,CAAC,QAAa;;YACpC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAEhE,IAAI,YAAY,EAAC,CAAC;gBAElB,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;oBAC7B,OAAO,KAAK,CAAC;gBACf,CAAC;gBAED,IAAI,MAAM,GAAY,KAAK,CAAC;gBAC5B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;oBACnC,MAAM,SAAS,GAAW,OAAO,CAAC,cAAc,CAAC;oBACjD,MAAM,gBAAgB,GAAG,GAAG,QAAQ,CAAC,UAAU,GAAG,cAAO,CAAC,aAAa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IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;4BAChC,kCAAiB,CAAC,YAAY,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;wBACvE,CAAC;oBACH,CAAC;oBAED,+CAA+C;oBAC/C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;oBAC9E,MAAM,GAAG,aAAa,CAAC;gBACzB,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;CAEF"}
|
|
@@ -70,6 +70,37 @@ export declare class ReadIndex extends IndexManager {
|
|
|
70
70
|
* const files = await readIndex.getFilesForPrefixQuery('name', 'John', true);
|
|
71
71
|
*/
|
|
72
72
|
getFilesForPrefixQuery(fieldName: string, prefix: string, caseInsensitive?: boolean): Promise<string[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve file paths from an index for documents whose field value falls within
|
|
75
|
+
* a numeric range ($gt/$gte/$lt/$lte).
|
|
76
|
+
*
|
|
77
|
+
* OPTIMIZED: Binary-searches the index's sorted value array for the matching bounds,
|
|
78
|
+
* then unions only the file lists for values inside that range - avoids the full
|
|
79
|
+
* collection scan that unindexed range queries require.
|
|
80
|
+
*
|
|
81
|
+
* @param fieldName - The field name to query (must have an index)
|
|
82
|
+
* @param range - Range operators to apply, e.g. `{ $gt: 25 }` or `{ $gte: 18, $lte: 65 }`
|
|
83
|
+
*
|
|
84
|
+
* @returns Promise resolving to an array of unique file paths matching the range,
|
|
85
|
+
* or an empty array if the field has no index, the index predates range
|
|
86
|
+
* support (not yet backfilled), or no values fall in range.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* - O(log U) to find the bounds + O(K) to union file lists, where U = unique indexed
|
|
90
|
+
* values and K = unique values within the range - independent of collection size.
|
|
91
|
+
* - Only numeric values participate (matches `Searcher.matchesQuery`, which already
|
|
92
|
+
* rejects range comparisons against non-numbers).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // For query: { age: { $gt: 25 } }
|
|
96
|
+
* const files = await readIndex.getFilesForRangeOperator('age', { $gt: 25 });
|
|
97
|
+
*/
|
|
98
|
+
getFilesForRangeOperator(fieldName: string, range: {
|
|
99
|
+
$gt?: number;
|
|
100
|
+
$gte?: number;
|
|
101
|
+
$lt?: number;
|
|
102
|
+
$lte?: number;
|
|
103
|
+
}): Promise<string[]>;
|
|
73
104
|
/**
|
|
74
105
|
* Finds index metadata entries that correspond to properties present on the provided document.
|
|
75
106
|
*
|
|
@@ -8,15 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.ReadIndex = void 0;
|
|
13
16
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
17
|
const Index_service_1 = require("./Index.service");
|
|
15
18
|
const IndexCache_service_1 = require("./IndexCache.service");
|
|
19
|
+
const SortedIndexValues_helper_1 = __importDefault(require("../../Helper/SortedIndexValues.helper"));
|
|
16
20
|
class ReadIndex extends Index_service_1.IndexManager {
|
|
17
21
|
constructor(path) {
|
|
18
22
|
super(path);
|
|
19
|
-
this.indexCache =
|
|
23
|
+
this.indexCache = IndexCache_service_1.IndexCache.getInstance(path);
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Retrieve file path(s) from an index that match the provided query.
|
|
@@ -147,6 +151,51 @@ class ReadIndex extends Index_service_1.IndexManager {
|
|
|
147
151
|
return Array.from(fileSet);
|
|
148
152
|
});
|
|
149
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Retrieve file paths from an index for documents whose field value falls within
|
|
156
|
+
* a numeric range ($gt/$gte/$lt/$lte).
|
|
157
|
+
*
|
|
158
|
+
* OPTIMIZED: Binary-searches the index's sorted value array for the matching bounds,
|
|
159
|
+
* then unions only the file lists for values inside that range - avoids the full
|
|
160
|
+
* collection scan that unindexed range queries require.
|
|
161
|
+
*
|
|
162
|
+
* @param fieldName - The field name to query (must have an index)
|
|
163
|
+
* @param range - Range operators to apply, e.g. `{ $gt: 25 }` or `{ $gte: 18, $lte: 65 }`
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to an array of unique file paths matching the range,
|
|
166
|
+
* or an empty array if the field has no index, the index predates range
|
|
167
|
+
* support (not yet backfilled), or no values fall in range.
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* - O(log U) to find the bounds + O(K) to union file lists, where U = unique indexed
|
|
171
|
+
* values and K = unique values within the range - independent of collection size.
|
|
172
|
+
* - Only numeric values participate (matches `Searcher.matchesQuery`, which already
|
|
173
|
+
* rejects range comparisons against non-numbers).
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // For query: { age: { $gt: 25 } }
|
|
177
|
+
* const files = await readIndex.getFilesForRangeOperator('age', { $gt: 25 });
|
|
178
|
+
*/
|
|
179
|
+
getFilesForRangeOperator(fieldName, range) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const indexData = yield this.indexCache.getIndex(fieldName);
|
|
182
|
+
if (!indexData || !indexData.sortedValues || indexData.sortedValues.length === 0) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
const bounds = SortedIndexValues_helper_1.default.resolveRange(indexData.sortedValues, range);
|
|
186
|
+
if (!bounds) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
const fileSet = new Set();
|
|
190
|
+
for (let i = bounds.startIndex; i <= bounds.endIndex; i++) {
|
|
191
|
+
const files = indexData.indexEntries[indexData.sortedValues[i]];
|
|
192
|
+
if (files) {
|
|
193
|
+
files.forEach(f => fileSet.add(f));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return Array.from(fileSet);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
150
199
|
/**
|
|
151
200
|
* Finds index metadata entries that correspond to properties present on the provided document.
|
|
152
201
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/ReadIndex.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReadIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/ReadIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,mDAA+C;AAC/C,6DAAkD;AAClD,qGAAsE;AAEtE,eAAuB,SAAQ,4BAAY;IAGzC,YAAa,IAAY;QACvB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,+BAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,gBAAgB,CAAE,KAAU;;YACvC,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;YACjE,IAAG,gBAAgB,KAAK,SAAS,EAAE,CAAC;gBAClC,oEAAoE;gBACpE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;gBAElF,IAAI,SAAS,EAAE,CAAC;oBACd,2CAA2C;oBAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;oBAE9C,gDAAgD;oBAChD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;wBAC1D,OAAO,EAAE,CAAC;oBACZ,C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@
|
|
|
1
1
|
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
|
|
2
2
|
import { LockInfo } from "../../config/Interfaces/Transaction/transaction.interface";
|
|
3
3
|
export default class LockManager {
|
|
4
|
+
private static instances;
|
|
4
5
|
private readonly collectionPath;
|
|
5
6
|
private readonly lockDir;
|
|
6
7
|
private readonly FileManager;
|
|
@@ -9,8 +10,12 @@ export default class LockManager {
|
|
|
9
10
|
private readonly ResponseHelper;
|
|
10
11
|
private readonly maxWaitTime;
|
|
11
12
|
private readonly pollInterval;
|
|
12
|
-
constructor(
|
|
13
|
+
private constructor();
|
|
14
|
+
/** Returns the shared LockManager for a collection path, creating it on first use. */
|
|
15
|
+
static getInstance(collectionPath: string): LockManager;
|
|
13
16
|
acquireLock(documentId: string, transactionId: string, transactionTimestamp: number): Promise<SuccessInterface | ErrorInterface>;
|
|
17
|
+
/** Builds the checksummed lock-file content; keeps format in sync with getLockOwner(). */
|
|
18
|
+
private buildLockContent;
|
|
14
19
|
releaseLock(documentId: string): Promise<SuccessInterface | ErrorInterface>;
|
|
15
20
|
releaseAllLocks(documentIds: string[]): Promise<void>;
|
|
16
21
|
isLocked(documentId: string): Promise<boolean>;
|
|
@@ -29,6 +29,15 @@ class LockManager {
|
|
|
29
29
|
this.Converter = new Converter_helper_1.default();
|
|
30
30
|
this.ResponseHelper = new response_helper_1.default();
|
|
31
31
|
}
|
|
32
|
+
/** Returns the shared LockManager for a collection path, creating it on first use. */
|
|
33
|
+
static getInstance(collectionPath) {
|
|
34
|
+
let instance = LockManager.instances.get(collectionPath);
|
|
35
|
+
if (!instance) {
|
|
36
|
+
instance = new LockManager(collectionPath);
|
|
37
|
+
LockManager.instances.set(collectionPath, instance);
|
|
38
|
+
}
|
|
39
|
+
return instance;
|
|
40
|
+
}
|
|
32
41
|
acquireLock(documentId, transactionId, transactionTimestamp) {
|
|
33
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
43
|
try {
|
|
@@ -37,36 +46,22 @@ class LockManager {
|
|
|
37
46
|
yield this.FolderManager.CreateDirectory(this.lockDir);
|
|
38
47
|
}
|
|
39
48
|
const lockFilePath = `${this.lockDir}/${documentId}.lock`;
|
|
49
|
+
const lockContent = this.buildLockContent(documentId, transactionId, transactionTimestamp);
|
|
40
50
|
const startTime = Date.now();
|
|
41
51
|
while (Date.now() - startTime < this.maxWaitTime) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
transactionId,
|
|
47
|
-
lockType: 'WRITE',
|
|
48
|
-
timestamp: transactionTimestamp,
|
|
49
|
-
};
|
|
50
|
-
const lockData = this.Converter.ToString(lockInfo);
|
|
51
|
-
const checksum = (0, crypto_1.createHash)('sha256').update(lockData).digest('hex');
|
|
52
|
-
const lockContent = this.Converter.ToString({ lockInfo, checksum });
|
|
53
|
-
const writeResult = yield this.FileManager.WriteFile(lockFilePath, lockContent);
|
|
54
|
-
if (writeResult.status) {
|
|
55
|
-
return this.ResponseHelper.Success({ message: "Lock acquired", documentId });
|
|
56
|
-
}
|
|
52
|
+
// Atomic acquire-if-free - avoids the FileExists-then-WriteFile race.
|
|
53
|
+
const acquired = yield this.FileManager.WriteFileExclusive(lockFilePath, lockContent);
|
|
54
|
+
if (acquired.status) {
|
|
55
|
+
return this.ResponseHelper.Success({ message: "Lock acquired", documentId });
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return this.ResponseHelper.Error(`Deadlock detected: Transaction ${transactionId} aborted (Wait-Die)`);
|
|
68
|
-
}
|
|
57
|
+
// Wait-Die: older transactions wait, younger ones abort.
|
|
58
|
+
const lockOwner = yield this.getLockOwner(documentId);
|
|
59
|
+
if (lockOwner) {
|
|
60
|
+
if (transactionTimestamp < lockOwner.timestamp) {
|
|
61
|
+
yield this.sleep(this.pollInterval);
|
|
62
|
+
continue;
|
|
69
63
|
}
|
|
64
|
+
return this.ResponseHelper.Error(`Deadlock detected: Transaction ${transactionId} aborted (Wait-Die)`);
|
|
70
65
|
}
|
|
71
66
|
yield this.sleep(this.pollInterval);
|
|
72
67
|
}
|
|
@@ -77,6 +72,19 @@ class LockManager {
|
|
|
77
72
|
}
|
|
78
73
|
});
|
|
79
74
|
}
|
|
75
|
+
/** Builds the checksummed lock-file content; keeps format in sync with getLockOwner(). */
|
|
76
|
+
buildLockContent(documentId, transactionId, transactionTimestamp) {
|
|
77
|
+
const lockInfo = {
|
|
78
|
+
documentId,
|
|
79
|
+
transactionId,
|
|
80
|
+
lockType: 'WRITE',
|
|
81
|
+
timestamp: transactionTimestamp,
|
|
82
|
+
};
|
|
83
|
+
const checksum = (0, crypto_1.createHash)('sha256')
|
|
84
|
+
.update(this.Converter.ToString(lockInfo))
|
|
85
|
+
.digest('hex');
|
|
86
|
+
return this.Converter.ToString({ lockInfo, checksum });
|
|
87
|
+
}
|
|
80
88
|
releaseLock(documentId) {
|
|
81
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
90
|
try {
|
|
@@ -147,5 +155,7 @@ class LockManager {
|
|
|
147
155
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
148
156
|
}
|
|
149
157
|
}
|
|
158
|
+
// One LockManager per collection path, shared across every caller.
|
|
159
|
+
LockManager.instances = new Map();
|
|
150
160
|
exports.default = LockManager;
|
|
151
161
|
//# sourceMappingURL=LockManager.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LockManager.service.js","sourceRoot":"","sources":["../../../source/Services/Transaction/LockManager.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,mCAAoC;AAMpC,sFAA8D;AAC9D,0FAAkE;AAClE,qFAAsD;AACtD,mFAA0D;AAE1D;
|
|
1
|
+
{"version":3,"file":"LockManager.service.js","sourceRoot":"","sources":["../../../source/Services/Trans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CAAC;oBACpC,OAAO,QAAoB,CAAC;gBAC9B,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAnKC,mEAAmE;AACpD,qBAAS,GAA6B,IAAI,GAAG,EAAE,AAAtC,CAAuC"}
|
|
@@ -8,14 +8,12 @@ import Transaction from "./Transaction.service";
|
|
|
8
8
|
export default class Session {
|
|
9
9
|
private readonly sessionId;
|
|
10
10
|
private readonly collectionPath;
|
|
11
|
-
private readonly isEncrypted;
|
|
12
|
-
private readonly encryptionKey?;
|
|
13
11
|
private readonly options;
|
|
14
12
|
private readonly ResponseHelper;
|
|
15
13
|
private readonly startTime;
|
|
16
14
|
private isActive;
|
|
17
15
|
private currentTransaction;
|
|
18
|
-
constructor(collectionPath: string,
|
|
16
|
+
constructor(collectionPath: string, options?: SessionOptions);
|
|
19
17
|
/**
|
|
20
18
|
* Gets the session ID
|
|
21
19
|
*/
|
|
@@ -21,14 +21,12 @@ const Transaction_service_1 = __importDefault(require("./Transaction.service"));
|
|
|
21
21
|
* Supports automatic retry, timeout handling, and the withTransaction pattern.
|
|
22
22
|
*/
|
|
23
23
|
class Session {
|
|
24
|
-
constructor(collectionPath,
|
|
24
|
+
constructor(collectionPath, options = {}) {
|
|
25
25
|
var _a, _b, _c;
|
|
26
26
|
this.isActive = true;
|
|
27
27
|
this.currentTransaction = null;
|
|
28
28
|
this.sessionId = new UniqueGenerator_helper_1.default(20).RandomWord(true);
|
|
29
29
|
this.collectionPath = collectionPath;
|
|
30
|
-
this.isEncrypted = isEncrypted;
|
|
31
|
-
this.encryptionKey = encryptionKey;
|
|
32
30
|
this.startTime = Date.now();
|
|
33
31
|
this.ResponseHelper = new response_helper_1.default();
|
|
34
32
|
// Default options
|
|
@@ -70,7 +68,7 @@ class Session {
|
|
|
70
68
|
if (this.currentTransaction) {
|
|
71
69
|
throw new Error("A transaction is already active in this session. Commit or rollback first.");
|
|
72
70
|
}
|
|
73
|
-
this.currentTransaction = new Transaction_service_1.default(this.collectionPath
|
|
71
|
+
this.currentTransaction = new Transaction_service_1.default(this.collectionPath);
|
|
74
72
|
return this.currentTransaction;
|
|
75
73
|
}
|
|
76
74
|
/**
|