Merge pull request #3465 from nextcloud/storage-log-locks

Add option to enable locking debug logging
This commit is contained in:
Lukas Reschke 2017-02-14 15:08:21 +01:00 committed by GitHub
commit 257e28f46d
5 changed files with 97 additions and 3 deletions

View File

@ -1447,6 +1447,17 @@ $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
* or should be used together with the ``log.condition`` setting.
*/
'filelocking.debug' => false,
/**
* Disable the web based updater
*/

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,25 +685,101 @@ 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(
sprintf(
'acquire %s lock on "%s" on storage "%s"',
$typeString,
$path,
$this->getId()
),
[
'app' => 'locking',
]
);
}
try {
$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
throw $e;
}
}
/**
* @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
*/
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(
sprintf(
'release %s lock on "%s" on storage "%s"',
$typeString,
$path,
$this->getId()
),
[
'app' => 'locking',
]
);
}
try {
$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
throw $e;
}
}
/**
* @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
*/
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(
sprintf(
'change lock on "%s" to %s on storage "%s"',
$path,
$typeString,
$this->getId()
),
[
'app' => 'locking',
]
);
}
try {
$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
throw $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;
}
/**

View File

@ -107,6 +107,7 @@ interface Storage extends \OCP\Files\Storage {
* @param string $path The path of the file to release the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
*/
public function releaseLock($path, $type, ILockingProvider $provider);

View File

@ -425,6 +425,7 @@ interface Storage extends IStorage {
* @param string $path The path of the file to acquire the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
* @since 8.1.0
*/
public function releaseLock($path, $type, ILockingProvider $provider);

View File

@ -46,6 +46,7 @@ interface ILockingStorage {
* @param string $path The path of the file to acquire the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
* @since 9.0.0
*/
public function releaseLock($path, $type, ILockingProvider $provider);