dataply 0.0.26-alpha.10 → 0.0.26-alpha.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.
package/dist/cjs/index.js
CHANGED
|
@@ -2191,13 +2191,7 @@ function insertOp(ops, ctx, key, value, comparator) {
|
|
|
2191
2191
|
}
|
|
2192
2192
|
function deleteEntry(ops, ctx, node, key, comparator) {
|
|
2193
2193
|
if (!node.leaf) {
|
|
2194
|
-
let keyIndex =
|
|
2195
|
-
for (let i = 0, len = node.keys.length; i < len; i++) {
|
|
2196
|
-
if (node.keys[i] === key) {
|
|
2197
|
-
keyIndex = i;
|
|
2198
|
-
break;
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2194
|
+
let keyIndex = node.keys.indexOf(key);
|
|
2201
2195
|
if (keyIndex !== -1) {
|
|
2202
2196
|
node = cloneNode(node);
|
|
2203
2197
|
node.keys.splice(keyIndex, 1);
|
|
@@ -2236,17 +2230,15 @@ function deleteEntry(ops, ctx, node, key, comparator) {
|
|
|
2236
2230
|
let nextNode = null;
|
|
2237
2231
|
let prevValue = null;
|
|
2238
2232
|
let postValue = null;
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
if (
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
postValue = parentNode.values[i];
|
|
2249
|
-
}
|
|
2233
|
+
let keyIndex = parentNode.keys.indexOf(node.id);
|
|
2234
|
+
if (keyIndex !== -1) {
|
|
2235
|
+
if (keyIndex > 0) {
|
|
2236
|
+
prevNode = ops.getNode(parentNode.keys[keyIndex - 1]);
|
|
2237
|
+
prevValue = parentNode.values[keyIndex - 1];
|
|
2238
|
+
}
|
|
2239
|
+
if (keyIndex < parentNode.keys.length - 1) {
|
|
2240
|
+
nextNode = ops.getNode(parentNode.keys[keyIndex + 1]);
|
|
2241
|
+
postValue = parentNode.values[keyIndex];
|
|
2250
2242
|
}
|
|
2251
2243
|
}
|
|
2252
2244
|
let siblingNode;
|
|
@@ -2279,7 +2271,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
|
|
|
2279
2271
|
siblingNode = node;
|
|
2280
2272
|
node = pTemp;
|
|
2281
2273
|
}
|
|
2282
|
-
siblingNode.keys.
|
|
2274
|
+
siblingNode.keys = siblingNode.keys.concat(node.keys);
|
|
2283
2275
|
if (!node.leaf) {
|
|
2284
2276
|
siblingNode.values.push(guess);
|
|
2285
2277
|
} else {
|
|
@@ -2290,7 +2282,7 @@ function deleteEntry(ops, ctx, node, key, comparator) {
|
|
|
2290
2282
|
ops.updateNode(n);
|
|
2291
2283
|
}
|
|
2292
2284
|
}
|
|
2293
|
-
siblingNode.values.
|
|
2285
|
+
siblingNode.values = siblingNode.values.concat(node.values);
|
|
2294
2286
|
if (!siblingNode.leaf) {
|
|
2295
2287
|
const keys = siblingNode.keys;
|
|
2296
2288
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
@@ -2338,8 +2330,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
|
|
|
2338
2330
|
if (!node.leaf) {
|
|
2339
2331
|
pointerP0 = siblingNode.keys.splice(0, 1)[0];
|
|
2340
2332
|
pointerK0 = siblingNode.values.splice(0, 1)[0];
|
|
2341
|
-
node.keys =
|
|
2342
|
-
node.values =
|
|
2333
|
+
node.keys = node.keys.concat(pointerP0);
|
|
2334
|
+
node.values = node.values.concat(guess);
|
|
2343
2335
|
parentNode = cloneNode(ops.getNode(node.parent));
|
|
2344
2336
|
const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
|
|
2345
2337
|
if (pointerIndex > 0) {
|
|
@@ -2349,8 +2341,8 @@ function deleteEntry(ops, ctx, node, key, comparator) {
|
|
|
2349
2341
|
} else {
|
|
2350
2342
|
pointerP0 = siblingNode.keys.splice(0, 1)[0];
|
|
2351
2343
|
pointerK0 = siblingNode.values.splice(0, 1)[0];
|
|
2352
|
-
node.keys =
|
|
2353
|
-
node.values =
|
|
2344
|
+
node.keys = node.keys.concat(pointerP0);
|
|
2345
|
+
node.values = node.values.concat(pointerK0);
|
|
2354
2346
|
parentNode = cloneNode(ops.getNode(node.parent));
|
|
2355
2347
|
const pointerIndex = parentNode.keys.indexOf(siblingNode.id);
|
|
2356
2348
|
if (pointerIndex > 0) {
|
|
@@ -4221,13 +4213,7 @@ async function insertOpAsync(ops, ctx, key, value, comparator) {
|
|
|
4221
4213
|
}
|
|
4222
4214
|
async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
4223
4215
|
if (!node.leaf) {
|
|
4224
|
-
let keyIndex =
|
|
4225
|
-
for (let i = 0, len = node.keys.length; i < len; i++) {
|
|
4226
|
-
if (node.keys[i] === key) {
|
|
4227
|
-
keyIndex = i;
|
|
4228
|
-
break;
|
|
4229
|
-
}
|
|
4230
|
-
}
|
|
4216
|
+
let keyIndex = node.keys.indexOf(key);
|
|
4231
4217
|
if (keyIndex !== -1) {
|
|
4232
4218
|
node = cloneNode(node);
|
|
4233
4219
|
node.keys.splice(keyIndex, 1);
|
|
@@ -4256,16 +4242,15 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
|
4256
4242
|
let nextNode = null;
|
|
4257
4243
|
let prevValue = null;
|
|
4258
4244
|
let postValue = null;
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
}
|
|
4245
|
+
let keyIndex = parentNode.keys.indexOf(node.id);
|
|
4246
|
+
if (keyIndex !== -1) {
|
|
4247
|
+
if (keyIndex > 0) {
|
|
4248
|
+
prevNode = await ops.getNode(parentNode.keys[keyIndex - 1]);
|
|
4249
|
+
prevValue = parentNode.values[keyIndex - 1];
|
|
4250
|
+
}
|
|
4251
|
+
if (keyIndex < parentNode.keys.length - 1) {
|
|
4252
|
+
nextNode = await ops.getNode(parentNode.keys[keyIndex + 1]);
|
|
4253
|
+
postValue = parentNode.values[keyIndex];
|
|
4269
4254
|
}
|
|
4270
4255
|
}
|
|
4271
4256
|
let siblingNode;
|
|
@@ -4292,11 +4277,11 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
|
4292
4277
|
siblingNode = cloneNode(siblingNode);
|
|
4293
4278
|
if (node.values.length + siblingNode.values.length < ctx.order) {
|
|
4294
4279
|
if (!isPredecessor) {
|
|
4295
|
-
const
|
|
4280
|
+
const pTemp = siblingNode;
|
|
4296
4281
|
siblingNode = node;
|
|
4297
|
-
node =
|
|
4282
|
+
node = pTemp;
|
|
4298
4283
|
}
|
|
4299
|
-
siblingNode.keys.
|
|
4284
|
+
siblingNode.keys = siblingNode.keys.concat(node.keys);
|
|
4300
4285
|
if (!node.leaf) {
|
|
4301
4286
|
siblingNode.values.push(guess);
|
|
4302
4287
|
} else {
|
|
@@ -4307,7 +4292,7 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
|
4307
4292
|
await ops.updateNode(n);
|
|
4308
4293
|
}
|
|
4309
4294
|
}
|
|
4310
|
-
siblingNode.values.
|
|
4295
|
+
siblingNode.values = siblingNode.values.concat(node.values);
|
|
4311
4296
|
if (!siblingNode.leaf) {
|
|
4312
4297
|
for (let i = 0, len = siblingNode.keys.length; i < len; i++) {
|
|
4313
4298
|
const n = cloneNode(await ops.getNode(siblingNode.keys[i]));
|
|
@@ -4351,8 +4336,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
|
4351
4336
|
if (!node.leaf) {
|
|
4352
4337
|
pointerP0 = siblingNode.keys.splice(0, 1)[0];
|
|
4353
4338
|
pointerK0 = siblingNode.values.splice(0, 1)[0];
|
|
4354
|
-
node.keys =
|
|
4355
|
-
node.values =
|
|
4339
|
+
node.keys = node.keys.concat(pointerP0);
|
|
4340
|
+
node.values = node.values.concat(guess);
|
|
4356
4341
|
parentNode = cloneNode(await ops.getNode(node.parent));
|
|
4357
4342
|
const pi = parentNode.keys.indexOf(siblingNode.id);
|
|
4358
4343
|
if (pi > 0) {
|
|
@@ -4362,8 +4347,8 @@ async function deleteEntryAsync(ops, ctx, node, key, comparator) {
|
|
|
4362
4347
|
} else {
|
|
4363
4348
|
pointerP0 = siblingNode.keys.splice(0, 1)[0];
|
|
4364
4349
|
pointerK0 = siblingNode.values.splice(0, 1)[0];
|
|
4365
|
-
node.keys =
|
|
4366
|
-
node.values =
|
|
4350
|
+
node.keys = node.keys.concat(pointerP0);
|
|
4351
|
+
node.values = node.values.concat(pointerK0);
|
|
4367
4352
|
parentNode = cloneNode(await ops.getNode(node.parent));
|
|
4368
4353
|
const pi = parentNode.keys.indexOf(siblingNode.id);
|
|
4369
4354
|
if (pi > 0) {
|
|
@@ -9916,7 +9901,7 @@ var PageFileSystem = class {
|
|
|
9916
9901
|
* @param tx Transaction
|
|
9917
9902
|
*/
|
|
9918
9903
|
async updateBitmap(pageId, isFree, tx) {
|
|
9919
|
-
const metadata = await this.getMetadata(tx);
|
|
9904
|
+
const metadata = await this.getMetadata(false, tx);
|
|
9920
9905
|
const metadataManager = this.pageFactory.getManager(metadata);
|
|
9921
9906
|
const bitmapPageId = metadataManager.getBitmapPageId(metadata);
|
|
9922
9907
|
const headerSize = PageManager.CONSTANT.SIZE_PAGE_HEADER;
|
|
@@ -9924,7 +9909,7 @@ var PageFileSystem = class {
|
|
|
9924
9909
|
let currentBitmapPageId = bitmapPageId;
|
|
9925
9910
|
let targetBitIndex = pageId;
|
|
9926
9911
|
while (targetBitIndex >= capacityPerBitmapPage) {
|
|
9927
|
-
const currentBitmapPage = await this.get(currentBitmapPageId, tx);
|
|
9912
|
+
const currentBitmapPage = await this.get(currentBitmapPageId, true, tx);
|
|
9928
9913
|
const manager = this.pageFactory.getManager(currentBitmapPage);
|
|
9929
9914
|
targetBitIndex -= capacityPerBitmapPage;
|
|
9930
9915
|
const nextPageId = manager.getNextPageId(currentBitmapPage);
|
|
@@ -9941,7 +9926,7 @@ var PageFileSystem = class {
|
|
|
9941
9926
|
}
|
|
9942
9927
|
}
|
|
9943
9928
|
await tx.__acquireWriteLock(currentBitmapPageId);
|
|
9944
|
-
const targetBitmapPage = await this.get(currentBitmapPageId, tx);
|
|
9929
|
+
const targetBitmapPage = await this.get(currentBitmapPageId, true, tx);
|
|
9945
9930
|
const bitmapManager = this.pageFactory.getManager(targetBitmapPage);
|
|
9946
9931
|
bitmapManager.setBit(targetBitmapPage, targetBitIndex, isFree);
|
|
9947
9932
|
await this.setPage(currentBitmapPageId, targetBitmapPage, tx);
|
|
@@ -9960,20 +9945,22 @@ var PageFileSystem = class {
|
|
|
9960
9945
|
}
|
|
9961
9946
|
/**
|
|
9962
9947
|
* @param pageIndex 페이지 인덱스
|
|
9948
|
+
* @param copy Copy-on-Read
|
|
9963
9949
|
* @param tx 트랜잭션
|
|
9964
9950
|
* @returns 페이지 버퍼
|
|
9965
9951
|
*/
|
|
9966
|
-
async get(pageIndex, tx) {
|
|
9967
|
-
return tx.__readPage(pageIndex);
|
|
9952
|
+
async get(pageIndex, copy, tx) {
|
|
9953
|
+
return tx.__readPage(pageIndex, copy);
|
|
9968
9954
|
}
|
|
9969
9955
|
/**
|
|
9970
9956
|
* Reads the page header.
|
|
9971
9957
|
* @param pageIndex Page index
|
|
9958
|
+
* @param copy Copy-on-Read
|
|
9972
9959
|
* @param tx Transaction
|
|
9973
9960
|
* @returns Page header buffer
|
|
9974
9961
|
*/
|
|
9975
|
-
async getHeader(pageIndex, tx) {
|
|
9976
|
-
const page = await this.get(pageIndex, tx);
|
|
9962
|
+
async getHeader(pageIndex, copy, tx) {
|
|
9963
|
+
const page = await this.get(pageIndex, copy, tx);
|
|
9977
9964
|
return page.subarray(0, PageManager.CONSTANT.SIZE_PAGE_HEADER);
|
|
9978
9965
|
}
|
|
9979
9966
|
/**
|
|
@@ -9984,7 +9971,7 @@ var PageFileSystem = class {
|
|
|
9984
9971
|
* @returns Page body buffer
|
|
9985
9972
|
*/
|
|
9986
9973
|
async getBody(pageIndex, recursive = false, tx) {
|
|
9987
|
-
const page = await this.get(pageIndex, tx);
|
|
9974
|
+
const page = await this.get(pageIndex, false, tx);
|
|
9988
9975
|
const manager = this.pageFactory.getManager(page);
|
|
9989
9976
|
const fullBody = manager.getBody(page);
|
|
9990
9977
|
if (!recursive) {
|
|
@@ -10002,11 +9989,12 @@ var PageFileSystem = class {
|
|
|
10002
9989
|
}
|
|
10003
9990
|
/**
|
|
10004
9991
|
* Returns the metadata page.
|
|
9992
|
+
* @param copy Copy-on-Read
|
|
10005
9993
|
* @param tx Transaction
|
|
10006
9994
|
* @returns Metadata page
|
|
10007
9995
|
*/
|
|
10008
|
-
async getMetadata(tx) {
|
|
10009
|
-
const page = await this.get(0, tx);
|
|
9996
|
+
async getMetadata(copy, tx) {
|
|
9997
|
+
const page = await this.get(0, copy, tx);
|
|
10010
9998
|
if (!MetadataPageManager.IsMetadataPage(page)) {
|
|
10011
9999
|
throw new Error("Invalid metadata page");
|
|
10012
10000
|
}
|
|
@@ -10018,20 +10006,21 @@ var PageFileSystem = class {
|
|
|
10018
10006
|
* @returns Number of pages
|
|
10019
10007
|
*/
|
|
10020
10008
|
async getPageCount(tx) {
|
|
10021
|
-
const metadata = await this.getMetadata(tx);
|
|
10009
|
+
const metadata = await this.getMetadata(false, tx);
|
|
10022
10010
|
const manager = this.pageFactory.getManager(metadata);
|
|
10023
10011
|
return manager.getPageCount(metadata);
|
|
10024
10012
|
}
|
|
10025
10013
|
/**
|
|
10026
10014
|
* Returns the root index page.
|
|
10015
|
+
* @param copy Copy-on-Read
|
|
10027
10016
|
* @param tx Transaction
|
|
10028
10017
|
* @returns Root index page
|
|
10029
10018
|
*/
|
|
10030
|
-
async getRootIndex(tx) {
|
|
10031
|
-
const metadata = await this.getMetadata(tx);
|
|
10019
|
+
async getRootIndex(copy, tx) {
|
|
10020
|
+
const metadata = await this.getMetadata(false, tx);
|
|
10032
10021
|
const manager = this.pageFactory.getManager(metadata);
|
|
10033
10022
|
const rootIndexPageId = manager.getRootIndexPageId(metadata);
|
|
10034
|
-
const rootIndexPage = await this.get(rootIndexPageId, tx);
|
|
10023
|
+
const rootIndexPage = await this.get(rootIndexPageId, copy, tx);
|
|
10035
10024
|
if (!IndexPageManager.IsIndexPage(rootIndexPage)) {
|
|
10036
10025
|
throw new Error("Invalid root index page");
|
|
10037
10026
|
}
|
|
@@ -10066,12 +10055,12 @@ var PageFileSystem = class {
|
|
|
10066
10055
|
async appendNewPage(pageType = PageManager.CONSTANT.PAGE_TYPE_EMPTY, tx) {
|
|
10067
10056
|
this.logger.debug(`Appending new page of type ${pageType}`);
|
|
10068
10057
|
await tx.__acquireWriteLock(0);
|
|
10069
|
-
const metadata = await this.getMetadata(tx);
|
|
10058
|
+
const metadata = await this.getMetadata(true, tx);
|
|
10070
10059
|
const metadataManager = this.pageFactory.getManager(metadata);
|
|
10071
10060
|
const freePageId = metadataManager.getFreePageId(metadata);
|
|
10072
10061
|
if (freePageId !== -1) {
|
|
10073
10062
|
const reusedPageId = freePageId;
|
|
10074
|
-
const reusedPage = await this.get(reusedPageId, tx);
|
|
10063
|
+
const reusedPage = await this.get(reusedPageId, false, tx);
|
|
10075
10064
|
const reusedPageManager = this.pageFactory.getManager(reusedPage);
|
|
10076
10065
|
const nextFreePageId = reusedPageManager.getNextPageId(reusedPage);
|
|
10077
10066
|
metadataManager.setFreePageId(metadata, nextFreePageId);
|
|
@@ -10116,7 +10105,7 @@ var PageFileSystem = class {
|
|
|
10116
10105
|
let currentOffset = offset;
|
|
10117
10106
|
let dataOffset = 0;
|
|
10118
10107
|
while (dataOffset < data.length) {
|
|
10119
|
-
const page = await this.get(currentPageId, tx);
|
|
10108
|
+
const page = await this.get(currentPageId, true, tx);
|
|
10120
10109
|
const manager = this.pageFactory.getManager(page);
|
|
10121
10110
|
const bodyStart = PageManager.CONSTANT.SIZE_PAGE_HEADER;
|
|
10122
10111
|
const bodySize = this.pageSize - bodyStart;
|
|
@@ -10176,7 +10165,7 @@ var PageFileSystem = class {
|
|
|
10176
10165
|
break;
|
|
10177
10166
|
}
|
|
10178
10167
|
visited.add(currentPageId);
|
|
10179
|
-
const page = await this.get(currentPageId, tx);
|
|
10168
|
+
const page = await this.get(currentPageId, false, tx);
|
|
10180
10169
|
const nextPageId = this.pageFactory.getManager(page).getNextPageId(page);
|
|
10181
10170
|
await this.setFreePage(currentPageId, tx);
|
|
10182
10171
|
currentPageId = nextPageId;
|
|
@@ -10192,7 +10181,7 @@ var PageFileSystem = class {
|
|
|
10192
10181
|
if (pageId <= 0) return;
|
|
10193
10182
|
await tx.__acquireWriteLock(0);
|
|
10194
10183
|
await tx.__acquireWriteLock(pageId);
|
|
10195
|
-
const metadata = await this.getMetadata(tx);
|
|
10184
|
+
const metadata = await this.getMetadata(true, tx);
|
|
10196
10185
|
const metadataManager = this.pageFactory.getManager(metadata);
|
|
10197
10186
|
const currentHeadFreePageId = metadataManager.getFreePageId(metadata);
|
|
10198
10187
|
const emptyPageManager = this.pageFactory.getManagerFromType(PageManager.CONSTANT.PAGE_TYPE_EMPTY);
|
|
@@ -10275,12 +10264,12 @@ var RowIdentifierStrategy = class extends SerializeStrategyAsync {
|
|
|
10275
10264
|
async id(isLeaf) {
|
|
10276
10265
|
const tx = this.txContext.get();
|
|
10277
10266
|
await tx.__acquireWriteLock(0);
|
|
10278
|
-
const metadata = await this.pfs.getMetadata(tx);
|
|
10267
|
+
const metadata = await this.pfs.getMetadata(true, tx);
|
|
10279
10268
|
const metadataManager = this.factory.getManager(metadata);
|
|
10280
10269
|
const freePageId = metadataManager.getFreePageId(metadata);
|
|
10281
10270
|
let pageId;
|
|
10282
10271
|
if (freePageId !== -1) {
|
|
10283
|
-
const freePage = await this.pfs.get(freePageId, tx);
|
|
10272
|
+
const freePage = await this.pfs.get(freePageId, false, tx);
|
|
10284
10273
|
const freePageManager = this.factory.getManager(freePage);
|
|
10285
10274
|
const nextFreePageId = freePageManager.getNextPageId(freePage);
|
|
10286
10275
|
metadataManager.setFreePageId(metadata, nextFreePageId);
|
|
@@ -10296,7 +10285,7 @@ var RowIdentifierStrategy = class extends SerializeStrategyAsync {
|
|
|
10296
10285
|
async read(id) {
|
|
10297
10286
|
const tx = this.txContext.get();
|
|
10298
10287
|
const pageId = +id;
|
|
10299
|
-
const page = await this.pfs.get(pageId, tx);
|
|
10288
|
+
const page = await this.pfs.get(pageId, false, tx);
|
|
10300
10289
|
if (!IndexPageManager.IsIndexPage(page)) {
|
|
10301
10290
|
throw new Error(`Node ${id} does not exist - not a valid index page`);
|
|
10302
10291
|
}
|
|
@@ -10331,7 +10320,7 @@ var RowIdentifierStrategy = class extends SerializeStrategyAsync {
|
|
|
10331
10320
|
async write(id, node) {
|
|
10332
10321
|
const tx = this.txContext.get();
|
|
10333
10322
|
const pageId = +id;
|
|
10334
|
-
let page = await this.pfs.get(pageId, tx);
|
|
10323
|
+
let page = await this.pfs.get(pageId, true, tx);
|
|
10335
10324
|
if (!IndexPageManager.IsIndexPage(page)) {
|
|
10336
10325
|
page = this.indexPageManger.create(this.pfs.pageSize, pageId);
|
|
10337
10326
|
}
|
|
@@ -10379,7 +10368,7 @@ var RowIdentifierStrategy = class extends SerializeStrategyAsync {
|
|
|
10379
10368
|
}
|
|
10380
10369
|
async readHead() {
|
|
10381
10370
|
const tx = this.txContext.get();
|
|
10382
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10371
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10383
10372
|
const manager = this.factory.getManager(metadataPage);
|
|
10384
10373
|
const rootIndexPageId = manager.getRootIndexPageId(metadataPage);
|
|
10385
10374
|
if (rootIndexPageId === -1) {
|
|
@@ -10399,7 +10388,7 @@ var RowIdentifierStrategy = class extends SerializeStrategyAsync {
|
|
|
10399
10388
|
if (root === null) {
|
|
10400
10389
|
throw new Error("");
|
|
10401
10390
|
}
|
|
10402
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10391
|
+
const metadataPage = await this.pfs.getMetadata(true, tx);
|
|
10403
10392
|
const manager = this.factory.getManager(metadataPage);
|
|
10404
10393
|
manager.setRootIndexPageId(metadataPage, +root);
|
|
10405
10394
|
manager.setRootIndexOrder(metadataPage, order);
|
|
@@ -10560,7 +10549,7 @@ var RowTableEngine = class {
|
|
|
10560
10549
|
if (!this.initialized) {
|
|
10561
10550
|
throw new Error("RowTableEngine instance is not initialized");
|
|
10562
10551
|
}
|
|
10563
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10552
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10564
10553
|
const manager = this.factory.getManagerFromType(MetadataPageManager.CONSTANT.PAGE_TYPE_METADATA);
|
|
10565
10554
|
const pageSize = manager.getPageSize(metadataPage);
|
|
10566
10555
|
const pageCount = manager.getPageCount(metadataPage);
|
|
@@ -10588,10 +10577,10 @@ var RowTableEngine = class {
|
|
|
10588
10577
|
}
|
|
10589
10578
|
await tx.__acquireWriteLock(0);
|
|
10590
10579
|
const pks = [];
|
|
10591
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10580
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10592
10581
|
let lastPk = this.metadataPageManager.getLastRowPk(metadataPage);
|
|
10593
10582
|
let lastInsertDataPageId = this.metadataPageManager.getLastInsertPageId(metadataPage);
|
|
10594
|
-
let lastInsertDataPage = await this.pfs.get(lastInsertDataPageId, tx);
|
|
10583
|
+
let lastInsertDataPage = await this.pfs.get(lastInsertDataPageId, true, tx);
|
|
10595
10584
|
if (!this.factory.isDataPage(lastInsertDataPage)) {
|
|
10596
10585
|
throw new Error(`Last insert page is not data page`);
|
|
10597
10586
|
}
|
|
@@ -10613,7 +10602,7 @@ var RowTableEngine = class {
|
|
|
10613
10602
|
await this.pfs.setPage(lastInsertDataPageId, lastInsertDataPage, tx);
|
|
10614
10603
|
} else {
|
|
10615
10604
|
const newPageId = await this.pfs.appendNewPage(this.dataPageManager.pageType, tx);
|
|
10616
|
-
const newPage = await this.pfs.get(newPageId, tx);
|
|
10605
|
+
const newPage = await this.pfs.get(newPageId, true, tx);
|
|
10617
10606
|
this.dataPageManager.insert(newPage, row);
|
|
10618
10607
|
this.setRID(newPageId, 0);
|
|
10619
10608
|
lastInsertDataPageId = newPageId;
|
|
@@ -10628,7 +10617,7 @@ var RowTableEngine = class {
|
|
|
10628
10617
|
this.rowManager.setBody(row, data);
|
|
10629
10618
|
if (slotIndex === -1) {
|
|
10630
10619
|
const newPageId = await this.pfs.appendNewPage(this.dataPageManager.pageType, tx);
|
|
10631
|
-
const newPage = await this.pfs.get(newPageId, tx);
|
|
10620
|
+
const newPage = await this.pfs.get(newPageId, true, tx);
|
|
10632
10621
|
this.dataPageManager.insert(newPage, row);
|
|
10633
10622
|
this.setRID(newPageId, 0);
|
|
10634
10623
|
lastInsertDataPageId = newPageId;
|
|
@@ -10644,7 +10633,7 @@ var RowTableEngine = class {
|
|
|
10644
10633
|
pks.push(pk);
|
|
10645
10634
|
}
|
|
10646
10635
|
await this.bptree.batchInsert(batchInsertData);
|
|
10647
|
-
const freshMetadataPage = await this.pfs.getMetadata(tx);
|
|
10636
|
+
const freshMetadataPage = await this.pfs.getMetadata(true, tx);
|
|
10648
10637
|
this.metadataPageManager.setLastInsertPageId(freshMetadataPage, lastInsertDataPageId);
|
|
10649
10638
|
this.metadataPageManager.setLastRowPk(freshMetadataPage, lastPk);
|
|
10650
10639
|
if (incrementRowCount) {
|
|
@@ -10690,7 +10679,7 @@ var RowTableEngine = class {
|
|
|
10690
10679
|
this.keyManager.setBufferFromKey(rid, this.ridBuffer);
|
|
10691
10680
|
const pageId = this.keyManager.getPageId(this.ridBuffer);
|
|
10692
10681
|
const slotIndex = this.keyManager.getSlotIndex(this.ridBuffer);
|
|
10693
|
-
const page = await this.pfs.get(pageId, tx);
|
|
10682
|
+
const page = await this.pfs.get(pageId, true, tx);
|
|
10694
10683
|
if (!this.factory.isDataPage(page)) {
|
|
10695
10684
|
throw new Error(`RID not found for PK: ${pk}`);
|
|
10696
10685
|
}
|
|
@@ -10726,22 +10715,22 @@ var RowTableEngine = class {
|
|
|
10726
10715
|
this.rowManager.setBodySize(newRow, newBodySize);
|
|
10727
10716
|
this.rowManager.setBody(newRow, data);
|
|
10728
10717
|
await tx.__acquireWriteLock(0);
|
|
10729
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10718
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10730
10719
|
let lastInsertDataPageId = this.metadataPageManager.getLastInsertPageId(metadataPage);
|
|
10731
|
-
let lastInsertDataPage = await this.pfs.get(lastInsertDataPageId, tx);
|
|
10720
|
+
let lastInsertDataPage = await this.pfs.get(lastInsertDataPageId, true, tx);
|
|
10732
10721
|
if (!this.factory.isDataPage(lastInsertDataPage)) {
|
|
10733
10722
|
throw new Error("Last insert page is not data page");
|
|
10734
10723
|
}
|
|
10735
10724
|
let newSlotIndex = this.dataPageManager.getNextSlotIndex(lastInsertDataPage, newRow);
|
|
10736
10725
|
if (newSlotIndex === -1) {
|
|
10737
10726
|
const newPageId = await this.pfs.appendNewPage(this.dataPageManager.pageType, tx);
|
|
10738
|
-
lastInsertDataPage = await this.pfs.get(newPageId, tx);
|
|
10727
|
+
lastInsertDataPage = await this.pfs.get(newPageId, true, tx);
|
|
10739
10728
|
lastInsertDataPageId = newPageId;
|
|
10740
10729
|
newSlotIndex = 0;
|
|
10741
10730
|
}
|
|
10742
10731
|
this.dataPageManager.insert(lastInsertDataPage, newRow);
|
|
10743
10732
|
await this.pfs.setPage(lastInsertDataPageId, lastInsertDataPage, tx);
|
|
10744
|
-
const targetPage = await this.pfs.get(pageId, tx);
|
|
10733
|
+
const targetPage = await this.pfs.get(pageId, true, tx);
|
|
10745
10734
|
if (!this.factory.isDataPage(targetPage)) {
|
|
10746
10735
|
throw new Error("Target page is not data page");
|
|
10747
10736
|
}
|
|
@@ -10754,7 +10743,7 @@ var RowTableEngine = class {
|
|
|
10754
10743
|
const newRidNumeric = this.getRID();
|
|
10755
10744
|
await this.bptree.delete(oldRidNumeric, pk);
|
|
10756
10745
|
await this.bptree.insert(newRidNumeric, pk);
|
|
10757
|
-
const freshMetadataPage = await this.pfs.getMetadata(tx);
|
|
10746
|
+
const freshMetadataPage = await this.pfs.getMetadata(true, tx);
|
|
10758
10747
|
this.metadataPageManager.setLastInsertPageId(freshMetadataPage, lastInsertDataPageId);
|
|
10759
10748
|
await this.pfs.setMetadata(freshMetadataPage, tx);
|
|
10760
10749
|
}
|
|
@@ -10774,7 +10763,7 @@ var RowTableEngine = class {
|
|
|
10774
10763
|
this.keyManager.setBufferFromKey(rid, this.ridBuffer);
|
|
10775
10764
|
const pageId = this.keyManager.getPageId(this.ridBuffer);
|
|
10776
10765
|
const slotIndex = this.keyManager.getSlotIndex(this.ridBuffer);
|
|
10777
|
-
const page = await this.pfs.get(pageId, tx);
|
|
10766
|
+
const page = await this.pfs.get(pageId, true, tx);
|
|
10778
10767
|
if (!this.factory.isDataPage(page)) {
|
|
10779
10768
|
throw new Error(`RID not found for PK: ${pk}`);
|
|
10780
10769
|
}
|
|
@@ -10790,14 +10779,14 @@ var RowTableEngine = class {
|
|
|
10790
10779
|
await this.pfs.setPage(pageId, page, tx);
|
|
10791
10780
|
await this.bptree.delete(rid, pk);
|
|
10792
10781
|
if (decrementRowCount) {
|
|
10793
|
-
const metadataPage2 = await this.pfs.getMetadata(tx);
|
|
10782
|
+
const metadataPage2 = await this.pfs.getMetadata(true, tx);
|
|
10794
10783
|
const currentRowCount = this.metadataPageManager.getRowCount(metadataPage2);
|
|
10795
10784
|
this.metadataPageManager.setRowCount(metadataPage2, currentRowCount - 1);
|
|
10796
10785
|
await this.pfs.setMetadata(metadataPage2, tx);
|
|
10797
10786
|
}
|
|
10798
10787
|
const insertedRowCount = this.dataPageManager.getInsertedRowCount(page);
|
|
10799
10788
|
let allDeleted = true;
|
|
10800
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10789
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10801
10790
|
const lastInsertPageId = this.metadataPageManager.getLastInsertPageId(metadataPage);
|
|
10802
10791
|
if (pageId === lastInsertPageId) {
|
|
10803
10792
|
allDeleted = false;
|
|
@@ -10903,7 +10892,7 @@ var RowTableEngine = class {
|
|
|
10903
10892
|
const sortedPageIds = Array.from(collections.keys()).sort((a, b) => a - b);
|
|
10904
10893
|
await Promise.all(sortedPageIds.map(async (pageId) => {
|
|
10905
10894
|
const items = collections.get(pageId);
|
|
10906
|
-
const page = await this.pfs.get(pageId, tx);
|
|
10895
|
+
const page = await this.pfs.get(pageId, false, tx);
|
|
10907
10896
|
if (!this.factory.isDataPage(page)) {
|
|
10908
10897
|
throw new Error(`Page ${pageId} is not a data page`);
|
|
10909
10898
|
}
|
|
@@ -10928,7 +10917,7 @@ var RowTableEngine = class {
|
|
|
10928
10917
|
this.keyManager.setBufferFromKey(rid, this.ridBuffer);
|
|
10929
10918
|
const pageId = this.keyManager.getPageId(this.ridBuffer);
|
|
10930
10919
|
const slotIndex = this.keyManager.getSlotIndex(this.ridBuffer);
|
|
10931
|
-
const page = await this.pfs.get(pageId, tx);
|
|
10920
|
+
const page = await this.pfs.get(pageId, false, tx);
|
|
10932
10921
|
if (!this.factory.isDataPage(page)) {
|
|
10933
10922
|
throw new Error(`RID not found for PK: ${pk}`);
|
|
10934
10923
|
}
|
|
@@ -10938,7 +10927,7 @@ var RowTableEngine = class {
|
|
|
10938
10927
|
return null;
|
|
10939
10928
|
} else if (this.rowManager.getOverflowFlag(row)) {
|
|
10940
10929
|
const overflowPageId = bytesToNumber(this.rowManager.getBody(row));
|
|
10941
|
-
const overflowPage = await this.pfs.get(overflowPageId, tx);
|
|
10930
|
+
const overflowPage = await this.pfs.get(overflowPageId, false, tx);
|
|
10942
10931
|
if (!this.factory.isOverflowPage(overflowPage)) {
|
|
10943
10932
|
throw new Error(`Overflow page not found for RID: ${rid}`);
|
|
10944
10933
|
}
|
|
@@ -10952,7 +10941,7 @@ var RowTableEngine = class {
|
|
|
10952
10941
|
* @returns Row count
|
|
10953
10942
|
*/
|
|
10954
10943
|
async getRowCount(tx) {
|
|
10955
|
-
const metadataPage = await this.pfs.getMetadata(tx);
|
|
10944
|
+
const metadataPage = await this.pfs.getMetadata(false, tx);
|
|
10956
10945
|
return this.metadataPageManager.getRowCount(metadataPage);
|
|
10957
10946
|
}
|
|
10958
10947
|
};
|
|
@@ -11063,16 +11052,20 @@ var Transaction = class {
|
|
|
11063
11052
|
/**
|
|
11064
11053
|
* Reads a page through the MVCC transaction.
|
|
11065
11054
|
* @param pageId Page ID
|
|
11055
|
+
* @param copy Copy-on-Read
|
|
11066
11056
|
* @returns Page data
|
|
11067
11057
|
*/
|
|
11068
|
-
async __readPage(pageId) {
|
|
11058
|
+
async __readPage(pageId, copy) {
|
|
11069
11059
|
const data = await this.mvccTx.read(pageId);
|
|
11070
11060
|
if (data === null) {
|
|
11071
11061
|
return new Uint8Array(this.pfs.pageSize);
|
|
11072
11062
|
}
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
|
|
11063
|
+
if (copy) {
|
|
11064
|
+
const copy2 = new Uint8Array(data.length);
|
|
11065
|
+
copy2.set(data);
|
|
11066
|
+
return copy2;
|
|
11067
|
+
}
|
|
11068
|
+
return data;
|
|
11076
11069
|
}
|
|
11077
11070
|
/**
|
|
11078
11071
|
* Writes a page through the MVCC transaction.
|
|
@@ -11082,9 +11075,7 @@ var Transaction = class {
|
|
|
11082
11075
|
async __writePage(pageId, data) {
|
|
11083
11076
|
const exists = await this.mvccTx.exists(pageId);
|
|
11084
11077
|
if (exists) {
|
|
11085
|
-
|
|
11086
|
-
copy.set(data);
|
|
11087
|
-
await this.mvccTx.write(pageId, copy);
|
|
11078
|
+
await this.mvccTx.write(pageId, data);
|
|
11088
11079
|
} else {
|
|
11089
11080
|
await this.mvccTx.create(pageId, data);
|
|
11090
11081
|
}
|
|
@@ -11490,7 +11481,7 @@ var DataplyAPI = class {
|
|
|
11490
11481
|
* @returns The result of the callback.
|
|
11491
11482
|
*/
|
|
11492
11483
|
async withWriteTransaction(callback, tx) {
|
|
11493
|
-
this.logger.debug("Running with
|
|
11484
|
+
this.logger.debug("Running with write transaction");
|
|
11494
11485
|
if (!tx) {
|
|
11495
11486
|
const release = await this.acquireWriteLock();
|
|
11496
11487
|
const internalTx = this.createTransaction();
|
|
@@ -11514,7 +11505,7 @@ var DataplyAPI = class {
|
|
|
11514
11505
|
return result;
|
|
11515
11506
|
}
|
|
11516
11507
|
async withReadTransaction(callback, tx) {
|
|
11517
|
-
this.logger.debug("Running with
|
|
11508
|
+
this.logger.debug("Running with read transaction");
|
|
11518
11509
|
const isInternalTx = !tx;
|
|
11519
11510
|
if (!tx) {
|
|
11520
11511
|
tx = this.createTransaction();
|
|
@@ -62,17 +62,19 @@ export declare class PageFileSystem {
|
|
|
62
62
|
get strategy(): PageMVCCStrategy;
|
|
63
63
|
/**
|
|
64
64
|
* @param pageIndex 페이지 인덱스
|
|
65
|
+
* @param copy Copy-on-Read
|
|
65
66
|
* @param tx 트랜잭션
|
|
66
67
|
* @returns 페이지 버퍼
|
|
67
68
|
*/
|
|
68
|
-
get(pageIndex: number, tx: Transaction): Promise<Uint8Array>;
|
|
69
|
+
get(pageIndex: number, copy: boolean, tx: Transaction): Promise<Uint8Array>;
|
|
69
70
|
/**
|
|
70
71
|
* Reads the page header.
|
|
71
72
|
* @param pageIndex Page index
|
|
73
|
+
* @param copy Copy-on-Read
|
|
72
74
|
* @param tx Transaction
|
|
73
75
|
* @returns Page header buffer
|
|
74
76
|
*/
|
|
75
|
-
getHeader(pageIndex: number, tx: Transaction): Promise<Uint8Array>;
|
|
77
|
+
getHeader(pageIndex: number, copy: boolean, tx: Transaction): Promise<Uint8Array>;
|
|
76
78
|
/**
|
|
77
79
|
* Reads the page body.
|
|
78
80
|
* @param pageIndex Page index
|
|
@@ -83,10 +85,11 @@ export declare class PageFileSystem {
|
|
|
83
85
|
getBody(pageIndex: number, recursive: boolean | undefined, tx: Transaction): Promise<Uint8Array>;
|
|
84
86
|
/**
|
|
85
87
|
* Returns the metadata page.
|
|
88
|
+
* @param copy Copy-on-Read
|
|
86
89
|
* @param tx Transaction
|
|
87
90
|
* @returns Metadata page
|
|
88
91
|
*/
|
|
89
|
-
getMetadata(tx: Transaction): Promise<MetadataPage>;
|
|
92
|
+
getMetadata(copy: boolean, tx: Transaction): Promise<MetadataPage>;
|
|
90
93
|
/**
|
|
91
94
|
* Returns the number of pages stored in the database.
|
|
92
95
|
* @param tx Transaction
|
|
@@ -95,10 +98,11 @@ export declare class PageFileSystem {
|
|
|
95
98
|
getPageCount(tx: Transaction): Promise<number>;
|
|
96
99
|
/**
|
|
97
100
|
* Returns the root index page.
|
|
101
|
+
* @param copy Copy-on-Read
|
|
98
102
|
* @param tx Transaction
|
|
99
103
|
* @returns Root index page
|
|
100
104
|
*/
|
|
101
|
-
getRootIndex(tx: Transaction): Promise<IndexPage>;
|
|
105
|
+
getRootIndex(copy: boolean, tx: Transaction): Promise<IndexPage>;
|
|
102
106
|
/**
|
|
103
107
|
* Sets the metadata page.
|
|
104
108
|
* @param metadataPage Metadata page
|
|
@@ -51,9 +51,10 @@ export declare class Transaction {
|
|
|
51
51
|
/**
|
|
52
52
|
* Reads a page through the MVCC transaction.
|
|
53
53
|
* @param pageId Page ID
|
|
54
|
+
* @param copy Copy-on-Read
|
|
54
55
|
* @returns Page data
|
|
55
56
|
*/
|
|
56
|
-
__readPage(pageId: number): Promise<Uint8Array>;
|
|
57
|
+
__readPage(pageId: number, copy: boolean): Promise<Uint8Array>;
|
|
57
58
|
/**
|
|
58
59
|
* Writes a page through the MVCC transaction.
|
|
59
60
|
* @param pageId Page ID
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataply",
|
|
3
|
-
"version": "0.0.26-alpha.
|
|
3
|
+
"version": "0.0.26-alpha.11",
|
|
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>",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"hookall": "^2.2.0",
|
|
50
50
|
"mvcc-api": "^1.3.7",
|
|
51
51
|
"ryoiki": "^1.2.0",
|
|
52
|
-
"serializable-bptree": "^9.0.
|
|
52
|
+
"serializable-bptree": "^9.0.4-alpha.0"
|
|
53
53
|
}
|
|
54
54
|
}
|