连接池增加失败移除配置和恢复时间

master 2.2.0
宇天 2018-03-15 11:44:32 +08:00
parent 2b0c88fd66
commit 21053fd3bf
4 changed files with 16 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2.2.0 / 2018-03-15
==================
* 连接池增加失败移除配置和恢复时间
2.1.3 / 2018-03-14 2.1.3 / 2018-03-14
================== ==================
* 优化异常输出 * 优化异常输出

View File

@ -30,7 +30,10 @@ class Mysqli {
//是否有从库 //是否有从库
this.useSlaveDB = config.length > 1 this.useSlaveDB = config.length > 1
this.pool = mysql.createPoolCluster() this.pool = mysql.createPoolCluster({
removeNodeErrorCount: 1, // 连续失败立即从节点中移除, 并在10秒后尝试恢复
restoreNodeTimeout: 10000
})
config.forEach((item, i) => { config.forEach((item, i) => {
let { host, port, user, charset, passwd: password, db: database } = item let { host, port, user, charset, passwd: password, db: database } = item

View File

@ -23,23 +23,23 @@ class Method {
} }
connect() { connect() {
this.defer = Promise.defer() const defer = Promise.defer()
this.pool.getConnection(this.slave, (err, conn) => { this.pool.getConnection(this.slave, (err, conn) => {
if (err) { if (err) {
return this.defer.reject(new SqlErr(`MySQL connect ${err}`)) return defer.reject(new SqlErr(`MySQL connect ${err}`))
} }
if (this.db) { if (this.db) {
conn.query('USE ' + this.db, err => { conn.query('USE ' + this.db, err => {
if (err) { if (err) {
return this.defer.reject(new SqlErr('Select DB ' + err)) return defer.reject(new SqlErr('Select DB ' + err))
} }
this.defer.resolve(conn) defer.resolve(conn)
}) })
} else { } else {
this.defer.resolve(conn) defer.resolve(conn)
} }
}) })
return this.defer.promise return defer.promise
} }
listDb() { listDb() {

View File

@ -1,6 +1,6 @@
{ {
"name": "mysqli", "name": "mysqli",
"version": "2.1.3", "version": "2.2.0",
"description": "MySQL tool", "description": "MySQL tool",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {