Browse Source

Add option to enable locking debug logging

Signed-off-by: Robin Appelman <robin@icewind.nl>
tags/v12.0.0beta1
Robin Appelman 7 years ago
parent
commit
8c1ed7507a
No account linked to committer's email address
2 changed files with 58 additions and 3 deletions
  1. 10
    0
      config/config.sample.php
  2. 48
    3
      lib/private/Files/Storage/Common.php

+ 10
- 0
config/config.sample.php View File

@@ -1447,6 +1447,16 @@ $CONFIG = array(
*/
'memcache.locking' => '\\OC\\Memcache\\Redis',

/**
* Enable locking debug logging
*
* Note that this can lead to a very large volume of log items being written which can lead
* to performance degradation and large log files on busy instance.
*
* Thus enabling this in production for longer periods of time is not recommended
*/
'filelocking.debug' => false,

/**
* Disable the web based updater
*/

+ 48
- 3
lib/private/Files/Storage/Common.php View File

@@ -53,6 +53,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;

/**
* Storage backend class for providing common filesystem operation methods
@@ -79,6 +80,9 @@ abstract class Common implements Storage, ILockingStorage {
protected $mountOptions = [];
protected $owner = null;

private $shouldLogLocks = null;
private $logger;

public function __construct($parameters) {
}

@@ -681,7 +685,18 @@ abstract class Common implements Storage, ILockingStorage {
* @throws \OCP\Lock\LockedException
*/
public function acquireLock($path, $type, ILockingProvider $provider) {
$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
$logger->info('acquire ' . $typeString . ' lock on ' . $path, ['app' => 'locking']);
}
try {
$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
}
}

/**
@@ -690,7 +705,18 @@ abstract class Common implements Storage, ILockingStorage {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function releaseLock($path, $type, ILockingProvider $provider) {
$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
$logger->info('release ' . $typeString . ' lock on ' . $path, ['app' => 'locking']);
}
try {
$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
}
}

/**
@@ -699,7 +725,26 @@ abstract class Common implements Storage, ILockingStorage {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function changeLock($path, $type, ILockingProvider $provider) {
$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
$logger->info('change lock on ' . $path . ' to ' . $typeString, ['app' => 'locking']);
}
try {
$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
}
}

private function getLockLogger() {
if (is_null($this->shouldLogLocks)) {
$this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
$this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null;
}
return $this->logger;
}

/**

Loading…
Cancel
Save