dataply 0.0.22-alpha.3 → 0.0.22
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/dist/cjs/index.js
CHANGED
|
@@ -375,6 +375,30 @@ var MVCCTransaction = class {
|
|
|
375
375
|
deleted
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Checks for conflicts among multiple transactions.
|
|
380
|
+
* A conflict occurs if two or more transactions modify (write or delete) the same key.
|
|
381
|
+
* @param transactions Array of transactions to check.
|
|
382
|
+
* @returns An array of keys that are in conflict.
|
|
383
|
+
*/
|
|
384
|
+
static CheckConflicts(transactions) {
|
|
385
|
+
const modifiedKeys = /* @__PURE__ */ new Map();
|
|
386
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
387
|
+
for (const tx of transactions) {
|
|
388
|
+
const txModified = /* @__PURE__ */ new Set([
|
|
389
|
+
...tx.writeBuffer.keys(),
|
|
390
|
+
...tx.deleteBuffer
|
|
391
|
+
]);
|
|
392
|
+
for (const key of txModified) {
|
|
393
|
+
const count = modifiedKeys.get(key) ?? 0;
|
|
394
|
+
if (count > 0) {
|
|
395
|
+
conflicts.add(key);
|
|
396
|
+
}
|
|
397
|
+
modifiedKeys.set(key, count + 1);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return Array.from(conflicts);
|
|
401
|
+
}
|
|
378
402
|
/**
|
|
379
403
|
* Cleans up both deletedCache and versionIndex based on minActiveVersion.
|
|
380
404
|
* Root transactions call this after commit to reclaim memory.
|
|
@@ -1662,6 +1686,15 @@ var BPTreeTransaction = class _BPTreeTransaction {
|
|
|
1662
1686
|
}
|
|
1663
1687
|
return best;
|
|
1664
1688
|
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Checks for conflicts between multiple transactions.
|
|
1691
|
+
*
|
|
1692
|
+
* @param transactions Array of BPTreeTransaction instances to check
|
|
1693
|
+
* @returns An array of keys that are in conflict. Empty array if no conflicts.
|
|
1694
|
+
*/
|
|
1695
|
+
static CheckConflicts(transactions) {
|
|
1696
|
+
return MVCCTransaction.CheckConflicts(transactions.map((tx) => tx.mvcc));
|
|
1697
|
+
}
|
|
1665
1698
|
/**
|
|
1666
1699
|
* Returns the ID of the root node.
|
|
1667
1700
|
* @returns The root node ID.
|
|
@@ -2112,11 +2145,7 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2112
2145
|
const { root, order } = head;
|
|
2113
2146
|
this.strategy.head = head;
|
|
2114
2147
|
this.order = order;
|
|
2115
|
-
this.
|
|
2116
|
-
root,
|
|
2117
|
-
order: this.order,
|
|
2118
|
-
data: this.strategy.head.data
|
|
2119
|
-
});
|
|
2148
|
+
this.rootId = root;
|
|
2120
2149
|
}
|
|
2121
2150
|
if (this.order < 3) {
|
|
2122
2151
|
throw new Error(`The 'order' parameter must be greater than 2. but got a '${this.order}'.`);
|
|
@@ -2442,6 +2471,12 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2442
2471
|
return node;
|
|
2443
2472
|
}
|
|
2444
2473
|
delete(key, value) {
|
|
2474
|
+
if (value === void 0) {
|
|
2475
|
+
value = this.get(key);
|
|
2476
|
+
}
|
|
2477
|
+
if (value === void 0) {
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2445
2480
|
let node = this.insertableNodeByPrimary(value);
|
|
2446
2481
|
let found = false;
|
|
2447
2482
|
while (true) {
|
|
@@ -2885,14 +2920,6 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
2885
2920
|
next,
|
|
2886
2921
|
prev
|
|
2887
2922
|
};
|
|
2888
|
-
const head = await this._readHead();
|
|
2889
|
-
if (head) {
|
|
2890
|
-
await this._writeHead({
|
|
2891
|
-
root: head.root,
|
|
2892
|
-
order: head.order,
|
|
2893
|
-
data: this.strategy.head.data
|
|
2894
|
-
});
|
|
2895
|
-
}
|
|
2896
2923
|
await this.mvcc.create(id, node);
|
|
2897
2924
|
return node;
|
|
2898
2925
|
}
|
|
@@ -3185,11 +3212,7 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3185
3212
|
const { root, order } = head;
|
|
3186
3213
|
this.strategy.head = head;
|
|
3187
3214
|
this.order = order;
|
|
3188
|
-
|
|
3189
|
-
root,
|
|
3190
|
-
order: this.order,
|
|
3191
|
-
data: this.strategy.head.data
|
|
3192
|
-
});
|
|
3215
|
+
this.rootId = root;
|
|
3193
3216
|
}
|
|
3194
3217
|
if (this.order < 3) {
|
|
3195
3218
|
throw new Error(`The 'order' parameter must be greater than 2. but got a '${this.order}'.`);
|
|
@@ -3518,6 +3541,12 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3518
3541
|
}
|
|
3519
3542
|
async delete(key, value) {
|
|
3520
3543
|
return this.writeLock(0, async () => {
|
|
3544
|
+
if (value === void 0) {
|
|
3545
|
+
value = await this.get(key);
|
|
3546
|
+
}
|
|
3547
|
+
if (value === void 0) {
|
|
3548
|
+
return;
|
|
3549
|
+
}
|
|
3521
3550
|
let node = await this.insertableNodeByPrimary(value);
|
|
3522
3551
|
let found = false;
|
|
3523
3552
|
while (true) {
|
|
@@ -4759,6 +4788,30 @@ var MVCCTransaction2 = class {
|
|
|
4759
4788
|
deleted
|
|
4760
4789
|
};
|
|
4761
4790
|
}
|
|
4791
|
+
/**
|
|
4792
|
+
* Checks for conflicts among multiple transactions.
|
|
4793
|
+
* A conflict occurs if two or more transactions modify (write or delete) the same key.
|
|
4794
|
+
* @param transactions Array of transactions to check.
|
|
4795
|
+
* @returns An array of keys that are in conflict.
|
|
4796
|
+
*/
|
|
4797
|
+
static CheckConflicts(transactions) {
|
|
4798
|
+
const modifiedKeys = /* @__PURE__ */ new Map();
|
|
4799
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
4800
|
+
for (const tx of transactions) {
|
|
4801
|
+
const txModified = /* @__PURE__ */ new Set([
|
|
4802
|
+
...tx.writeBuffer.keys(),
|
|
4803
|
+
...tx.deleteBuffer
|
|
4804
|
+
]);
|
|
4805
|
+
for (const key of txModified) {
|
|
4806
|
+
const count = modifiedKeys.get(key) ?? 0;
|
|
4807
|
+
if (count > 0) {
|
|
4808
|
+
conflicts.add(key);
|
|
4809
|
+
}
|
|
4810
|
+
modifiedKeys.set(key, count + 1);
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
return Array.from(conflicts);
|
|
4814
|
+
}
|
|
4762
4815
|
/**
|
|
4763
4816
|
* Cleans up both deletedCache and versionIndex based on minActiveVersion.
|
|
4764
4817
|
* Root transactions call this after commit to reclaim memory.
|
|
@@ -7753,9 +7806,8 @@ var WALManager = class {
|
|
|
7753
7806
|
|
|
7754
7807
|
// src/core/PageMVCCStrategy.ts
|
|
7755
7808
|
var import_node_fs2 = __toESM(require("node:fs"));
|
|
7756
|
-
var PageMVCCStrategy = class
|
|
7809
|
+
var PageMVCCStrategy = class {
|
|
7757
7810
|
constructor(fileHandle, pageSize, cacheCapacity) {
|
|
7758
|
-
super();
|
|
7759
7811
|
this.fileHandle = fileHandle;
|
|
7760
7812
|
this.pageSize = pageSize;
|
|
7761
7813
|
this.cache = new LRUMap2(cacheCapacity);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncMVCCStrategy } from 'mvcc-api';
|
|
2
1
|
/**
|
|
3
2
|
* 페이지 수준 MVCC Strategy.
|
|
4
3
|
* mvcc-api의 AsyncMVCCStrategy를 상속하여 디스크 I/O를 담당합니다.
|
|
@@ -6,7 +5,7 @@ import { AsyncMVCCStrategy } from 'mvcc-api';
|
|
|
6
5
|
* 키: 페이지 ID (number)
|
|
7
6
|
* 값: 페이지 데이터 (Uint8Array)
|
|
8
7
|
*/
|
|
9
|
-
export declare class PageMVCCStrategy
|
|
8
|
+
export declare class PageMVCCStrategy {
|
|
10
9
|
private readonly fileHandle;
|
|
11
10
|
private readonly pageSize;
|
|
12
11
|
/** LRU 캐시 (페이지 ID -> 페이지 데이터) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataply",
|
|
3
|
-
"version": "0.0.22
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "A lightweight storage engine for Node.js with support for MVCC, WAL.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"cache-entanglement": "^1.7.1",
|
|
49
49
|
"hookall": "^2.2.0",
|
|
50
|
-
"mvcc-api": "^1.3.
|
|
50
|
+
"mvcc-api": "^1.3.4",
|
|
51
51
|
"ryoiki": "^1.2.0",
|
|
52
|
-
"serializable-bptree": "^8.1.
|
|
52
|
+
"serializable-bptree": "^8.1.7"
|
|
53
53
|
}
|
|
54
54
|
}
|