@zz1996/dbhub-dameng 0.1.6 → 0.1.7
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.
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
import dmdb from "dmdb";
|
|
11
11
|
var DEFAULT_OPERATION_TIMEOUT_MS = 11e4;
|
|
12
12
|
var RESOURCE_CLEANUP_TIMEOUT_MS = 2e3;
|
|
13
|
+
var CONNECT_RETRY_ATTEMPTS = 3;
|
|
14
|
+
var CONNECT_RETRY_DELAY_MS = 500;
|
|
13
15
|
var DamengOperationTimeoutError = class extends Error {
|
|
14
16
|
constructor(message, label) {
|
|
15
17
|
super(message);
|
|
@@ -95,61 +97,73 @@ var DamengConnector = class _DamengConnector {
|
|
|
95
97
|
return new _DamengConnector();
|
|
96
98
|
}
|
|
97
99
|
async connect(dsn, initScript, config) {
|
|
98
|
-
let
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
for (let attempt = 1; attempt <= CONNECT_RETRY_ATTEMPTS; attempt += 1) {
|
|
101
|
+
let createdPool = null;
|
|
102
|
+
try {
|
|
103
|
+
const connectionConfig = await this.dsnParser.parse(dsn, config);
|
|
104
|
+
connectionConfig.poolAlias = this.buildPoolAlias();
|
|
105
|
+
this.defaultSchema = connectionConfig.schema ?? null;
|
|
106
|
+
this.poolAlias = connectionConfig.poolAlias;
|
|
107
|
+
this.connectionTimeoutMs = config?.connectionTimeoutSeconds !== void 0 ? config.connectionTimeoutSeconds * 1e3 : 5e3;
|
|
108
|
+
this.operationTimeoutMs = config?.queryTimeoutSeconds !== void 0 ? config.queryTimeoutSeconds * 1e3 : DEFAULT_OPERATION_TIMEOUT_MS;
|
|
109
|
+
connectionConfig.connectTimeout ?? (connectionConfig.connectTimeout = this.connectionTimeoutMs);
|
|
110
|
+
connectionConfig.queueTimeout ?? (connectionConfig.queueTimeout = this.connectionTimeoutMs);
|
|
111
|
+
await this.closeRegisteredPool(connectionConfig.poolAlias);
|
|
112
|
+
await this.validateDirectConnection(connectionConfig);
|
|
113
|
+
createdPool = await dmdb.createPool(connectionConfig);
|
|
114
|
+
this.pool = createdPool;
|
|
115
|
+
await this.withConnection((conn) => this.initializeSession(conn, initScript));
|
|
116
|
+
this.connectionConfig = connectionConfig;
|
|
117
|
+
this.initScript = initScript;
|
|
118
|
+
return;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (createdPool) {
|
|
121
|
+
await this.closePoolQuietly(createdPool);
|
|
122
|
+
} else if (this.poolAlias) {
|
|
123
|
+
await this.closeRegisteredPool(this.poolAlias);
|
|
124
|
+
}
|
|
125
|
+
this.pool = null;
|
|
126
|
+
this.poolAlias = null;
|
|
127
|
+
this.connectionConfig = null;
|
|
128
|
+
this.initScript = void 0;
|
|
129
|
+
if (attempt < CONNECT_RETRY_ATTEMPTS && this.isRetryableConnectFailure(error)) {
|
|
130
|
+
console.error(
|
|
131
|
+
`Retrying Dameng source '${this.sourceId}' connection after transient failure (${attempt}/${CONNECT_RETRY_ATTEMPTS}): ${error instanceof Error ? error.message : String(error)}`
|
|
132
|
+
);
|
|
133
|
+
await this.delay(CONNECT_RETRY_DELAY_MS * attempt);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
console.error("Failed to connect to Dameng database:", error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw new Error("Failed to connect to Dameng database");
|
|
141
|
+
}
|
|
142
|
+
async initializeSession(conn, initScript) {
|
|
143
|
+
await this.executeWithTimeout(
|
|
144
|
+
conn,
|
|
145
|
+
"SELECT 1 AS OK",
|
|
146
|
+
[],
|
|
147
|
+
this.executeOptions()
|
|
148
|
+
);
|
|
149
|
+
if (!this.defaultSchema) {
|
|
150
|
+
const result = await this.executeWithTimeout(
|
|
151
|
+
conn,
|
|
152
|
+
"SELECT USER AS SCHEMA_NAME FROM DUAL",
|
|
153
|
+
[],
|
|
154
|
+
this.executeOptions()
|
|
155
|
+
);
|
|
156
|
+
this.defaultSchema = this.rowValue(result.rows?.[0], "SCHEMA_NAME") ?? null;
|
|
157
|
+
}
|
|
158
|
+
if (initScript) {
|
|
159
|
+
for (const statement of splitSQLStatements(initScript, "dameng")) {
|
|
113
160
|
await this.executeWithTimeout(
|
|
114
161
|
conn,
|
|
115
|
-
|
|
162
|
+
statement,
|
|
116
163
|
[],
|
|
117
|
-
this.executeOptions()
|
|
164
|
+
this.executeOptions({ autoCommit: true })
|
|
118
165
|
);
|
|
119
|
-
if (!this.defaultSchema) {
|
|
120
|
-
const result = await this.executeWithTimeout(
|
|
121
|
-
conn,
|
|
122
|
-
"SELECT USER AS SCHEMA_NAME FROM DUAL",
|
|
123
|
-
[],
|
|
124
|
-
this.executeOptions()
|
|
125
|
-
);
|
|
126
|
-
this.defaultSchema = this.rowValue(result.rows?.[0], "SCHEMA_NAME") ?? null;
|
|
127
|
-
}
|
|
128
|
-
if (initScript) {
|
|
129
|
-
for (const statement of splitSQLStatements(initScript, "dameng")) {
|
|
130
|
-
await this.executeWithTimeout(
|
|
131
|
-
conn,
|
|
132
|
-
statement,
|
|
133
|
-
[],
|
|
134
|
-
this.executeOptions({ autoCommit: true })
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
this.connectionConfig = connectionConfig;
|
|
140
|
-
this.initScript = initScript;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
if (createdPool) {
|
|
143
|
-
await this.closePoolQuietly(createdPool);
|
|
144
|
-
} else if (this.poolAlias) {
|
|
145
|
-
await this.closeRegisteredPool(this.poolAlias);
|
|
146
166
|
}
|
|
147
|
-
this.pool = null;
|
|
148
|
-
this.poolAlias = null;
|
|
149
|
-
this.connectionConfig = null;
|
|
150
|
-
this.initScript = void 0;
|
|
151
|
-
console.error("Failed to connect to Dameng database:", error);
|
|
152
|
-
throw error;
|
|
153
167
|
}
|
|
154
168
|
}
|
|
155
169
|
async disconnect() {
|
|
@@ -657,6 +671,34 @@ var DamengConnector = class _DamengConnector {
|
|
|
657
671
|
"\u8FDE\u63A5\u6C60\u5DF2\u8FBE\u5230\u6700\u5927\u8FDE\u63A5\u6570"
|
|
658
672
|
].some((item) => message.includes(item));
|
|
659
673
|
}
|
|
674
|
+
isRetryableConnectFailure(error) {
|
|
675
|
+
if (error instanceof DamengOperationTimeoutError) {
|
|
676
|
+
return [
|
|
677
|
+
"Dameng direct connection",
|
|
678
|
+
"Dameng connection acquisition",
|
|
679
|
+
"Dameng SQL execution"
|
|
680
|
+
].includes(error.label);
|
|
681
|
+
}
|
|
682
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
683
|
+
return [
|
|
684
|
+
"ECONNRESET",
|
|
685
|
+
"ETIMEDOUT",
|
|
686
|
+
"ECONNREFUSED",
|
|
687
|
+
"socket hang up",
|
|
688
|
+
"Socket timeout",
|
|
689
|
+
"connect timeout",
|
|
690
|
+
"Connection request timeout in queue",
|
|
691
|
+
"Pool cannot open more connections",
|
|
692
|
+
"\u7F51\u7EDC\u901A\u8BAF\u8D85\u65F6",
|
|
693
|
+
"\u7F51\u7EDC\u901A\u4FE1\u5F02\u5E38",
|
|
694
|
+
"\u8FDE\u63A5\u8D85\u65F6",
|
|
695
|
+
"\u83B7\u53D6\u8FDE\u63A5\u8BF7\u6C42\u7B49\u5F85\u8D85\u65F6",
|
|
696
|
+
"\u8FDE\u63A5\u6C60\u5DF2\u8FBE\u5230\u6700\u5927\u8FDE\u63A5\u6570"
|
|
697
|
+
].some((item) => message.includes(item));
|
|
698
|
+
}
|
|
699
|
+
delay(ms) {
|
|
700
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
701
|
+
}
|
|
660
702
|
executeOptions(extra = {}) {
|
|
661
703
|
return {
|
|
662
704
|
outFormat: dmdb.OUT_FORMAT_OBJECT,
|
package/dist/index.js
CHANGED
|
@@ -1865,7 +1865,7 @@ var connectorModules = [
|
|
|
1865
1865
|
{ load: () => import("./sqlite-IOUAYHGE.js"), name: "SQLite", driver: "node:sqlite" },
|
|
1866
1866
|
{ load: () => import("./mysql-A43SL7UM.js"), name: "MySQL", driver: "mysql2" },
|
|
1867
1867
|
{ load: () => import("./mariadb-7F72IRB4.js"), name: "MariaDB", driver: "mariadb" },
|
|
1868
|
-
{ load: () => import("./dameng-
|
|
1868
|
+
{ load: () => import("./dameng-5KYI5JBK.js"), name: "Dameng", driver: "dmdb" }
|
|
1869
1869
|
];
|
|
1870
1870
|
loadConnectors(connectorModules).then(() => main()).catch((error) => {
|
|
1871
1871
|
console.error("Fatal error:", error);
|