fix(db): Prevent two connections for single node databases

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
fix/db/two-primary-connections-transaction-isolation-level
Christoph Wurst 3 weeks ago
parent c0b54c7577
commit ffee499f01
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8

@ -58,6 +58,7 @@ use OCP\Profiler\IProfiler;
use OCP\Server;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;
use function count;
use function in_array;
class Connection extends PrimaryReadReplicaConnection {
@ -100,7 +101,7 @@ class Connection extends PrimaryReadReplicaConnection {
* @throws \Exception
*/
public function __construct(
array $params,
private array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
@ -163,6 +164,15 @@ class Connection extends PrimaryReadReplicaConnection {
}
}
protected function performConnect(?string $connectionName = null): bool {
if (($connectionName ?? 'replica') === 'replica'
&& count($this->params['replica']) === 1
&& $this->params['primary'] === $this->params['replica'][0]) {
return parent::performConnect('primary');
}
return parent::performConnect($connectionName);
}
public function getStats(): array {
return [
'built' => $this->queriesBuilt,

Loading…
Cancel
Save