Skip to content

Commit

Permalink
Avoid directly using CONN_TRX_AUTOCOMMIT in TermsDomainDb
Browse files Browse the repository at this point in the history
This uses the newly added getAutoCommitPrimaryConnection() method
instead of directly using the CONN_TRX_AUTOCOMMIT, which also means that
we can get rid of the $flags param on the getWriteConnection() method.

Bug: T351802
Bug: T383246
Change-Id: I250b8a2ce03ff9ee7c03423a5b16a2cf4d42f0f8
  • Loading branch information
jakobw committed Jan 9, 2025
1 parent e0aadd5 commit 21aa0c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/includes/Rdbms/DomainDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Wikibase\Lib\Rdbms;

use Wikimedia\Rdbms\ConnectionManager;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILBFactory;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\SessionConsistentConnectionManager;
Expand Down Expand Up @@ -78,6 +79,10 @@ public function connections(): ConnectionManager {
return $this->connectionManager;
}

public function getAutoCommitPrimaryConnection(): IDatabase {
return $this->lbFactory->getAutoCommitPrimaryConnection( $this->domainId );
}

public function replication(): ReplicationWaiter {
return $this->replicationWaiter;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/includes/Rdbms/RepoDomainTermsDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ public function __construct( RepoDomainDb $repoDb ) {
$this->repoDb = $repoDb;
}

public function getWriteConnection( int $flags = 0 ): IDatabase {
return $this->repoDb->connections()->getWriteConnection( $flags );
public function getWriteConnection(): IDatabase {
return $this->repoDb->connections()->getWriteConnection();
}

public function getAutoCommitPrimaryConnection(): IDatabase {
return $this->repoDb->getAutoCommitPrimaryConnection();
}

public function getReadConnection( ?array $groups = null ): IReadableDatabase {
Expand Down
4 changes: 3 additions & 1 deletion lib/includes/Rdbms/TermsDomainDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
interface TermsDomainDb {

public function getWriteConnection( int $flags = 0 ): IDatabase;
public function getWriteConnection(): IDatabase;

public function getAutoCommitPrimaryConnection(): IDatabase;

public function getReadConnection( ?array $groups = null ): IReadableDatabase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use LogicException;
use Wikibase\Lib\Rdbms\TermsDomainDb;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\IReadableDatabase;

/**
Expand Down Expand Up @@ -169,7 +168,7 @@ private function insertNonExistingRecords(
// gets stuck in an infinite loop. To avoid this, we read it with CONN_TRX_AUTOCOMMIT
// Surprisingly it's not too rare not to happen in production: T247553

$dbw = $this->termsDb->getWriteConnection( ILoadBalancer::CONN_TRX_AUTOCOMMIT );
$dbw = $this->termsDb->getAutoCommitPrimaryConnection();

$insertedRecords = array_merge(
$insertedRecords,
Expand Down

0 comments on commit 21aa0c7

Please sign in to comment.