Page MenuHomePhabricator

Warning: SQLPlatform::isWriteQuery fallback to regex (CentralNotice)
Closed, ResolvedPublic

Description

#4 /srv/mediawiki/php-1.41.0-wmf.2/extensions/CentralNotice/includes/CNCampaignPager.php(126): Wikimedia\Rdbms\DBConnRef->query(string, string)
#5 /srv/mediawiki/php-1.41.0-wmf.2/includes/pager/IndexPager.php(563): CNCampaignPager->doQuery()
#6 /srv/mediawiki/php-1.41.0-wmf.2/includes/pager/TablePager.php(79): IndexPager->getBody()
#7 /srv/mediawiki/php-1.41.0-wmf.2/extensions/CentralNotice/includes/specials/CentralNotice.php(141): TablePager->getBody()
#8 /srv/mediawiki/php-1.41.0-wmf.2/extensions/CentralNotice/includes/specials/CentralNotice.php(107): CentralNotice->outputListOfNotices()

This call to ->query() should either be ported to a different method, or specify one of the ISQLPlatform::QUERY_CHANGE_* constants if that’s not possible.

Event Timeline

Sheesh.

CNCampaignPager::doQuery()
	public function doQuery() {
		// group_concat output is limited to 1024 characters by default, increase
		// the limit temporarily so the list of all languages can be rendered.
		$db = $this->getDatabase();
		if ( $db->getType() === 'mysql' ) {
			$db->query( 'SET SESSION group_concat_max_len = 10000', __METHOD__ );
		}

		parent::doQuery();
	}

I don’t think we have an abstraction for this at all? setSessionOptions() exists, but only supports one option in DatabaseMysqlBase, connTimeout (mapping to MySQL net_read_timeout and net_write_timeout with the same value). (The method also issues SET x=y instead of SET SESSION x=y, but I think those are equivalent?)

I’m also confused what the right QUERY_CHANGE_* flags would be – DatabaseMysqlBase::setSessionOptions() sets QUERY_CHANGE_TRX and QUERY_CHANGE_NONE? Is that correct?

DatabaseMysqlBase::setSessionOptions()
	public function setSessionOptions( array $options ) {
		$sqlAssignments = [];

		if ( isset( $options['connTimeout'] ) ) {
			$encTimeout = (int)$options['connTimeout'];
			$sqlAssignments[] = "net_read_timeout=$encTimeout";
			$sqlAssignments[] = "net_write_timeout=$encTimeout";
		}

		if ( $sqlAssignments ) {
			$this->query(
				'SET ' . implode( ', ', $sqlAssignments ),
				__METHOD__,
				self::QUERY_CHANGE_TRX | self::QUERY_CHANGE_NONE
			);
		}
	}
Lucas_Werkmeister_WMDE renamed this task from Warning: Wikimedia\Rdbms\Platform\SQLPlatform::isWriteQuery fallback to regex (CentralNotice) to Warning: SQLPlatform::isWriteQuery fallback to regex (CentralNotice).Mar 31 2023, 2:26 PM

I’m also confused what the right QUERY_CHANGE_* flags would be – DatabaseMysqlBase::setSessionOptions() sets QUERY_CHANGE_TRX and QUERY_CHANGE_NONE? Is that correct?

AFAICT the TRX and NONE flags are only used here and have the same effect:

SQLPlatform::isWriteQuery()
		// Check if a SQL wrapper method already flagged the query as a non-write
		if (
			$this->fieldHasBit( $flags, self::QUERY_CHANGE_NONE ) ||
			$this->fieldHasBit( $flags, self::QUERY_CHANGE_TRX ) ||
			$this->fieldHasBit( $flags, self::QUERY_CHANGE_LOCKS )
		) {
			return false;
		}

So I guess it doesn’t really matter.

Let’s add group_concat_max_len as another option to setSessionOptions() so CentralNotice can use it?

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

[mediawiki/core@master] rdbms: Add groupConcatMaxLen to setSessionOptions()

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

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

[mediawiki/extensions/CentralNotice@master] Use IDatabase::setSessionOptions() to set group_concat_max_len

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

Change 908571 merged by jenkins-bot:

[mediawiki/core@master] rdbms: Add groupConcatMaxLen to setSessionOptions()

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

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

[mediawiki/extensions/CentralNotice@master] Use IDatabase::setSessionOptions() to set group_concat_max_len

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

This is stalled a bit because of CentralNotice’s unusual deployment method (probably waiting until the MediaWiki core change is fully rolled out with the train?).

Change 908572 merged by jenkins-bot:

[mediawiki/extensions/CentralNotice@master] Use IDatabase::setSessionOptions() to set group_concat_max_len

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

Let’s close this already – I’ll recheck logstash in a few days, and if the warning message still appears there, reopen if needed.