From e9e5a02d7c18b06cd995e07232e033efb609f65f Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 17 Sep 2020 16:03:34 +0200 Subject: [PATCH 1/3] Allow to run occ preview:repair in parallel Signed-off-by: Morris Jobke --- core/Command/Preview/Repair.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index 845b9dbda9..1d4bbec813 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -33,6 +33,8 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\ILogger; +use OCP\Lock\ILockingProvider; +use OCP\Lock\LockedException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; @@ -54,11 +56,14 @@ class Repair extends Command { private $memoryLimit; /** @var int */ private $memoryTreshold; + /** @var ILockingProvider */ + private $lockingProvider; - public function __construct(IConfig $config, IRootFolder $rootFolder, ILogger $logger, IniGetWrapper $phpIni) { + public function __construct(IConfig $config, IRootFolder $rootFolder, ILogger $logger, IniGetWrapper $phpIni, ILockingProvider $lockingProvider) { $this->config = $config; $this->rootFolder = $rootFolder; $this->logger = $logger; + $this->lockingProvider = $lockingProvider; $this->memoryLimit = $phpIni->getBytes('memory_limit'); $this->memoryTreshold = $this->memoryLimit - 25 * 1024 * 1024; @@ -218,6 +223,15 @@ class Repair extends Command { return 1; } + $lockName = 'occ preview:repair lock ' . $oldPreviewFolder->getId(); + try { + $section1->writeln(" Locking \"$lockName\" …"); + $this->lockingProvider->acquireLock($lockName, ILockingProvider::LOCK_EXCLUSIVE); + } catch (LockedException $e) { + $section1->writeln(" Skipping because it is locked - another process seems to work on this …"); + continue; + } + $previews = $oldPreviewFolder->getDirectoryListing(); if ($previews !== []) { try { @@ -264,6 +278,10 @@ class Repair extends Command { } } } + + $this->lockingProvider->releaseLock($lockName, ILockingProvider::LOCK_EXCLUSIVE); + $section1->writeln(" Unlocked"); + $section1->writeln(" Finished migrating previews of file with fileId $name …"); $progressBar->advance(); } From 55393939cec9517fc43746bc29b99e65aef0891c Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 17 Sep 2020 16:30:11 +0200 Subject: [PATCH 2/3] Show lock messages only in verbose mode Signed-off-by: Morris Jobke --- core/Command/Preview/Repair.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index 1d4bbec813..c04da7ab53 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -225,7 +225,7 @@ class Repair extends Command { $lockName = 'occ preview:repair lock ' . $oldPreviewFolder->getId(); try { - $section1->writeln(" Locking \"$lockName\" …"); + $section1->writeln(" Locking \"$lockName\" …", OutputInterface::VERBOSITY_VERBOSE); $this->lockingProvider->acquireLock($lockName, ILockingProvider::LOCK_EXCLUSIVE); } catch (LockedException $e) { $section1->writeln(" Skipping because it is locked - another process seems to work on this …"); @@ -280,7 +280,7 @@ class Repair extends Command { } $this->lockingProvider->releaseLock($lockName, ILockingProvider::LOCK_EXCLUSIVE); - $section1->writeln(" Unlocked"); + $section1->writeln(" Unlocked", OutputInterface::VERBOSITY_VERBOSE); $section1->writeln(" Finished migrating previews of file with fileId $name …"); $progressBar->advance(); From b35daf665f683af496fcb6e3f45bb4a1f9f7a186 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 17 Sep 2020 16:30:33 +0200 Subject: [PATCH 3/3] Migrate verbose messages to inline syntax of writeln() Signed-off-by: Morris Jobke --- core/Command/Preview/Repair.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index c04da7ab53..8c83ce2ebe 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -100,8 +100,6 @@ class Repair extends Command { $output->writeln(""); } - $verbose = $output->isVerbose(); - $instanceId = $this->config->getSystemValueString('instanceid'); $output->writeln("This will migrate all previews from the old preview location to the new one."); @@ -237,9 +235,7 @@ class Repair extends Command { try { $this->rootFolder->get("appdata_$instanceId/preview/$newFoldername"); } catch (NotFoundException $e) { - if ($verbose) { - $section1->writeln(" Create folder preview/$newFoldername"); - } + $section1->writeln(" Create folder preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE); if (!$dryMode) { $this->rootFolder->newFolder("appdata_$instanceId/preview/$newFoldername"); } @@ -254,9 +250,7 @@ class Repair extends Command { $progressBar->advance(); continue; } - if ($verbose) { - $section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername"); - } + $section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE); if (!$dryMode) { try { $preview->move("appdata_$instanceId/preview/$newFoldername/$previewName"); @@ -267,9 +261,7 @@ class Repair extends Command { } } if ($oldPreviewFolder->getDirectoryListing() === []) { - if ($verbose) { - $section1->writeln(" Delete empty folder preview/$name"); - } + $section1->writeln(" Delete empty folder preview/$name", OutputInterface::VERBOSITY_VERBOSE); if (!$dryMode) { try { $oldPreviewFolder->delete();