@zz1996/dbhub-dameng 0.1.5 → 0.1.6
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.
|
@@ -11,8 +11,9 @@ import dmdb from "dmdb";
|
|
|
11
11
|
var DEFAULT_OPERATION_TIMEOUT_MS = 11e4;
|
|
12
12
|
var RESOURCE_CLEANUP_TIMEOUT_MS = 2e3;
|
|
13
13
|
var DamengOperationTimeoutError = class extends Error {
|
|
14
|
-
constructor(message) {
|
|
14
|
+
constructor(message, label) {
|
|
15
15
|
super(message);
|
|
16
|
+
this.label = label;
|
|
16
17
|
this.name = "DamengOperationTimeoutError";
|
|
17
18
|
}
|
|
18
19
|
};
|
|
@@ -102,6 +103,8 @@ var DamengConnector = class _DamengConnector {
|
|
|
102
103
|
this.poolAlias = connectionConfig.poolAlias;
|
|
103
104
|
this.connectionTimeoutMs = config?.connectionTimeoutSeconds !== void 0 ? config.connectionTimeoutSeconds * 1e3 : 5e3;
|
|
104
105
|
this.operationTimeoutMs = config?.queryTimeoutSeconds !== void 0 ? config.queryTimeoutSeconds * 1e3 : DEFAULT_OPERATION_TIMEOUT_MS;
|
|
106
|
+
connectionConfig.connectTimeout ?? (connectionConfig.connectTimeout = this.connectionTimeoutMs);
|
|
107
|
+
connectionConfig.queueTimeout ?? (connectionConfig.queueTimeout = this.connectionTimeoutMs);
|
|
105
108
|
await this.closeRegisteredPool(connectionConfig.poolAlias);
|
|
106
109
|
await this.validateDirectConnection(connectionConfig);
|
|
107
110
|
createdPool = await dmdb.createPool(connectionConfig);
|
|
@@ -494,6 +497,20 @@ var DamengConnector = class _DamengConnector {
|
|
|
494
497
|
});
|
|
495
498
|
}
|
|
496
499
|
async withConnection(fn) {
|
|
500
|
+
try {
|
|
501
|
+
return await this.withConnectionAttempt(fn);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
if (!this.isConnectionAcquisitionFailure(error)) {
|
|
504
|
+
throw error;
|
|
505
|
+
}
|
|
506
|
+
console.error(
|
|
507
|
+
`Retrying Dameng source '${this.sourceId}' after connection acquisition failure: ${error instanceof Error ? error.message : String(error)}`
|
|
508
|
+
);
|
|
509
|
+
await this.ensurePool();
|
|
510
|
+
return this.withConnectionAttempt(fn);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async withConnectionAttempt(fn) {
|
|
497
514
|
await this.ensurePool();
|
|
498
515
|
const pool = this.pool;
|
|
499
516
|
if (!pool) {
|
|
@@ -502,16 +519,15 @@ var DamengConnector = class _DamengConnector {
|
|
|
502
519
|
let conn = null;
|
|
503
520
|
let shouldRelease = true;
|
|
504
521
|
try {
|
|
505
|
-
conn = await this.
|
|
506
|
-
pool.getConnection(),
|
|
507
|
-
this.connectionTimeoutMs,
|
|
508
|
-
"Dameng connection acquisition"
|
|
509
|
-
);
|
|
522
|
+
conn = await this.acquireConnectionWithTimeout(pool);
|
|
510
523
|
return await fn(conn);
|
|
511
524
|
} catch (error) {
|
|
512
525
|
if (error instanceof DamengOperationTimeoutError) {
|
|
513
526
|
shouldRelease = false;
|
|
514
527
|
this.markPoolUnhealthy(error.message);
|
|
528
|
+
} else if (!conn && this.isConnectionAcquisitionFailure(error)) {
|
|
529
|
+
shouldRelease = false;
|
|
530
|
+
this.markPoolUnhealthy(error instanceof Error ? error.message : String(error));
|
|
515
531
|
}
|
|
516
532
|
throw error;
|
|
517
533
|
} finally {
|
|
@@ -520,6 +536,21 @@ var DamengConnector = class _DamengConnector {
|
|
|
520
536
|
}
|
|
521
537
|
}
|
|
522
538
|
}
|
|
539
|
+
async acquireConnectionWithTimeout(pool) {
|
|
540
|
+
const acquisition = pool.getConnection();
|
|
541
|
+
try {
|
|
542
|
+
return await this.withTimeout(
|
|
543
|
+
acquisition,
|
|
544
|
+
this.connectionTimeoutMs,
|
|
545
|
+
"Dameng connection acquisition"
|
|
546
|
+
);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
if (error instanceof DamengOperationTimeoutError) {
|
|
549
|
+
void acquisition.then((conn) => this.releaseConnectionQuietly(conn)).catch(() => void 0);
|
|
550
|
+
}
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
523
554
|
async ensurePool() {
|
|
524
555
|
if (this.pool) {
|
|
525
556
|
return;
|
|
@@ -581,7 +612,7 @@ var DamengConnector = class _DamengConnector {
|
|
|
581
612
|
let timer;
|
|
582
613
|
const timeout = new Promise((_, reject) => {
|
|
583
614
|
timer = setTimeout(() => {
|
|
584
|
-
reject(new DamengOperationTimeoutError(`${label} timed out after ${timeoutMs}ms
|
|
615
|
+
reject(new DamengOperationTimeoutError(`${label} timed out after ${timeoutMs}ms`, label));
|
|
585
616
|
}, timeoutMs);
|
|
586
617
|
});
|
|
587
618
|
try {
|
|
@@ -614,6 +645,18 @@ var DamengConnector = class _DamengConnector {
|
|
|
614
645
|
);
|
|
615
646
|
}
|
|
616
647
|
}
|
|
648
|
+
isConnectionAcquisitionFailure(error) {
|
|
649
|
+
if (error instanceof DamengOperationTimeoutError) {
|
|
650
|
+
return error.label === "Dameng connection acquisition";
|
|
651
|
+
}
|
|
652
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
653
|
+
return [
|
|
654
|
+
"Connection request timeout in queue",
|
|
655
|
+
"Pool cannot open more connections",
|
|
656
|
+
"\u83B7\u53D6\u8FDE\u63A5\u8BF7\u6C42\u7B49\u5F85\u8D85\u65F6",
|
|
657
|
+
"\u8FDE\u63A5\u6C60\u5DF2\u8FBE\u5230\u6700\u5927\u8FDE\u63A5\u6570"
|
|
658
|
+
].some((item) => message.includes(item));
|
|
659
|
+
}
|
|
617
660
|
executeOptions(extra = {}) {
|
|
618
661
|
return {
|
|
619
662
|
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-27LNS5MO.js"), name: "Dameng", driver: "dmdb" }
|
|
1869
1869
|
];
|
|
1870
1870
|
loadConnectors(connectorModules).then(() => main()).catch((error) => {
|
|
1871
1871
|
console.error("Fatal error:", error);
|