This should get us back on track (tested on ARCH Linux)
This commit is contained in:
+11
-18
@@ -4,9 +4,8 @@ import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
import mariadb
|
||||
import mysql.connector
|
||||
# noinspection PyProtectedMember
|
||||
from mariadb._mariadb import ConnectionPool, OperationalError
|
||||
from pkg_resources import parse_version
|
||||
|
||||
from conf.config import BotConfig
|
||||
@@ -23,7 +22,7 @@ class DB:
|
||||
def __init__(self):
|
||||
self.pool_size = 4
|
||||
# noinspection PyTypeChecker
|
||||
self.pool: ConnectionPool = None
|
||||
self.pool = None
|
||||
self.enhanced_like_regex = re.compile(r"(\s+)(\S+)\s+<EXTENDED_LIKE=(\d+)>\s+\?(\s*)", re.IGNORECASE)
|
||||
self.lastrowid = None
|
||||
self.logger = Logger(__name__)
|
||||
@@ -40,10 +39,14 @@ class DB:
|
||||
self.type = self.MARIADB
|
||||
self.connect_detail = {'host': host, 'port': port, 'user': username,
|
||||
'password': password, 'database': database_name, 'autocommit': True}
|
||||
self.pool = mariadb.ConnectionPool(pool_name=database_name, pool_size=self.pool_size,
|
||||
pool_reset_connection=False,
|
||||
host=host, port=port, user=username, password=password,
|
||||
database=database_name, autocommit=True)
|
||||
self.pool = mysql.connector.pooling.MySQLConnectionPool(pool_name=database_name, pool_size=self.pool_size,
|
||||
host=host, port=port, user=username, password=password,
|
||||
database=database_name, autocommit=True
|
||||
)
|
||||
# self.pool = mariadb.ConnectionPool(pool_name=database_name, pool_size=self.pool_size,
|
||||
# pool_reset_connection=False,
|
||||
# host=host, port=port, user=username, password=password,
|
||||
# database=database_name, autocommit=True)
|
||||
self.exec("SET collation_connection = 'utf8_general_ci'")
|
||||
self.exec("SET sql_mode = 'TRADITIONAL,ANSI'")
|
||||
self.create_db_version_table()
|
||||
@@ -58,9 +61,6 @@ class DB:
|
||||
def _execute_wrapper(self, sql, params, callback):
|
||||
with self.lock:
|
||||
start_time = time.time()
|
||||
if self.pool.pool_size < self.pool_size - 1:
|
||||
self.pool.add_connection(mariadb.connect(**self.connect_detail))
|
||||
|
||||
with self.pool.get_connection() as conn:
|
||||
conn.auto_reconnect = True
|
||||
conn.autocommit = True
|
||||
@@ -74,16 +74,9 @@ class DB:
|
||||
if string.__contains__("UPDATE ") or string.__contains__("INSERT "):
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
print(sql, params)
|
||||
raise SqlException(f"SQL Error: '{str(e)}' for '{sql}' "
|
||||
f"[{', '.join(map(lambda x: str(x), params))}]") from e
|
||||
except mariadb.OperationalError as e:
|
||||
self.logger.error("Please use 'FLUSH TABLES;' inside of the DB, and consider upping the 'table_definition_cache' value of the Database Server.", e)
|
||||
time.sleep(30)
|
||||
exit(-3)
|
||||
except mariadb.PoolError as e:
|
||||
self.logger.error("No Connections available for the Connection Pool. Restarting in 30 seconds...", e)
|
||||
time.sleep(30)
|
||||
exit(-2)
|
||||
elapsed = time.time() - start_time
|
||||
result = callback(cur)
|
||||
if elapsed > 5:
|
||||
|
||||
Reference in New Issue
Block a user