From 6c72961d125dbaf1cab43294f63babf4b787b803 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 17 Oct 2023 18:10:55 +0300 Subject: [PATCH] allow query of donor nodes if allwed by config --- src/MariaDB.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/MariaDB.ts b/src/MariaDB.ts index 7dd72f1..3b9287a 100644 --- a/src/MariaDB.ts +++ b/src/MariaDB.ts @@ -24,7 +24,8 @@ export type MariaOptions = { cluster?: PoolClusterConfig, client?: PoolConfig, credentials: Credentials, - loggerOptions?: LoggerClientOptions + loggerOptions?: LoggerClientOptions, + donorQuery?: boolean } type MariaError = { @@ -93,8 +94,9 @@ class MariaDB #cluster: boolean; #pool: PoolCluster | null; #nodes: Node[]; + #canQueryDonor: boolean; - constructor (server: IServer, options: MariaOptions) + constructor (server: IServer, options: MariaOptions) { if (!server) @@ -124,6 +126,7 @@ class MariaDB this.#afterLastQuery = null; this.#cluster = this.#credentials.length > 1; + this.#canQueryDonor = options.donorQuery ?? false; this.#logger = server.createLogger(this, options.loggerOptions); } @@ -338,7 +341,7 @@ class MariaDB const pool = this.#pool; if (nodeName) { - const available = this.#nodes.filter(n => n.status === 'synced' || !n.status); + const available = this.#nodes.filter(n => n.status === 'synced' || !n.status || (this.#canQueryDonor && n.status === 'donor')); if (!available.length) throw new Error('No nodes available for query'); const node = this.#nodes.find(n => n.name === nodeName); @@ -350,7 +353,7 @@ class MariaDB this.#logger.warn(str); nodeName = '*'; } - else if (node.status && node.status !== 'synced') + else if (node.status && node.status !== 'synced' && !(this.#canQueryDonor && node.status === 'donor')) { const str = `Node ${nodeName} is currently not synced with the pool and thus unqueryable`; if (throwError)