Page MenuHomePhabricator

Deprecate ILoadBalancer::getAnyOpenConnection()
Closed, ResolvedPublic

Description

Follow-up from T236880: Document when to use different ILoadBalancer::get*Connection* methods.

This method should be private to avoid exposing details and complexity. It requires awareness of different connection pool types (e.g. autocommit vs round). Any new internal types would also leak out through here.

Known caller (besides private use within the LoadBalancer class implementation)

  • mediawiki/core: Rdbms\LoadMonitor
  • mediawiki/core: PageEditStash
  • mediawiki/core: JobRunner
  • mediawiki/core: ChronologyProtector
  • EventBus: JobExecutor.php

Event Timeline

Krinkle updated the task description. (Show Details)
Krinkle subscribed.

LoadMonitor's reliance on LoadBalance::getAnyOpenConnection was removed as part of T265386 and T314020: LoadMonitor connection weighting reimagined:

Change 868514 merged by jenkins-bot:

[mediawiki/core@master] rdbms: add CONN_UNTRACKED_GAUGE LoadBalancer flag for LoadMonitor gauging

https://gerrit.wikimedia.org/r/868514

Change 876362 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] Storage: Change LoadBalancer::getAnyOpenConnection to getConnectionRef

https://gerrit.wikimedia.org/r/876362

Change 876362 merged by jenkins-bot:

[mediawiki/core@master] Storage: Change LoadBalancer::getAnyOpenConnection to getConnectionRef

https://gerrit.wikimedia.org/r/876362

Change 974671 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/extensions/EventBus@master] Remove JobSerialCommitThreshold

https://gerrit.wikimedia.org/r/974671

Change 974677 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] Remove wgJobSerialCommitThreshold

https://gerrit.wikimedia.org/r/974677

Change 974671 merged by jenkins-bot:

[mediawiki/extensions/EventBus@master] Remove support for $wgJobSerialCommitThreshold

https://gerrit.wikimedia.org/r/974671

Change 974677 merged by jenkins-bot:

[mediawiki/core@master] jobqueue: Remove $wgJobSerialCommitThreshold

https://gerrit.wikimedia.org/r/974677

Only call left is in CP. There is no easy replacement there. CP is part of rdbms and the function is explicitly marked as @internal, We are also phasing direct dependencies to LB anyway, not sure it's worth doing

Only call left is in CP. There is no easy replacement there. CP is part of rdbms and the function is explicitly marked as @internal, We are also phasing direct dependencies to LB anyway, not sure it's worth doing

We could invert it slightly to remove this. Would that work?

Today
class ChronologyProtector
	public function stageSessionPrimaryPos( LoadBalancer $lb )
		$primaryConn = $lb->getAnyOpenConnection(  );
		$pos = $primaryConn->getPrimaryPos();
		$this->shutdownPositions[] = $pos;
		

class LBFactory
  public function shutdown()
    foreach ( $this->getLBsForOwner() as $lb )
      $this->chronologyProtector->stageSessionPrimaryPos( $lb );

And let LB return the position first:

Fix 1
class ChronologyProtector
	public function stageSessionPrimaryPos( DBPrimaryPos $pos ) {
		$this->shutdownPositions[] = $pos;
		

class LBFactory
  public function shutdown()
    foreach ( $this->getLBsForOwner() as $lb )
      $this->chronologyProtector->stageSessionPrimaryPos( $lb->getPrimaryPos() );

Or if accessible from there:

Fix 2
class ChronologyProtector
	public function stageSessionPrimaryPos( LoadBalancer $lb )
		$pos = $lb->getPrimaryPos()
		$this->shutdownPositions[] = $pos;
		

class LBFactory
  public function shutdown()
    foreach ( $this->getLBsForOwner() as $lb )
      $this->chronologyProtector->stageSessionPrimaryPos( $lb );

Both ways moves the responsibility to LB to deal with known positions. The downside is getPrimaryPos() actually already exists, and it's a bit of a strange method that actually uses getAnyOpenConnection but then *also* proactively opens a new connection, because it's used by waitForReplication to create proactive wait cycles prior to any db writes at the start of some loops/jobs/scripts. So we'd need some kind of getPrimaryPos( POS_OPEN_ONLY | POS_ALLOW_CONNECT ) flag to differentiate the two use cases. Which.. yeah, might as well use getAnyOpenConnection.

Perhaps an alternative is to make getAnyOpenConnection() @internal and maybe move to ILoadBalancerForOwner at some point.

Indeed my biggest problem was that I don't want CP open a primary connection on shutdown on every LB in config (s1-s8, x1, x2, es1-5, etc.) but your fix gave me an idea. Patch coming.

Change 975266 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] rdbms: Drop ILoadBalancer::getAnyOpenConnection()

https://gerrit.wikimedia.org/r/975266

I basically check for connection to primary already existing in LBF itself where there is a function to do exactly that

Change 975266 merged by jenkins-bot:

[mediawiki/core@master] rdbms: Drop ILoadBalancer::getAnyOpenConnection()

https://gerrit.wikimedia.org/r/975266

Ladsgroup claimed this task.
Ladsgroup updated the task description. (Show Details)
Ladsgroup edited projects, added DBA; removed Patch-For-Review.
Ladsgroup moved this task from Triage to Done on the DBA board.