Merge pull request #22938 from nextcloud/backport/22911/stable20
[stable20] Allow to run occ preview:repair in parallel
This commit is contained in:
commit
5d81cb36b5
|
@ -33,6 +33,8 @@ use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\Lock\ILockingProvider;
|
||||||
|
use OCP\Lock\LockedException;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
@ -54,11 +56,14 @@ class Repair extends Command {
|
||||||
private $memoryLimit;
|
private $memoryLimit;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $memoryTreshold;
|
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->config = $config;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->lockingProvider = $lockingProvider;
|
||||||
|
|
||||||
$this->memoryLimit = $phpIni->getBytes('memory_limit');
|
$this->memoryLimit = $phpIni->getBytes('memory_limit');
|
||||||
$this->memoryTreshold = $this->memoryLimit - 25 * 1024 * 1024;
|
$this->memoryTreshold = $this->memoryLimit - 25 * 1024 * 1024;
|
||||||
|
@ -95,8 +100,6 @@ class Repair extends Command {
|
||||||
$output->writeln("");
|
$output->writeln("");
|
||||||
}
|
}
|
||||||
|
|
||||||
$verbose = $output->isVerbose();
|
|
||||||
|
|
||||||
$instanceId = $this->config->getSystemValueString('instanceid');
|
$instanceId = $this->config->getSystemValueString('instanceid');
|
||||||
|
|
||||||
$output->writeln("This will migrate all previews from the old preview location to the new one.");
|
$output->writeln("This will migrate all previews from the old preview location to the new one.");
|
||||||
|
@ -218,14 +221,21 @@ class Repair extends Command {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lockName = 'occ preview:repair lock ' . $oldPreviewFolder->getId();
|
||||||
|
try {
|
||||||
|
$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 …");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$previews = $oldPreviewFolder->getDirectoryListing();
|
$previews = $oldPreviewFolder->getDirectoryListing();
|
||||||
if ($previews !== []) {
|
if ($previews !== []) {
|
||||||
try {
|
try {
|
||||||
$this->rootFolder->get("appdata_$instanceId/preview/$newFoldername");
|
$this->rootFolder->get("appdata_$instanceId/preview/$newFoldername");
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
if ($verbose) {
|
$section1->writeln(" Create folder preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
$section1->writeln(" Create folder preview/$newFoldername");
|
|
||||||
}
|
|
||||||
if (!$dryMode) {
|
if (!$dryMode) {
|
||||||
$this->rootFolder->newFolder("appdata_$instanceId/preview/$newFoldername");
|
$this->rootFolder->newFolder("appdata_$instanceId/preview/$newFoldername");
|
||||||
}
|
}
|
||||||
|
@ -240,9 +250,7 @@ class Repair extends Command {
|
||||||
$progressBar->advance();
|
$progressBar->advance();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($verbose) {
|
$section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
$section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername");
|
|
||||||
}
|
|
||||||
if (!$dryMode) {
|
if (!$dryMode) {
|
||||||
try {
|
try {
|
||||||
$preview->move("appdata_$instanceId/preview/$newFoldername/$previewName");
|
$preview->move("appdata_$instanceId/preview/$newFoldername/$previewName");
|
||||||
|
@ -253,9 +261,7 @@ class Repair extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($oldPreviewFolder->getDirectoryListing() === []) {
|
if ($oldPreviewFolder->getDirectoryListing() === []) {
|
||||||
if ($verbose) {
|
$section1->writeln(" Delete empty folder preview/$name", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
$section1->writeln(" Delete empty folder preview/$name");
|
|
||||||
}
|
|
||||||
if (!$dryMode) {
|
if (!$dryMode) {
|
||||||
try {
|
try {
|
||||||
$oldPreviewFolder->delete();
|
$oldPreviewFolder->delete();
|
||||||
|
@ -264,6 +270,10 @@ class Repair extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lockingProvider->releaseLock($lockName, ILockingProvider::LOCK_EXCLUSIVE);
|
||||||
|
$section1->writeln(" Unlocked", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
|
|
||||||
$section1->writeln(" Finished migrating previews of file with fileId $name …");
|
$section1->writeln(" Finished migrating previews of file with fileId $name …");
|
||||||
$progressBar->advance();
|
$progressBar->advance();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue