Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class ConnectionAdapter implements IDBConnection {
/** @var Connection */
private $inner;

/**
* The currently active transaction isolation level or NULL before it has been determined.
*
* @var \Doctrine\DBAL\TransactionIsolationLevel::*|null
*/
private ?int $transactionIsolationLevel = null;

public function __construct(Connection $inner) {
$this->inner = $inner;
}
Expand Down Expand Up @@ -262,4 +269,14 @@ public function getShardDefinition(string $name): ?ShardDefinition {
public function getCrossShardMoveHelper(): CrossShardMoveHelper {
return $this->inner->getCrossShardMoveHelper();
}

public function setTransactionIsolation(int $level): int {
$this->transactionIsolationLevel = $level;

return $this->executeStatement($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level));
}

public function getTransactionIsolation(): int {
return $this->transactionIsolationLevel ??= $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
}
}
5 changes: 5 additions & 0 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OC\Files\Config;

use Doctrine\DBAL\TransactionIsolationLevel;
use OC\User\LazyUser;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -99,6 +100,8 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider
$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);

if ($addedMounts || $removedMounts || $changedMounts) {
$this->connection->setTransactionIsolation(TransactionIsolationLevel::REPEATABLE_READ);

$this->connection->beginTransaction();
$userUID = $user->getUID();
try {
Expand All @@ -124,6 +127,8 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider
} catch (\Throwable $e) {
$this->connection->rollBack();
throw $e;
} finally {
$this->connection->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
}

// Only fire events after all mounts have already been adjusted in the database.
Expand Down
22 changes: 22 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,26 @@ public function getShardDefinition(string $name): ?ShardDefinition;
* @since 30.0.0
*/
public function getCrossShardMoveHelper(): CrossShardMoveHelper;

/**
* Sets the transaction isolation level.
*
* @param \Doctrine\DBAL\TransactionIsolationLevel::* $level The level to set.
*
* @throws \Doctrine\DBAL\Exception
*
* @since 33.0.0
*/
public function setTransactionIsolation(int $level): int;

/**
* Gets the currently active transaction isolation level.
*
* @return \Doctrine\DBAL\TransactionIsolationLevel::* The current transaction isolation level.
*
* @throws \Doctrine\DBAL\Exception
*
* @since 33.0.0
*/
public function getTransactionIsolation(): int;
}
Loading