@yydb/yyds 0.0.15 → 0.0.20
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/package.json +6 -6
- package/src/bindings.ts +19 -3
- package/src/node/cluster.ts +2 -1
- package/src/node/runtime.ts +34 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yydb/yyds",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Node.js facade, CLI, and native bindings for local YYDS nodes.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"optionalDependencies": {
|
|
62
|
-
"@yydb/yyds-win32-x64": "0.0.
|
|
63
|
-
"@yydb/yyds-linux-x64": "0.0.
|
|
64
|
-
"@yydb/yyds-darwin-x64": "0.0.
|
|
65
|
-
"@yydb/yyds-darwin-arm64": "0.0.
|
|
62
|
+
"@yydb/yyds-win32-x64": "0.0.20",
|
|
63
|
+
"@yydb/yyds-linux-x64": "0.0.20",
|
|
64
|
+
"@yydb/yyds-darwin-x64": "0.0.20",
|
|
65
|
+
"@yydb/yyds-darwin-arm64": "0.0.20"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^22.15.0",
|
|
69
|
-
"@yydb/yyds-webui": "0.0.
|
|
69
|
+
"@yydb/yyds-webui": "0.0.20",
|
|
70
70
|
"typescript": "^5.9.2"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
package/src/bindings.ts
CHANGED
|
@@ -6,14 +6,30 @@ export interface YydsBindings {
|
|
|
6
6
|
NodeLeaseHandle: {
|
|
7
7
|
acquire(dataDir: string, identity: unknown): unknown;
|
|
8
8
|
};
|
|
9
|
-
LocalExecutorHandle: new (dataDir: string) => unknown;
|
|
9
|
+
LocalExecutorHandle: new (dataDir: string, catalogPath?: string | null) => unknown;
|
|
10
10
|
RedisServiceHandle: new (
|
|
11
11
|
lease: unknown,
|
|
12
12
|
port: number,
|
|
13
13
|
executor: unknown,
|
|
14
14
|
) => RedisServiceBinding;
|
|
15
|
-
PgsqlServiceHandle:
|
|
16
|
-
|
|
15
|
+
PgsqlServiceHandle: {
|
|
16
|
+
new (lease: unknown, port: number): PgsqlServiceBinding;
|
|
17
|
+
start_with_executor(
|
|
18
|
+
lease: unknown,
|
|
19
|
+
port: number,
|
|
20
|
+
executor: unknown,
|
|
21
|
+
catalogPath: string,
|
|
22
|
+
): PgsqlServiceBinding;
|
|
23
|
+
};
|
|
24
|
+
MysqlServiceHandle: {
|
|
25
|
+
new (lease: unknown, port: number): MysqlServiceBinding;
|
|
26
|
+
start_with_executor(
|
|
27
|
+
lease: unknown,
|
|
28
|
+
port: number,
|
|
29
|
+
executor: unknown,
|
|
30
|
+
catalogPath: string,
|
|
31
|
+
): MysqlServiceBinding;
|
|
32
|
+
};
|
|
17
33
|
MongoServiceHandle: new (
|
|
18
34
|
lease: unknown,
|
|
19
35
|
port: number,
|
package/src/node/cluster.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StartNodeOptions } from "./runtime.ts";
|
|
2
2
|
import { parseStartOptions, runNodeStart } from "./runtime.ts";
|
|
3
3
|
|
|
4
|
-
export type YydsProtocol = "redis" | "mysql" | "postgresql";
|
|
4
|
+
export type YydsProtocol = "redis" | "mysql" | "postgresql" | "mongodb";
|
|
5
5
|
|
|
6
6
|
/** Maps disguise-server `--port` flags to protocol-specific yyds start flags. */
|
|
7
7
|
export function yydsStartArguments(protocol: YydsProtocol, args: string[]): string[] {
|
|
@@ -9,6 +9,7 @@ export function yydsStartArguments(protocol: YydsProtocol, args: string[]): stri
|
|
|
9
9
|
redis: "--redis-port",
|
|
10
10
|
mysql: "--mysql-port",
|
|
11
11
|
postgresql: "--pgsql-port",
|
|
12
|
+
mongodb: "--mongo-port",
|
|
12
13
|
};
|
|
13
14
|
const defaultPorts: Partial<Record<YydsProtocol, number>> = {
|
|
14
15
|
mysql: 3306,
|
package/src/node/runtime.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface StartNodeOptions {
|
|
|
9
9
|
dataDir: string;
|
|
10
10
|
clusterId: string;
|
|
11
11
|
nodeId: string;
|
|
12
|
+
catalogPath?: string;
|
|
12
13
|
redisPort?: number;
|
|
13
14
|
pgsqlPort?: number;
|
|
14
15
|
mysqlPort?: number;
|
|
@@ -27,6 +28,7 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
|
|
|
27
28
|
redis: "--redis-port",
|
|
28
29
|
mysql: "--mysql-port",
|
|
29
30
|
postgresql: "--pgsql-port",
|
|
31
|
+
mongodb: "--mongo-port",
|
|
30
32
|
};
|
|
31
33
|
const defaultPorts: Partial<Record<YydsProtocol, number>> = { mysql: 3306, postgresql: 5432 };
|
|
32
34
|
|
|
@@ -39,6 +41,7 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
|
|
|
39
41
|
if (protocol === "redis") options.redisPort = value;
|
|
40
42
|
if (protocol === "mysql") options.mysqlPort = value;
|
|
41
43
|
if (protocol === "postgresql") options.pgsqlPort = value;
|
|
44
|
+
if (protocol === "mongodb") options.mongoPort = value;
|
|
42
45
|
continue;
|
|
43
46
|
}
|
|
44
47
|
if (argument === "--data-dir") {
|
|
@@ -53,6 +56,10 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
|
|
|
53
56
|
options.nodeId = args[++index] ?? "";
|
|
54
57
|
continue;
|
|
55
58
|
}
|
|
59
|
+
if (argument === "--catalog-path") {
|
|
60
|
+
options.catalogPath = args[++index] ?? "";
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
56
63
|
if (argument === "--redis-port") {
|
|
57
64
|
options.redisPort = Number(args[++index]);
|
|
58
65
|
continue;
|
|
@@ -79,6 +86,10 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
|
|
|
79
86
|
if (!options.dataDir || !options.clusterId || !options.nodeId) {
|
|
80
87
|
throw new Error("start requires --data-dir, --cluster-id, and --node-id");
|
|
81
88
|
}
|
|
89
|
+
if (options.catalogPath !== undefined && options.catalogPath.length === 0) {
|
|
90
|
+
// 空字符串视为未提供;避免将空值传给 Rust。
|
|
91
|
+
options.catalogPath = undefined;
|
|
92
|
+
}
|
|
82
93
|
const defaultPort = defaultPorts[protocol];
|
|
83
94
|
if (protocol === "mysql" && options.mysqlPort === undefined && defaultPort !== undefined) {
|
|
84
95
|
options.mysqlPort = defaultPort;
|
|
@@ -86,6 +97,7 @@ export function parseStartOptions(protocol: YydsProtocol, args: string[]): Start
|
|
|
86
97
|
if (protocol === "postgresql" && options.pgsqlPort === undefined && defaultPort !== undefined) {
|
|
87
98
|
options.pgsqlPort = defaultPort;
|
|
88
99
|
}
|
|
100
|
+
void portFlags; // 变量声明用于协议完整性校验,运行时不再读取
|
|
89
101
|
return options;
|
|
90
102
|
}
|
|
91
103
|
|
|
@@ -94,20 +106,37 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
|
|
|
94
106
|
const native = loadYydsNative();
|
|
95
107
|
const identity = new native.NodeIdentityHandle(options.clusterId, options.nodeId);
|
|
96
108
|
const lease = native.NodeLeaseHandle.acquire(options.dataDir, identity);
|
|
97
|
-
const executor = new native.LocalExecutorHandle(options.dataDir);
|
|
109
|
+
const executor = new native.LocalExecutorHandle(options.dataDir, options.catalogPath);
|
|
98
110
|
const redis = new native.RedisServiceHandle(
|
|
99
111
|
lease,
|
|
100
112
|
options.redisPort ?? DEFAULT_REDIS_PORT,
|
|
101
113
|
executor,
|
|
102
114
|
);
|
|
115
|
+
|
|
116
|
+
// SQL runtimes 仅在提供了 catalog 时启动完整执行路径;否则保持协议壳。
|
|
117
|
+
const hasRuntime = options.catalogPath !== undefined;
|
|
103
118
|
const pgsql =
|
|
104
119
|
options.pgsqlPort === undefined
|
|
105
120
|
? undefined
|
|
106
|
-
:
|
|
121
|
+
: hasRuntime
|
|
122
|
+
? native.PgsqlServiceHandle.start_with_executor(
|
|
123
|
+
lease,
|
|
124
|
+
options.pgsqlPort,
|
|
125
|
+
executor,
|
|
126
|
+
options.catalogPath!,
|
|
127
|
+
)
|
|
128
|
+
: new native.PgsqlServiceHandle(lease, options.pgsqlPort);
|
|
107
129
|
const mysql =
|
|
108
130
|
options.mysqlPort === undefined
|
|
109
131
|
? undefined
|
|
110
|
-
:
|
|
132
|
+
: hasRuntime
|
|
133
|
+
? native.MysqlServiceHandle.start_with_executor(
|
|
134
|
+
lease,
|
|
135
|
+
options.mysqlPort,
|
|
136
|
+
executor,
|
|
137
|
+
options.catalogPath!,
|
|
138
|
+
)
|
|
139
|
+
: new native.MysqlServiceHandle(lease, options.mysqlPort);
|
|
111
140
|
const mongo =
|
|
112
141
|
options.mongoPort === undefined
|
|
113
142
|
? undefined
|
|
@@ -129,8 +158,9 @@ export async function runNodeStart(options: StartNodeOptions): Promise<void> {
|
|
|
129
158
|
};
|
|
130
159
|
native.nodeWriteRuntimeStatus(options.dataDir, JSON.stringify(runtime));
|
|
131
160
|
|
|
161
|
+
const runtimeTag = hasRuntime ? "sql-runtime" : "protocol-only";
|
|
132
162
|
process.stdout.write(
|
|
133
|
-
`yyds running pid=${runtime.pid} redis=${runtime.redisAddress} pgsql=${runtime.pgsqlAddress ?? "null"} mysql=${runtime.mysqlAddress ?? "null"} mongo=${mongo?.address() ?? "null"} wire=${runtime.wireAddress ?? "null"}\n`,
|
|
163
|
+
`yyds running pid=${runtime.pid} mode=${runtimeTag} redis=${runtime.redisAddress} pgsql=${runtime.pgsqlAddress ?? "null"} mysql=${runtime.mysqlAddress ?? "null"} mongo=${mongo?.address() ?? "null"} wire=${runtime.wireAddress ?? "null"}\n`,
|
|
134
164
|
);
|
|
135
165
|
|
|
136
166
|
while (true) {
|