Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors lib/private/Lock #39108

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/private/Lock/AbstractLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
* to release any leftover locks at the end of the request
*/
abstract class AbstractLockingProvider implements ILockingProvider {
/** how long until we clear stray locks in seconds */
protected int $ttl;

protected $acquiredLocks = [
protected array $acquiredLocks = [
'shared' => [],
'exclusive' => []
];

/**
*
* @param int $ttl how long until we clear stray locks in seconds
*/
public function __construct(protected int $ttl) {
}

/** @inheritDoc */
protected function hasAcquiredLock(string $path, int $type): bool {
if ($type === self::LOCK_SHARED) {
Expand Down
14 changes: 4 additions & 10 deletions lib/private/Lock/DBLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,15 @@
* Locking provider that stores the locks in the database
*/
class DBLockingProvider extends AbstractLockingProvider {
private IDBConnection $connection;
private ITimeFactory $timeFactory;
private array $sharedLocks = [];
private bool $cacheSharedLocks;

public function __construct(
IDBConnection $connection,
ITimeFactory $timeFactory,
private IDBConnection $connection,
private ITimeFactory $timeFactory,
int $ttl = 3600,
bool $cacheSharedLocks = true
private bool $cacheSharedLocks = true
) {
$this->connection = $connection;
$this->timeFactory = $timeFactory;
$this->ttl = $ttl;
$this->cacheSharedLocks = $cacheSharedLocks;
parent::__construct($ttl);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Lock/MemcacheLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
use OCP\Lock\LockedException;

class MemcacheLockingProvider extends AbstractLockingProvider {
private IMemcache $memcache;

public function __construct(IMemcache $memcache, int $ttl = 3600) {
$this->memcache = $memcache;
$this->ttl = $ttl;
public function __construct(
private IMemcache $memcache,
int $ttl = 3600,
) {
parent::__construct($ttl);
}

private function setTTL(string $path): void {
Expand Down