fix hanging when starting multiple intances on the same db
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace ManiaControl\Database;
|
namespace ManiaControl\Database;
|
||||||
|
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
use ManiaControl\Logger;
|
use ManiaControl\Logger;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
@@ -13,7 +15,7 @@ use ManiaControl\ManiaControl;
|
|||||||
* @copyright 2014-2020 ManiaControl Team
|
* @copyright 2014-2020 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class Database implements TimerListener {
|
class Database implements CallbackListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
* Public properties
|
* Public properties
|
||||||
*/
|
*/
|
||||||
@@ -56,12 +58,14 @@ class Database implements TimerListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->getMysqli()->set_charset("utf8");
|
$this->getMysqli()->set_charset("utf8");
|
||||||
|
$this->reduceLockWaitTimeout();
|
||||||
|
|
||||||
$this->initDatabase();
|
$this->initDatabase();
|
||||||
// $this->optimizeTables();
|
// $this->optimizeTables();
|
||||||
|
|
||||||
// Register Method which checks the Database Connection every 5 seconds
|
// Register Method which checks the Database Connection every 5 seconds
|
||||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'checkConnection', 5000);
|
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'checkConnection', 5000);
|
||||||
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||||
|
|
||||||
// Children
|
// Children
|
||||||
$this->migrationHelper = new MigrationHelper($maniaControl);
|
$this->migrationHelper = new MigrationHelper($maniaControl);
|
||||||
@@ -201,6 +205,24 @@ class Database implements TimerListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reduce session lock wait timeout value to between 5 and 10 seconds
|
||||||
|
* designed to be used during the initialization to prevent maniacontrol to be stuck when launched in parallel with other instances
|
||||||
|
*/
|
||||||
|
public function reduceLockWaitTimeout() {
|
||||||
|
// limit session lock during initialization
|
||||||
|
$this->getMysqli()->query("SET SESSION lock_wait_timeout = ". rand(5, 10) .";");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset session lock wait timeout value to the default one
|
||||||
|
* designed to be used during the initialization to prevent maniacontrol to be stuck when launched in parallel with other instances
|
||||||
|
*/
|
||||||
|
public function resetLockWaitTimeout() {
|
||||||
|
// limit session lock during initialization
|
||||||
|
$this->getMysqli()->query("SET SESSION lock_wait_timeout = @@GLOBAL.lock_wait_timeout;");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the database config
|
* Return the database config
|
||||||
*
|
*
|
||||||
@@ -228,6 +250,10 @@ class Database implements TimerListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleAfterInit() {
|
||||||
|
$this->resetLockWaitTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destruct Database Connection
|
* Destruct Database Connection
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user