dataply 0.0.16-alpha.4 → 0.0.16-alpha.6
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
|
@@ -5619,8 +5619,6 @@ var VirtualFileSystem = class {
|
|
|
5619
5619
|
}
|
|
5620
5620
|
/** Cache list (Page ID -> Data Buffer) */
|
|
5621
5621
|
cache;
|
|
5622
|
-
/** Page IDs that have changes and need disk synchronization */
|
|
5623
|
-
dirtyPages = /* @__PURE__ */ new Set();
|
|
5624
5622
|
/** Track logical file size */
|
|
5625
5623
|
fileSize;
|
|
5626
5624
|
/** Bit shift value for page size */
|
|
@@ -5645,11 +5643,9 @@ var VirtualFileSystem = class {
|
|
|
5645
5643
|
if (restoredPages.size === 0) {
|
|
5646
5644
|
return;
|
|
5647
5645
|
}
|
|
5646
|
+
const promises = [];
|
|
5648
5647
|
for (const [pageId, data] of restoredPages) {
|
|
5649
|
-
if (pageId > 1e6)
|
|
5650
|
-
console.warn(`[VFS] Ignoring suspicious PageID ${pageId} during recovery.`);
|
|
5651
|
-
continue;
|
|
5652
|
-
}
|
|
5648
|
+
if (pageId > 1e6) continue;
|
|
5653
5649
|
try {
|
|
5654
5650
|
const manager = new PageManagerFactory().getManager(data);
|
|
5655
5651
|
if (!manager.verifyChecksum(data)) {
|
|
@@ -5661,12 +5657,23 @@ var VirtualFileSystem = class {
|
|
|
5661
5657
|
continue;
|
|
5662
5658
|
}
|
|
5663
5659
|
this.cache.set(pageId, data);
|
|
5664
|
-
this.
|
|
5660
|
+
promises.push(this._writeAsync(
|
|
5661
|
+
this.fileHandle,
|
|
5662
|
+
data,
|
|
5663
|
+
0,
|
|
5664
|
+
this.pageSize,
|
|
5665
|
+
pageId * this.pageSize
|
|
5666
|
+
));
|
|
5665
5667
|
const endPos = (pageId + 1) * this.pageSize;
|
|
5666
5668
|
if (endPos > this.fileSize) {
|
|
5667
5669
|
this.fileSize = endPos;
|
|
5668
5670
|
}
|
|
5669
5671
|
}
|
|
5672
|
+
Promise.all(promises).then(() => {
|
|
5673
|
+
if (this.logManager && restoredPages.size > 0) {
|
|
5674
|
+
this.logManager.clear().catch(console.error);
|
|
5675
|
+
}
|
|
5676
|
+
});
|
|
5670
5677
|
}
|
|
5671
5678
|
/**
|
|
5672
5679
|
* Prepares the transaction for commit (Phase 1).
|
|
@@ -5674,17 +5681,10 @@ var VirtualFileSystem = class {
|
|
|
5674
5681
|
* @param tx Transaction
|
|
5675
5682
|
*/
|
|
5676
5683
|
async prepareCommit(tx) {
|
|
5677
|
-
const
|
|
5678
|
-
if (
|
|
5684
|
+
const dirtyPageMap = tx.__getDirtyPages();
|
|
5685
|
+
if (dirtyPageMap.size === 0) {
|
|
5679
5686
|
return;
|
|
5680
5687
|
}
|
|
5681
|
-
const dirtyPageMap = /* @__PURE__ */ new Map();
|
|
5682
|
-
for (const pageId of dirtyPages) {
|
|
5683
|
-
const page = this.cache.get(pageId);
|
|
5684
|
-
if (page) {
|
|
5685
|
-
dirtyPageMap.set(pageId, page);
|
|
5686
|
-
}
|
|
5687
|
-
}
|
|
5688
5688
|
if (this.logManager && dirtyPageMap.size > 0) {
|
|
5689
5689
|
await this.logManager.append(dirtyPageMap);
|
|
5690
5690
|
}
|
|
@@ -5695,18 +5695,18 @@ var VirtualFileSystem = class {
|
|
|
5695
5695
|
* @param tx Transaction
|
|
5696
5696
|
*/
|
|
5697
5697
|
async finalizeCommit(tx) {
|
|
5698
|
-
const
|
|
5699
|
-
if (
|
|
5698
|
+
const dirtyPageMap = tx.__getDirtyPages();
|
|
5699
|
+
if (dirtyPageMap.size === 0) {
|
|
5700
5700
|
this.cleanupTransaction(tx);
|
|
5701
5701
|
return;
|
|
5702
5702
|
}
|
|
5703
5703
|
if (this.logManager) {
|
|
5704
5704
|
await this.logManager.writeCommitMarker();
|
|
5705
5705
|
}
|
|
5706
|
-
const
|
|
5706
|
+
const sortedPageIds = Array.from(dirtyPageMap.keys()).sort((a, b) => a - b);
|
|
5707
5707
|
const promises = [];
|
|
5708
|
-
for (const pageId of
|
|
5709
|
-
const page =
|
|
5708
|
+
for (const pageId of sortedPageIds) {
|
|
5709
|
+
const page = dirtyPageMap.get(pageId);
|
|
5710
5710
|
if (page) {
|
|
5711
5711
|
promises.push(this._writeAsync(
|
|
5712
5712
|
this.fileHandle,
|
|
@@ -5714,7 +5714,10 @@ var VirtualFileSystem = class {
|
|
|
5714
5714
|
0,
|
|
5715
5715
|
this.pageSize,
|
|
5716
5716
|
pageId * this.pageSize
|
|
5717
|
-
))
|
|
5717
|
+
).then((v) => {
|
|
5718
|
+
this.cache.set(pageId, page);
|
|
5719
|
+
return v;
|
|
5720
|
+
}));
|
|
5718
5721
|
}
|
|
5719
5722
|
}
|
|
5720
5723
|
await Promise.all(promises);
|
|
@@ -5739,18 +5742,14 @@ var VirtualFileSystem = class {
|
|
|
5739
5742
|
* @param tx Transaction
|
|
5740
5743
|
*/
|
|
5741
5744
|
async rollback(tx) {
|
|
5742
|
-
const
|
|
5743
|
-
|
|
5744
|
-
const undoData = tx.__getUndoPage(pageId);
|
|
5745
|
-
if (undoData) {
|
|
5746
|
-
this.cache.set(pageId, undoData);
|
|
5747
|
-
}
|
|
5745
|
+
for (const [pageId, undoData] of tx.__getUndoPages()) {
|
|
5746
|
+
this.cache.set(pageId, undoData);
|
|
5748
5747
|
}
|
|
5749
5748
|
this.cleanupTransaction(tx);
|
|
5750
5749
|
}
|
|
5751
5750
|
cleanupTransaction(tx) {
|
|
5752
|
-
const
|
|
5753
|
-
for (const pageId of
|
|
5751
|
+
const pageIds = tx.__getDirtyPageIds();
|
|
5752
|
+
for (const pageId of pageIds) {
|
|
5754
5753
|
this.dirtyPageOwners.delete(pageId);
|
|
5755
5754
|
}
|
|
5756
5755
|
this.activeTransactions.delete(tx.id);
|
|
@@ -5807,6 +5806,10 @@ var VirtualFileSystem = class {
|
|
|
5807
5806
|
});
|
|
5808
5807
|
}
|
|
5809
5808
|
async _readPage(pageIndex, tx) {
|
|
5809
|
+
const txDirtyPage = tx.__getDirtyPage(pageIndex);
|
|
5810
|
+
if (txDirtyPage) {
|
|
5811
|
+
return txDirtyPage;
|
|
5812
|
+
}
|
|
5810
5813
|
if (this.activeTransactions.size > 0) {
|
|
5811
5814
|
const ownerTx = this.dirtyPageOwners.get(pageIndex);
|
|
5812
5815
|
if (ownerTx) {
|
|
@@ -5899,7 +5902,7 @@ var VirtualFileSystem = class {
|
|
|
5899
5902
|
page.set(buffer.subarray(bufferOffset, bufferOffset + (writeEnd - writeStart)), writeStart);
|
|
5900
5903
|
bufferOffset += writeEnd - writeStart;
|
|
5901
5904
|
this.cache.set(pageIndex, page);
|
|
5902
|
-
tx.__addDirtyPage(pageIndex);
|
|
5905
|
+
tx.__addDirtyPage(pageIndex, page);
|
|
5903
5906
|
}
|
|
5904
5907
|
const endPosition = offset + buffer.length;
|
|
5905
5908
|
if (endPosition > this.fileSize) {
|
|
@@ -5907,33 +5910,10 @@ var VirtualFileSystem = class {
|
|
|
5907
5910
|
}
|
|
5908
5911
|
return buffer.length;
|
|
5909
5912
|
}
|
|
5910
|
-
/**
|
|
5911
|
-
* Synchronizes dirty pages to disk.
|
|
5912
|
-
*/
|
|
5913
|
-
async sync() {
|
|
5914
|
-
const promises = [];
|
|
5915
|
-
const sortedPages = Array.from(this.dirtyPages).sort((a, b) => a - b);
|
|
5916
|
-
for (const pageIndex of sortedPages) {
|
|
5917
|
-
const page = this.cache.get(pageIndex);
|
|
5918
|
-
if (page) {
|
|
5919
|
-
promises.push(this._writeAsync(
|
|
5920
|
-
this.fileHandle,
|
|
5921
|
-
page,
|
|
5922
|
-
0,
|
|
5923
|
-
this.pageSize,
|
|
5924
|
-
pageIndex * this.pageSize
|
|
5925
|
-
));
|
|
5926
|
-
}
|
|
5927
|
-
}
|
|
5928
|
-
await Promise.all(promises);
|
|
5929
|
-
this.dirtyPages.clear();
|
|
5930
|
-
}
|
|
5931
5913
|
/**
|
|
5932
5914
|
* Closes the file.
|
|
5933
5915
|
*/
|
|
5934
5916
|
async close() {
|
|
5935
|
-
await this.sync();
|
|
5936
|
-
this.dirtyPages.clear();
|
|
5937
5917
|
this.cache.clear();
|
|
5938
5918
|
if (this.logManager) {
|
|
5939
5919
|
this.logManager.close();
|
|
@@ -6937,8 +6917,8 @@ var Transaction = class {
|
|
|
6937
6917
|
pageLocks = /* @__PURE__ */ new Map();
|
|
6938
6918
|
/** Undo Logs: PageID -> Original Page Buffer (Snapshot) */
|
|
6939
6919
|
undoPages = /* @__PURE__ */ new Map();
|
|
6940
|
-
/** Dirty Pages modified by the transaction */
|
|
6941
|
-
dirtyPages = /* @__PURE__ */ new
|
|
6920
|
+
/** Dirty Pages modified by the transaction: PageID -> Modified Page Buffer */
|
|
6921
|
+
dirtyPages = /* @__PURE__ */ new Map();
|
|
6942
6922
|
/** BPTree Transaction instance */
|
|
6943
6923
|
bptreeTx;
|
|
6944
6924
|
/** Whether the BPTree transaction is dirty */
|
|
@@ -7007,6 +6987,14 @@ var Transaction = class {
|
|
|
7007
6987
|
__hasUndoPage(pageId) {
|
|
7008
6988
|
return this.undoPages.has(pageId);
|
|
7009
6989
|
}
|
|
6990
|
+
/**
|
|
6991
|
+
* Returns all Undo pages.
|
|
6992
|
+
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
6993
|
+
* @returns Map of PageID -> Undo Page Buffer
|
|
6994
|
+
*/
|
|
6995
|
+
__getUndoPages() {
|
|
6996
|
+
return this.undoPages;
|
|
6997
|
+
}
|
|
7010
6998
|
/**
|
|
7011
6999
|
* Acquires a write lock.
|
|
7012
7000
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
@@ -7054,15 +7042,31 @@ var Transaction = class {
|
|
|
7054
7042
|
this.releaseAllLocks();
|
|
7055
7043
|
}
|
|
7056
7044
|
/**
|
|
7057
|
-
* Adds a Dirty Page.
|
|
7045
|
+
* Adds or updates a Dirty Page with its buffer.
|
|
7058
7046
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
7059
7047
|
* @param pageId Page ID
|
|
7048
|
+
* @param buffer Modified page buffer
|
|
7049
|
+
*/
|
|
7050
|
+
__addDirtyPage(pageId, buffer) {
|
|
7051
|
+
this.dirtyPages.set(pageId, buffer);
|
|
7052
|
+
}
|
|
7053
|
+
/**
|
|
7054
|
+
* Returns a Dirty Page buffer if it exists in the current transaction.
|
|
7055
|
+
* @param pageId Page ID
|
|
7056
|
+
* @returns Modified page buffer or undefined
|
|
7057
|
+
*/
|
|
7058
|
+
__getDirtyPage(pageId) {
|
|
7059
|
+
return this.dirtyPages.get(pageId);
|
|
7060
|
+
}
|
|
7061
|
+
/**
|
|
7062
|
+
* Returns the list of Dirty Page IDs.
|
|
7063
|
+
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
7060
7064
|
*/
|
|
7061
|
-
|
|
7062
|
-
this.dirtyPages.
|
|
7065
|
+
__getDirtyPageIds() {
|
|
7066
|
+
return this.dirtyPages.keys();
|
|
7063
7067
|
}
|
|
7064
7068
|
/**
|
|
7065
|
-
* Returns the
|
|
7069
|
+
* Returns the map of Dirty Pages.
|
|
7066
7070
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
7067
7071
|
*/
|
|
7068
7072
|
__getDirtyPages() {
|
|
@@ -10,8 +10,6 @@ export declare class VirtualFileSystem {
|
|
|
10
10
|
protected pageCacheCapacity: number;
|
|
11
11
|
/** Cache list (Page ID -> Data Buffer) */
|
|
12
12
|
protected cache: LRUMap<number, Uint8Array>;
|
|
13
|
-
/** Page IDs that have changes and need disk synchronization */
|
|
14
|
-
protected dirtyPages: Set<number>;
|
|
15
13
|
/** Track logical file size */
|
|
16
14
|
protected fileSize: number;
|
|
17
15
|
/** Bit shift value for page size */
|
|
@@ -98,10 +96,6 @@ export declare class VirtualFileSystem {
|
|
|
98
96
|
* @returns Length of data written
|
|
99
97
|
*/
|
|
100
98
|
write(offset: number, buffer: Uint8Array, tx: Transaction): Promise<number>;
|
|
101
|
-
/**
|
|
102
|
-
* Synchronizes dirty pages to disk.
|
|
103
|
-
*/
|
|
104
|
-
sync(): Promise<void>;
|
|
105
99
|
/**
|
|
106
100
|
* Closes the file.
|
|
107
101
|
*/
|
|
@@ -18,7 +18,7 @@ export declare class Transaction {
|
|
|
18
18
|
private pageLocks;
|
|
19
19
|
/** Undo Logs: PageID -> Original Page Buffer (Snapshot) */
|
|
20
20
|
private undoPages;
|
|
21
|
-
/** Dirty Pages modified by the transaction */
|
|
21
|
+
/** Dirty Pages modified by the transaction: PageID -> Modified Page Buffer */
|
|
22
22
|
private dirtyPages;
|
|
23
23
|
/** BPTree Transaction instance */
|
|
24
24
|
private bptreeTx?;
|
|
@@ -78,6 +78,12 @@ export declare class Transaction {
|
|
|
78
78
|
* @returns True if the transaction has an Undo page for the given page ID
|
|
79
79
|
*/
|
|
80
80
|
__hasUndoPage(pageId: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Returns all Undo pages.
|
|
83
|
+
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
84
|
+
* @returns Map of PageID -> Undo Page Buffer
|
|
85
|
+
*/
|
|
86
|
+
__getUndoPages(): Map<number, Uint8Array>;
|
|
81
87
|
/**
|
|
82
88
|
* Acquires a write lock.
|
|
83
89
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
@@ -98,16 +104,28 @@ export declare class Transaction {
|
|
|
98
104
|
*/
|
|
99
105
|
rollback(cleanup?: boolean): Promise<void>;
|
|
100
106
|
/**
|
|
101
|
-
* Adds a Dirty Page.
|
|
107
|
+
* Adds or updates a Dirty Page with its buffer.
|
|
102
108
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
103
109
|
* @param pageId Page ID
|
|
110
|
+
* @param buffer Modified page buffer
|
|
111
|
+
*/
|
|
112
|
+
__addDirtyPage(pageId: number, buffer: Uint8Array): void;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a Dirty Page buffer if it exists in the current transaction.
|
|
115
|
+
* @param pageId Page ID
|
|
116
|
+
* @returns Modified page buffer or undefined
|
|
117
|
+
*/
|
|
118
|
+
__getDirtyPage(pageId: number): Uint8Array | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the list of Dirty Page IDs.
|
|
121
|
+
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
104
122
|
*/
|
|
105
|
-
|
|
123
|
+
__getDirtyPageIds(): IterableIterator<number>;
|
|
106
124
|
/**
|
|
107
|
-
* Returns the
|
|
125
|
+
* Returns the map of Dirty Pages.
|
|
108
126
|
* Does not call this method directly. It is called by the `VirtualFileSystem` instance.
|
|
109
127
|
*/
|
|
110
|
-
__getDirtyPages():
|
|
128
|
+
__getDirtyPages(): Map<number, Uint8Array>;
|
|
111
129
|
/**
|
|
112
130
|
* Releases all locks.
|
|
113
131
|
*/
|