@based/db 0.2.8 → 0.2.10
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/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- 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/libnode-v25.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v25.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v25.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/server/index.js +2 -9
- package/dist/src/server/migrate/index.d.ts +1 -1
- package/dist/src/server/migrate/index.js +23 -3
- package/dist/src/server/save.js +1 -0
- package/dist/src/server/subscription.d.ts +1 -0
- package/dist/src/server/subscription.js +9 -0
- package/package.json +3 -2
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/src/server/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { DbShared } from '../shared/DbBase.js';
|
|
|
13
13
|
import { setNativeSchema, setSchemaOnServer, writeSchemaFile, } from './schema.js';
|
|
14
14
|
import { resizeModifyDirtyRanges } from './resizeModifyDirtyRanges.js';
|
|
15
15
|
import { loadBlock, unloadBlock } from './blocks.js';
|
|
16
|
+
import { initDefaultSubscriptions } from './subscription.js';
|
|
16
17
|
const emptyUint8Array = new Uint8Array(0);
|
|
17
18
|
class SortIndex {
|
|
18
19
|
constructor(buf, dbCtxExternal) {
|
|
@@ -26,15 +27,7 @@ class SortIndex {
|
|
|
26
27
|
export class DbServer extends DbShared {
|
|
27
28
|
modifyDirtyRanges;
|
|
28
29
|
dbCtxExternal; // pointer to zig dbCtx
|
|
29
|
-
subscriptions =
|
|
30
|
-
subInterval: 200,
|
|
31
|
-
active: 0,
|
|
32
|
-
updateHandler: null,
|
|
33
|
-
ids: new Map(),
|
|
34
|
-
fullType: new Map(),
|
|
35
|
-
updateId: 1,
|
|
36
|
-
now: { listeners: new Set(), lastUpdated: 1 },
|
|
37
|
-
};
|
|
30
|
+
subscriptions = initDefaultSubscriptions();
|
|
38
31
|
migrating = null;
|
|
39
32
|
saveInProgress = false;
|
|
40
33
|
fileSystemPath;
|
|
@@ -5,4 +5,4 @@ export type MigrateRange = {
|
|
|
5
5
|
start: number;
|
|
6
6
|
end: number;
|
|
7
7
|
};
|
|
8
|
-
export declare const migrate: (server: DbServer, fromSchema: DbSchema, toSchema: DbSchema, transform?: MigrateFns) => Promise<void>;
|
|
8
|
+
export declare const migrate: (server: DbServer, fromSchema: DbSchema, toSchema: DbSchema, transform?: MigrateFns) => Promise<true | void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasedDb, save } from '../../index.js';
|
|
1
|
+
import { BasedDb, initDefaultSubscriptions, save } from '../../index.js';
|
|
2
2
|
import { dirname, join } from 'path';
|
|
3
3
|
import { Worker, MessageChannel } from 'node:worker_threads';
|
|
4
4
|
import native from '../../native.js';
|
|
@@ -80,7 +80,7 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
80
80
|
return newMigrationInProgress;
|
|
81
81
|
};
|
|
82
82
|
const tmpDb = new BasedDb({
|
|
83
|
-
path: null,
|
|
83
|
+
path: null, //join(tmpdir(), String(Math.random())),
|
|
84
84
|
});
|
|
85
85
|
await tmpDb.start({
|
|
86
86
|
clean: true,
|
|
@@ -140,6 +140,23 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
140
140
|
const end = start + def.blockCapacity - 1;
|
|
141
141
|
rangesToMigrate.push({ typeId, start, end });
|
|
142
142
|
});
|
|
143
|
+
rangesToMigrate.sort((a, b) => {
|
|
144
|
+
const typeA = server.schemaTypesParsedById[a.typeId];
|
|
145
|
+
const typeB = server.schemaTypesParsedById[b.typeId];
|
|
146
|
+
for (const k in typeA.props) {
|
|
147
|
+
const prop = typeA.props[k];
|
|
148
|
+
if (prop.dependent && prop.inverseTypeName === typeB.type) {
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const k in typeB.props) {
|
|
153
|
+
const prop = typeB.props[k];
|
|
154
|
+
if (prop.dependent && prop.inverseTypeName === typeA.type) {
|
|
155
|
+
return -1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return 0;
|
|
159
|
+
});
|
|
143
160
|
await waitUntilSleeping(workerState);
|
|
144
161
|
while (i < rangesToMigrate.length) {
|
|
145
162
|
if (abort()) {
|
|
@@ -176,15 +193,17 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
176
193
|
}
|
|
177
194
|
server.dbCtxExternal = toCtx;
|
|
178
195
|
server.sortIndexes = {};
|
|
196
|
+
server.subscriptions = initDefaultSubscriptions();
|
|
179
197
|
setSchemaOnServer(server, toSchema);
|
|
180
198
|
tmpDb.server.dbCtxExternal = fromCtx;
|
|
181
199
|
// TODO makes this SYNC
|
|
182
200
|
const promises = [server.ioWorker, ...server.workers].map((worker) => worker.updateCtx(toAddress));
|
|
183
|
-
promises.push(
|
|
201
|
+
promises.push(worker.terminate());
|
|
184
202
|
await Promise.all(promises);
|
|
185
203
|
if (abort()) {
|
|
186
204
|
return;
|
|
187
205
|
}
|
|
206
|
+
tmpDb.destroy();
|
|
188
207
|
native.membarSyncRead();
|
|
189
208
|
await save(server, {
|
|
190
209
|
forceFullDump: true,
|
|
@@ -194,5 +213,6 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
194
213
|
await writeSchemaFile(server, toSchema);
|
|
195
214
|
server.migrating = 0;
|
|
196
215
|
process.nextTick(() => server.emit('schema', server.schema));
|
|
216
|
+
return true;
|
|
197
217
|
};
|
|
198
218
|
//# sourceMappingURL=index.js.map
|
package/dist/src/server/save.js
CHANGED
|
@@ -110,6 +110,7 @@ export async function save(db, opts = {}) {
|
|
|
110
110
|
let err;
|
|
111
111
|
err = native.saveCommon(join(db.fileSystemPath, COMMON_SDB_FILE), db.dbCtxExternal);
|
|
112
112
|
if (err) {
|
|
113
|
+
console.log({ err });
|
|
113
114
|
db.emit('error', `Save common failed: ${err}`);
|
|
114
115
|
// Return ?
|
|
115
116
|
}
|
|
@@ -27,6 +27,7 @@ export type Subscriptions = {
|
|
|
27
27
|
};
|
|
28
28
|
subInterval: number;
|
|
29
29
|
};
|
|
30
|
+
export declare const initDefaultSubscriptions: () => Subscriptions;
|
|
30
31
|
export declare const startUpdateHandler: (server: DbServer) => void;
|
|
31
32
|
export declare const registerSubscription: (server: DbServer, query: Uint8Array, sub: Uint8Array, onData: OnData, onError: OnError, subInterval?: number) => () => void;
|
|
32
33
|
export {};
|
|
@@ -3,6 +3,15 @@ import { SubscriptionType, } from '../client/query/subscription/types.js';
|
|
|
3
3
|
import native from '../native.js';
|
|
4
4
|
import { MAX_ID } from '@based/schema';
|
|
5
5
|
import { styleText } from 'util';
|
|
6
|
+
export const initDefaultSubscriptions = () => ({
|
|
7
|
+
subInterval: 200,
|
|
8
|
+
active: 0,
|
|
9
|
+
updateHandler: null,
|
|
10
|
+
ids: new Map(),
|
|
11
|
+
fullType: new Map(),
|
|
12
|
+
updateId: 1,
|
|
13
|
+
now: { listeners: new Set(), lastUpdated: 1 },
|
|
14
|
+
});
|
|
6
15
|
export const startUpdateHandler = (server) => {
|
|
7
16
|
// skip next if queries are sitll in progress can add a number for each staged sub
|
|
8
17
|
// combine this with handled modify
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"test-fast-linux_aarch64": "podman run -t --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; npm run test-fast'",
|
|
24
24
|
"test-fast-linux_aarch64-gdb": "podman run -t --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; LOCPATH=../locale/locale-x86_64-gnu/locale gdb -ex run --args node ./scripts/test.js'",
|
|
25
25
|
"test-fast-linux_aarch64-valgrind": "podman run -t --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; LOCPATH=../locale/locale-aarch64-gnu/locale valgrind --leak-check=full node ./scripts/test.js'",
|
|
26
|
+
"test-fast-linux_aarch64-valgrind-subs": "podman run -t --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; LOCPATH=../locale/locale-aarch64-gnu/locale valgrind --leak-check=full node ./scripts/test.js subscription/subscription.js'",
|
|
26
27
|
"test-vector": "podman run --rm -v \"$PWD/../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64 sh -c '\\. \"/usr/local/nvm/nvm.sh\"; cd /usr/src/based-db/packages/db; npm run test-fast -- mem.js'",
|
|
27
28
|
"test-zig": "npm run build-zig && tsc && npm run test-fast",
|
|
28
29
|
"test-zig-debug": "npm run build-zig -- debug && tsc && LOCPATH=../locale/locale-x86_64-gnu/locale ./scripts/lldb-node ./scripts/test.js",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"@based/hash": "1.1.0",
|
|
45
46
|
"@based/schema": "5.1.4",
|
|
46
47
|
"@based/utils": "1.2.0",
|
|
47
|
-
"@based/protocol": "0.1.
|
|
48
|
+
"@based/protocol": "0.1.5",
|
|
48
49
|
"exit-hook": "^4.0.0"
|
|
49
50
|
},
|
|
50
51
|
"optionalDependencies": {
|