@based/db 0.0.69 → 0.0.70
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/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/modify/create.js +4 -0
- package/dist/src/client/modify/update.js +4 -0
- package/dist/src/server/migrate/index.js +21 -7
- package/dist/src/server/migrate/worker.js +70 -62
- package/package.json +4 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,6 +11,7 @@ import { writeString } from './string.js';
|
|
|
11
11
|
import { writeText } from './text.js';
|
|
12
12
|
import { writeJson } from './json.js';
|
|
13
13
|
import { writeAlias } from './alias.js';
|
|
14
|
+
import { getByPath } from '@saulx/utils';
|
|
14
15
|
const appendCreate = (ctx, schema, obj, res, unsafe) => {
|
|
15
16
|
const len = ctx.len;
|
|
16
17
|
let err = modify(ctx, res, obj, schema, CREATE, schema.tree, true, unsafe);
|
|
@@ -26,6 +27,9 @@ const appendCreate = (ctx, schema, obj, res, unsafe) => {
|
|
|
26
27
|
if (schema.createTs) {
|
|
27
28
|
const createTs = Date.now();
|
|
28
29
|
for (const prop of schema.createTs) {
|
|
30
|
+
if (getByPath(obj, prop.path) !== undefined) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
29
33
|
if (ctx.lastMain === -1) {
|
|
30
34
|
let mainLenU32 = schema.mainLen;
|
|
31
35
|
setCursor(ctx, schema, prop.prop, MICRO_BUFFER, res.tmpId, CREATE);
|
|
@@ -5,6 +5,7 @@ import { modify } from './modify.js';
|
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
6
6
|
import { RANGE_ERR, UPDATE } from './types.js';
|
|
7
7
|
import { appendFixedValue } from './fixed.js';
|
|
8
|
+
import { getByPath } from '@saulx/utils';
|
|
8
9
|
const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
9
10
|
const err = modify(ctx, res, obj, def, UPDATE, def.tree, overwrite);
|
|
10
11
|
if (err) {
|
|
@@ -13,6 +14,9 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
|
13
14
|
if (def.updateTs) {
|
|
14
15
|
const updateTs = Date.now();
|
|
15
16
|
for (const prop of def.updateTs) {
|
|
17
|
+
if (getByPath(obj, prop.path) !== undefined) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
16
20
|
if (ctx.mergeMain) {
|
|
17
21
|
ctx.mergeMain.push(prop, updateTs);
|
|
18
22
|
ctx.mergeMainSize += prop.len + 4;
|
|
@@ -7,6 +7,7 @@ import { foreachDirtyBlock } from '../blocks.js';
|
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { setNativeSchema, setSchemaOnServer, writeSchemaFile, } from '../schema.js';
|
|
9
9
|
import { setToAwake, waitUntilSleeping } from './utils.js';
|
|
10
|
+
import { serialize } from '@based/schema';
|
|
10
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
12
|
const __dirname = dirname(__filename);
|
|
12
13
|
const workerPath = join(__dirname, 'worker.js');
|
|
@@ -74,8 +75,14 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
74
75
|
isDbMigrateWorker: true,
|
|
75
76
|
from: fromAddress,
|
|
76
77
|
to: toAddress,
|
|
77
|
-
fromSchema,
|
|
78
|
-
|
|
78
|
+
fromSchema: serialize(fromSchema, {
|
|
79
|
+
stripMetaInformation: true,
|
|
80
|
+
stripTransform: true,
|
|
81
|
+
}),
|
|
82
|
+
toSchema: serialize(toSchema, {
|
|
83
|
+
stripMetaInformation: true,
|
|
84
|
+
stripTransform: true,
|
|
85
|
+
}),
|
|
79
86
|
channel: port2,
|
|
80
87
|
workerState,
|
|
81
88
|
transformFns,
|
|
@@ -83,9 +90,12 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
83
90
|
transferList: [port2],
|
|
84
91
|
});
|
|
85
92
|
// handle?
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
const errorPromise = new Promise((resolve) => {
|
|
94
|
+
worker.once('error', (err) => {
|
|
95
|
+
killed = true;
|
|
96
|
+
console.error(`Error in migration ${err.message}, aborting migration`);
|
|
97
|
+
resolve();
|
|
98
|
+
});
|
|
89
99
|
});
|
|
90
100
|
// Block handling
|
|
91
101
|
let i = 0;
|
|
@@ -107,7 +117,7 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
107
117
|
const leafData = rangesToMigrate[i++];
|
|
108
118
|
port1.postMessage(leafData);
|
|
109
119
|
setToAwake(workerState, true);
|
|
110
|
-
await waitUntilSleeping(workerState);
|
|
120
|
+
await Promise.race([errorPromise, waitUntilSleeping(workerState)]);
|
|
111
121
|
// exec queued modifies
|
|
112
122
|
server.activeReaders--;
|
|
113
123
|
server.onQueryEnd();
|
|
@@ -156,7 +166,11 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
156
166
|
return;
|
|
157
167
|
}
|
|
158
168
|
native.membarSyncRead();
|
|
159
|
-
await save(server, {
|
|
169
|
+
await save(server, {
|
|
170
|
+
forceFullDump: true,
|
|
171
|
+
skipDirtyCheck: true,
|
|
172
|
+
skipMigrationCheck: true,
|
|
173
|
+
});
|
|
160
174
|
await writeSchemaFile(server, toSchema);
|
|
161
175
|
server.migrating = 0;
|
|
162
176
|
process.nextTick(() => server.emit('schema', server.schema));
|
|
@@ -6,6 +6,7 @@ import { isTypedArray } from 'node:util/types';
|
|
|
6
6
|
import { setSchemaOnServer } from '../schema.js';
|
|
7
7
|
import { setToSleep } from './utils.js';
|
|
8
8
|
import { setLocalClientSchema } from '../../client/setLocalClientSchema.js';
|
|
9
|
+
import { deSerialize } from '@based/schema';
|
|
9
10
|
if (isMainThread) {
|
|
10
11
|
console.warn('running worker.ts in mainthread');
|
|
11
12
|
}
|
|
@@ -41,80 +42,87 @@ else if (workerData?.isDbMigrateWorker) {
|
|
|
41
42
|
};
|
|
42
43
|
fromDb.server.dbCtxExternal = fromCtx;
|
|
43
44
|
toDb.server.dbCtxExternal = toCtx;
|
|
44
|
-
setSchemaOnServer(fromDb.server, fromSchema);
|
|
45
|
-
setSchemaOnServer(toDb.server, toSchema);
|
|
45
|
+
setSchemaOnServer(fromDb.server, deSerialize(fromSchema));
|
|
46
|
+
setSchemaOnServer(toDb.server, deSerialize(toSchema));
|
|
46
47
|
setLocalClientSchema(fromDb.client, fromDb.server.schema);
|
|
47
48
|
setLocalClientSchema(toDb.client, toDb.server.schema);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
props[path].typeIndex ===
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
try {
|
|
50
|
+
const map = {};
|
|
51
|
+
for (const type in fromDb.server.schemaTypesParsed) {
|
|
52
|
+
const { id, props } = fromDb.server.schemaTypesParsed[type];
|
|
53
|
+
const include = Object.keys(props);
|
|
54
|
+
let i = include.length;
|
|
55
|
+
while (i--) {
|
|
56
|
+
const path = include[i];
|
|
57
|
+
if (props[path].typeIndex === REFERENCE ||
|
|
58
|
+
props[path].typeIndex === REFERENCES) {
|
|
59
|
+
include[i] = `${path}.id`;
|
|
60
|
+
if (props[path].edges) {
|
|
61
|
+
for (const key in props[path].edges) {
|
|
62
|
+
const prop = props[path].edges[key];
|
|
63
|
+
if (prop.typeIndex === REFERENCE ||
|
|
64
|
+
prop.typeIndex === REFERENCES) {
|
|
65
|
+
include.push(`${path}.${key}.id`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
include.push(`${path}.${key}`);
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
map[id] = { type, include };
|
|
70
75
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
toDb.create(type, res || node, { unsafe: true });
|
|
76
|
+
for (const type in transformFns) {
|
|
77
|
+
const fnOrNull = transformFns[type];
|
|
78
|
+
transformFns[type] = eval(`(${fnOrNull})`);
|
|
79
|
+
}
|
|
80
|
+
while (true) {
|
|
81
|
+
let msg;
|
|
82
|
+
while ((msg = receiveMessageOnPort(channel))) {
|
|
83
|
+
const leafData = msg.message;
|
|
84
|
+
const { type, include } = map[leafData.typeId];
|
|
85
|
+
const typeTransformFn = transformFns[type];
|
|
86
|
+
if (typeTransformFn) {
|
|
87
|
+
const nodes = fromDb
|
|
88
|
+
.query(type)
|
|
89
|
+
.include(include)
|
|
90
|
+
.range(leafData.start - 1, leafData.end)
|
|
91
|
+
._getSync(fromCtx);
|
|
92
|
+
for (const node of nodes) {
|
|
93
|
+
const res = typeTransformFn(node);
|
|
94
|
+
if (res === null) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(res)) {
|
|
98
|
+
toDb.create(res[0], res[1] || node, { unsafe: true });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
toDb.create(type, res || node, { unsafe: true });
|
|
102
|
+
}
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
else if (type in toDb.server.schemaTypesParsed) {
|
|
106
|
+
const nodes = fromDb
|
|
107
|
+
.query(type)
|
|
108
|
+
.include(include)
|
|
109
|
+
.range(leafData.start - 1, leafData.end)
|
|
110
|
+
._getSync(fromCtx);
|
|
111
|
+
for (const node of nodes) {
|
|
112
|
+
toDb.create(type, node, { unsafe: true });
|
|
113
|
+
}
|
|
110
114
|
}
|
|
111
115
|
}
|
|
116
|
+
await toDb.drain();
|
|
117
|
+
native.membarSyncWrite();
|
|
118
|
+
// WE ARE ONLY GOING TO SEND { type: lastNodeId }
|
|
119
|
+
channel.postMessage(cp(toDb.server.schemaTypesParsed));
|
|
120
|
+
setToSleep(workerState);
|
|
112
121
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
setToSleep(workerState);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
console.error(e);
|
|
125
|
+
throw e;
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.70",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"basedDbNative.cjs"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@based/schema": "5.0.0-alpha.
|
|
42
|
+
"@based/schema": "5.0.0-alpha.26",
|
|
43
43
|
"@saulx/hash": "^3.0.0",
|
|
44
44
|
"@saulx/utils": "^6.7.2",
|
|
45
45
|
"exit-hook": "^4.0.0",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"axios": "^1.7.9",
|
|
57
57
|
"rimraf": "^3.0.2",
|
|
58
58
|
"tar": "^7.4.3",
|
|
59
|
-
"typescript": "^5.6.3"
|
|
59
|
+
"typescript": "^5.6.3",
|
|
60
|
+
"fs-extra": "^11.1.1"
|
|
60
61
|
}
|
|
61
62
|
}
|