Skip to content

Commit 6bd8f19

Browse files
committed
fix(UserMountCache): Set transaction isolation level to REPEATABLE_READ before executing insertIfNotExist without unique index
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 65d008b commit 6bd8f19

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

lib/private/Files/Config/UserMountCache.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
namespace OC\Files\Config;
99

10+
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
11+
use Doctrine\DBAL\TransactionIsolationLevel;
1012
use OC\User\LazyUser;
1113
use OCP\Cache\CappedMemoryCache;
1214
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -99,6 +101,11 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider
99101
$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
100102

101103
if ($addedMounts || $removedMounts || $changedMounts) {
104+
$isPrimary = $this->connection instanceof PrimaryReadReplicaConnection && $this->connection->isConnectedToPrimary();
105+
if ($isPrimary) {
106+
$this->connection->setTransactionIsolation(TransactionIsolationLevel::REPEATABLE_READ);
107+
}
108+
102109
$this->connection->beginTransaction();
103110
$userUID = $user->getUID();
104111
try {
@@ -124,6 +131,10 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider
124131
} catch (\Throwable $e) {
125132
$this->connection->rollBack();
126133
throw $e;
134+
} finally {
135+
if ($isPrimary) {
136+
$this->connection->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
137+
}
127138
}
128139

129140
// Only fire events after all mounts have already been adjusted in the database.

0 commit comments

Comments
 (0)