Skip to content

Commit

Permalink
add extra logs to check mysql parser results
Browse files Browse the repository at this point in the history
  • Loading branch information
alihm committed Jul 10, 2023
1 parent 4f08ae3 commit 5a04041
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ClusterOperator/Backlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class BackLog {
* @param {int} timestamp [description]
* @return {Array}
*/
static async pushQuery(query, seq = 0, timestamp, buffer = false, connId = false) {
static async pushQuery(query, seq = 0, timestamp, buffer = false, connId = false, fullQuery = '') {
// eslint-disable-next-line no-param-reassign
if (timestamp === undefined) timestamp = Date.now();
if (!this.BLClient) {
Expand Down Expand Up @@ -116,9 +116,9 @@ class BackLog {
this.writeLock = false;
let result = null;
if (connId === false) {
result = await this.UserDBClient.query(query);
result = await this.UserDBClient.query(query, false, fullQuery);
} else if (connId >= 0) {
result = await ConnectionPool.getConnectionById(connId).query(query);
result = await ConnectionPool.getConnectionById(connId).query(query, false, fullQuery);
}
return [result, seqForThis, timestamp];
}
Expand Down
11 changes: 6 additions & 5 deletions ClusterOperator/DBClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DBClient {
* [query]
* @param {string} query [description]
*/
async query(query, rawResult = false) {
async query(query, rawResult = false, fullQuery = '') {
if (config.dbType === 'mysql') {
// log.info(`running Query: ${query}`);
try {
Expand All @@ -109,11 +109,11 @@ class DBClient {
// eslint-disable-next-line no-else-return
} else {
const [rows, err] = await this.connection.query(query);
if (err && err.toString().includes('Error')) log.error(`Error running query: ${err.toString()}, ${query}`, 'red');
if (err && err.toString().includes('Error')) log.error(`Error running query: ${err.toString()}, ${fullQuery}`, 'red');
return rows;
}
} catch (err) {
if (err && err.toString().includes('Error')) log.error(`Error running query: ${err.toString()}, ${query}`, 'red');
if (err && err.toString().includes('Error')) log.error(`Error running query: ${err.toString()}, ${fullQuery}`, 'red');
return [null, null, err];
}
}
Expand All @@ -125,17 +125,18 @@ class DBClient {
* @param {string} query [description]
* @param {array} params [description]
*/
async execute(query, params, rawResult = false) {
async execute(query, params, rawResult = false, fullQuery = '') {
if (config.dbType === 'mysql') {
try {
if (!this.connected) {
await this.init();
}
const [rows, fields, err] = await this.connection.execute(query, params);
if (err) log.error(`Error executing query: ${JSON.stringify(err)}`);
if (err && err.toString().includes('Error')) log.error(`Error executing query: ${err.toString()}, ${fullQuery}`, 'red');
if (rawResult) return [rows, fields, err];
return rows;
} catch (err) {
if (err && err.toString().includes('Error')) log.error(`Error executing query: ${err.toString()}, ${fullQuery}`, 'red');
return [null, null, err];
}
}
Expand Down
6 changes: 3 additions & 3 deletions ClusterOperator/Operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Operator {
* [sendWriteQuery]
* @param {string} query [description]
*/
static async sendWriteQuery(query, connId) {
static async sendWriteQuery(query, connId, fullQuery) {
if (this.masterNode !== null) {
// log.info(`master node: ${this.masterNode}`);
if (!this.IamMaster) {
Expand All @@ -314,7 +314,7 @@ class Operator {
log.info(`out of queue: ${myTicket}, in queue: ${this.operator.masterQueue.length}`, 'cyan');
}
*/
const result = await BackLog.pushQuery(query, 0, Date.now(), false, connId);
const result = await BackLog.pushQuery(query, 0, Date.now(), false, connId, fullQuery);
// log.info(`sending query to slaves: ${JSON.stringify(result)}`);
if (result) this.serverSocket.emit('query', query, result[1], result[2], false);
return result[0];
Expand Down Expand Up @@ -367,7 +367,7 @@ class Operator {
await this.sendWriteQuery(this.operator.sessionQueries[id], -1);
this.operator.sessionQueries[id] = undefined;
}
await this.sendWriteQuery(queryItem[0], id);
await this.sendWriteQuery(queryItem[0], id, query);
// log.info(`finish write ${id}`);
// this.localDB.enableSocketWrite = false;
// let result = await this.localDB.query(queryItem[0], true);
Expand Down

0 comments on commit 5a04041

Please sign in to comment.