Merge pull request #30768 from nextcloud/feat/chunked-mysql-joblist-remove

Do chuncked job deletion
This commit is contained in:
Carl Schwan 2022-03-18 12:29:42 +01:00 committed by GitHub
commit d70e9d6516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -29,6 +29,7 @@
*/
namespace OC\BackgroundJob;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\AutoloadNotAllowedException;
@ -114,7 +115,22 @@ class JobList implements IJobList {
$argumentJson = json_encode($argument);
$query->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(md5($argumentJson))));
}
$query->execute();
// Add galera safe delete chunking if using mysql
// Stops us hitting wsrep_max_ws_rows when large row counts are deleted
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
// Then use chunked delete
$max = IQueryBuilder::MAX_ROW_DELETION;
$query->setMaxResults($max);
do {
$deleted = $query->execute();
} while ($deleted === $max);
} else {
// Dont use chunked delete - let the DB handle the large row count natively
$query->execute();
}
}
/**

View file

@ -73,6 +73,11 @@ interface IQueryBuilder {
*/
public const PARAM_STR_ARRAY = Connection::PARAM_STR_ARRAY;
/**
* @since 24.0.0 Indicates how many rows can be deleted at once with MySQL
* database server.
*/
public const MAX_ROW_DELETION = 100000;
/**
* Enable/disable automatic prefixing of table names with the oc_ prefix