Page MenuHomePhabricator

Replace ILBFactory by injecting new Db-Service in Client's UpdateRepo class and add MaxLag functionality
Closed, ResolvedPublic

Description

UpdateRepo uses LoadBalancer only in a single place, but hasn't been done with DomainDb until now:

UpdateRepo.php
	/**
	 * Get the time (in seconds) for which the job execution should be delayed
	 * (if delayed jobs are enabled). Defaults to the max replag of any pooled
	 * DB server + 2 seconds.
	 *
	 * @return int
	 */
	protected function getJobDelay() {
		$lagArray = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaxLag();
		// This should be good enough, especially given that lagged servers get
		// less load by the load balancer, thus it's very unlikely we'll end
		// up on the server with the highest lag.
		// We add +2 here, to make sure we have a minimum delay of a full
		// second (this is being added to time() so +1 actually just means
		// wait until this second is over).
		return $lagArray[1] + 2;
	}

This getMaxLag should be somehow added to the DomainDb and then used in UpdateRepo

Incomplete list of Things to Consider when working on this:

  • Should getMaxLag be added to the ReplicationWaiter or its own little service/interface?
  • Should we return the complete lag array ({0:string,1:float|int|false,2:int} (host, max lag, index of max lagged host)) or just one piece of info or maybe same info in a different structure / value object?
  • Do we maybe want to implement more of the lag-related methods in the future? (We want to avoid having an interface specifying 61 methods, but also some methods maybe "belong" together.)

Event Timeline

I'm a little bit hesitant to add getMaxLag to DomainDb as it would violate ISP but OTOH, I don't have a better idea.

I'm a little bit hesitant to add getMaxLag to DomainDb as it would violate ISP but OTOH, I don't have a better idea.

Mh, probably not to DomainDb directly. Either to the ReplicationWaiter interface (after all, it tells us something about how much the replication is lagging), or a new interface specialized to methods concerning lag, e.g. ReplicationLag interface or something

Change 700869 had a related patch set uploaded (by Ladsgroup; author: Ladsgroup):

[mediawiki/extensions/Wikibase@master] client: Replace ILBFactory with ClientDomainDb in UpdateRepo

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

Since this is a method on the load balancer (not the load balancer factory), I assume $db->loadBalancer()->getMaxLag() would also be an option…

Change 701060 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Remove repo DB from UpdateRepo* classes

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

Yes and no, it makes sense internally (to the core's internals and implementation) but it's conceptually less cohesive, if it's related to replication, then it should be on ReplicationWaiter, not connection manager or others.

Change 700869 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] client: Replace ILBFactory with ClientDomainDb in UpdateRepo

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

Change 701060 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Remove repo DB from UpdateRepo* classes

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