云
昨天 74b0d9c5ab1dc316b29f8525dcffe45225d4c43c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""Cancel only this script's advisory-lock-owned transaction for optimized batch retry."""
import sys,json
from pathlib import Path
P=Path(__file__).parent
sys.path.insert(0,str(P.parent/'iqc-import-20261012/deps'))
import pymysql
c=pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor,connect_timeout=10,read_timeout=60)
with c.cursor() as q:
 q.execute('SELECT COUNT(*) n FROM mes_pro_mps WHERE deleted=0');committed=q.fetchone()['n']
 q.execute("SELECT IS_USED_LOCK('sales-mps-20261012') holder");holder=q.fetchone()['holder']
 if holder and committed==0:
  q.execute('SELECT trx_mysql_thread_id FROM information_schema.innodb_trx WHERE trx_mysql_thread_id=%s',(holder,));own=q.fetchone()
  assert own and own['trx_mysql_thread_id']==holder
  q.execute('KILL CONNECTION '+str(int(holder)))
  print(json.dumps({'own_transaction_cancelled_for_bulk_retry':True,'lock_holder':holder,'committed_mps':committed}))
 else:print(json.dumps({'own_transaction_cancelled_for_bulk_retry':False,'lock_holder':holder,'committed_mps':committed}))
c.close()