From bdd0634f61aa8ddd8dc997c0591f824ad6d17f02 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 1 Dec 2024 04:17:28 +0800 Subject: [PATCH] update --- plugins/data_query/sql_mysql.py | 45 +++++++++++++++++++--- plugins/data_query/static/js/app.js | 59 ++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/plugins/data_query/sql_mysql.py b/plugins/data_query/sql_mysql.py index d96ce5f75..e1d4007be 100755 --- a/plugins/data_query/sql_mysql.py +++ b/plugins/data_query/sql_mysql.py @@ -546,10 +546,33 @@ class nosqlMySQLCtr(): a.trx_started """ ) - - print(data) return mw.returnData(True, 'ok', data) + def killLockPid(self, args): + sid = args['sid'] + my_instance = self.getInstanceBySid(sid).conn() + if my_instance is False: + return mw.returnData(False,'无法链接') + + pid = args['pid'] + my_instance.execute('kill %s' % pid) + return mw.returnData(True, '执行成功!') + + def killAllLock(self, args): + sid = args['sid'] + my_instance = self.getInstanceBySid(sid).conn() + if my_instance is False: + return mw.returnData(False,'无法链接') + + data = self.getLockSql(args) + if data['status']: + pid_data = data['data'] + for x in pid_data: + my_instance.execute('kill %s' % x['processlist_id']) + return mw.returnData(True, '执行成功!') + + + def getDeadlockInfo(self, args): sid = args['sid'] my_instance = self.getInstanceBySid(sid).conn() @@ -589,9 +612,7 @@ class nosqlMySQLCtr(): else: msg = '主从复制报错,请检查\nSlave_IO_Running状态值是:%s, | Slave_SQL_Running状态值是:%s\nLast_Error错误信息是:%s\nLast_SQL_Error错误信息是:%s\n' \ % (slave_info['Slave_IO_Running'], slave_info['Slave_SQL_Running'], slave_info['Last_Error'], slave_info['Last_SQL_Error']) - error_dict = my_instance.find('select LAST_ERROR_NUMBER,LAST_ERROR_MESSAGE,LAST_ERROR_TIMESTAMP ' - 'from performance_schema.replication_applier_status_by_worker ' - 'ORDER BY LAST_ERROR_TIMESTAMP desc limit 1') + error_dict = my_instance.find('select LAST_ERROR_NUMBER,LAST_ERROR_MESSAGE,LAST_ERROR_TIMESTAMP from performance_schema.replication_applier_status_by_worker ORDER BY LAST_ERROR_TIMESTAMP desc limit 1') msg += '错误号是:%s \n' % error_dict['LAST_ERROR_NUMBER'] msg += '错误信息是:%s \n' % error_dict['LAST_ERROR_MESSAGE'] msg += '报错时间是:%s \n' % error_dict['LAST_ERROR_TIMESTAMP'] @@ -665,6 +686,16 @@ def get_lock_sql(args): t = nosqlMySQLCtr() return t.getLockSql(args) +# KILL阻塞SQL +def kill_lock_pid(args): + t = nosqlMySQLCtr() + return t.killLockPid(args) + +# KILL阻塞SQL +def kill_all_lock(args): + t = nosqlMySQLCtr() + return t.killAllLock(args) + # 查看死锁信息 def get_deadlock_info(args): t = nosqlMySQLCtr() @@ -676,6 +707,10 @@ def get_slave_status(args): return t.getSlaveStatus(args) + + + + # 测试 def test(args): sid = args['sid'] diff --git a/plugins/data_query/static/js/app.js b/plugins/data_query/static/js/app.js index b630235ee..d46aa31c0 100755 --- a/plugins/data_query/static/js/app.js +++ b/plugins/data_query/static/js/app.js @@ -666,12 +666,35 @@ function mysqlCommonFuncLockSQL(){ var tbody = ''; for (var i = 0; i < items.length; i++) { var t = ''; - t += ''+items[i]['table_schema']+''; - t += ''+items[i]['table_name']+''; + t += ''+items[i]['trx_id']+''; + t += ''+items[i]['trx_state']+''; + t += ''+items[i]['trx_started']+''; + t += ''+items[i]['processlist_id']+''; + t += ''+items[i]['info']+''; + t += ''+items[i]['user']+''; + t += ''+items[i]['host']+''; + t += ''+items[i]['db']+''; + t += ''+items[i]['command']+''; + t += ''+items[i]['state']+''; + t += ''+items[i]['sql_kill_blocking_query']+''; + t += '执行'; t += ''; tbody += t; } $('#mysql_data_id tbody').html(tbody); + + $('#mysql_data_id tbody .exec').click(function(){ + var index = $(this).attr('index'); + var pid = items[index]['processlist_id']; + myPostCB('kill_lock_pid', {'sid':sid, 'pid':pid}, function(rdata){ + var data = rdata.data; + showMsg(data.msg,function(){ + if (data.status){ + renderSQL(); + } + },{icon: data.status ? 1 : 2}, 2000); + }); + }); } else { layer.msg(data.msg,{icon:2}); } @@ -681,20 +704,46 @@ function mysqlCommonFuncLockSQL(){ layer.open({ type: 1, title: "查看当前锁阻塞的SQL", - area: ['800px', '400px'], + area: ['1000px', '400px'], closeBtn: 1, shadeClose: false, content: '
\ +
\ + \ +
\ +
\ \ \ - \ - \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ \ \
库名表名事务ID事务状态执行时间线程IDInfouserhostdbcommandstatekill操作
\
', success:function(i,l){ renderSQL(); + + $('#kill_all').unbind('click').click(function(){ + var sid = mysqlGetSid(); + myPostCB('kill_all_lock', {'sid':sid}, function(rdata){ + var data = rdata.data; + showMsg(data.msg,function(){ + if (data.status){ + renderSQL(); + } + },{icon: data.status ? 1 : 2}, 2000); + }); + }); } }); }