mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
Merge pull request #57733 from nextcloud/carl/propagator-rollback
fix(Propagator): rollback transaction if it fails
This commit is contained in:
commit
9b547f5c8d
1 changed files with 31 additions and 26 deletions
|
|
@ -160,40 +160,45 @@ class Propagator implements IPropagator {
|
|||
}
|
||||
$this->inBatch = false;
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
try {
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$storageId = $this->storage->getCache()->getNumericStorageId();
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$storageId = $this->storage->getCache()->getNumericStorageId();
|
||||
|
||||
$query->update('filecache')
|
||||
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
|
||||
->set('etag', $query->expr()->literal(uniqid()))
|
||||
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
|
||||
$query->update('filecache')
|
||||
->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time')))
|
||||
->set('etag', $query->expr()->literal(uniqid()))
|
||||
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')));
|
||||
|
||||
$sizeQuery = $this->connection->getQueryBuilder();
|
||||
$sizeQuery->update('filecache')
|
||||
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
|
||||
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
|
||||
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
|
||||
$sizeQuery = $this->connection->getQueryBuilder();
|
||||
$sizeQuery->update('filecache')
|
||||
->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size')))
|
||||
->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash')))
|
||||
->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT)));
|
||||
|
||||
foreach ($this->batch as $item) {
|
||||
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
|
||||
$query->setParameter('hash', $item['hash']);
|
||||
foreach ($this->batch as $item) {
|
||||
$query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT);
|
||||
$query->setParameter('hash', $item['hash']);
|
||||
|
||||
$query->executeStatement();
|
||||
$query->executeStatement();
|
||||
|
||||
if ($item['size']) {
|
||||
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
|
||||
$sizeQuery->setParameter('hash', $item['hash']);
|
||||
if ($item['size']) {
|
||||
$sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT);
|
||||
$sizeQuery->setParameter('hash', $item['hash']);
|
||||
|
||||
$sizeQuery->executeStatement();
|
||||
$sizeQuery->executeStatement();
|
||||
}
|
||||
}
|
||||
|
||||
$this->batch = [];
|
||||
|
||||
$this->connection->commit();
|
||||
} catch (\Exception $e) {
|
||||
$this->connection->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->batch = [];
|
||||
|
||||
$this->connection->commit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue