Add config option to enable multibucket preview distribution

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2020-08-06 20:10:25 +02:00
parent 4fdd38c737
commit 45428e4948
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
4 changed files with 50 additions and 23 deletions

View File

@ -1354,6 +1354,23 @@ $CONFIG = [
], ],
], ],
/**
* If this is set to true and a multibucket object store is configured then
* newly created previews are put into 256 dedicated buckets.
*
* Those buckets are named like the mulibucket version but with the postfix
* ``-preview-NUMBER`` where NUMBER is between 0 and 255.
*
* Keep in mind that only previews of files are put in there that don't have
* some already. Otherwise the old bucket will be used.
*
* To migrate existing previews to this new multibucket distribution of previews
* use the occ command ``preview:repair``. For now this will only migrate
* previews that were generated before Nextcloud 19 in the flat
* ``appdata_INSTANCEID/previews/FILEID`` folder structure.
*/
'objectstore.multibucket.preview-distribution' => false,
/** /**
* Sharing * Sharing

View File

@ -55,6 +55,9 @@ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider {
if (!is_array($this->config->getSystemValue('objectstore_multibucket'))) { if (!is_array($this->config->getSystemValue('objectstore_multibucket'))) {
return []; return [];
} }
if ($this->config->getSystemValue('objectstore.multibucket.preview-distribution', false) !== true) {
return [];
}
$instanceId = $this->config->getSystemValueString('instanceid', ''); $instanceId = $this->config->getSystemValueString('instanceid', '');
$mountPoints = []; $mountPoints = [];

View File

@ -32,23 +32,23 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder; use OCP\Files\SimpleFS\ISimpleFolder;
class Root extends AppData { class Root extends AppData {
private $isMultibucketPreviewDistributionEnabled = false;
public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) { public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) {
parent::__construct($rootFolder, $systemConfig, 'preview'); parent::__construct($rootFolder, $systemConfig, 'preview');
$this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true;
} }
public function getFolder(string $name): ISimpleFolder { public function getFolder(string $name): ISimpleFolder {
$internalFolder = $this->getInternalFolder($name); $internalFolder = $this->getInternalFolder($name);
try { if ($this->isMultibucketPreviewDistributionEnabled) {
return parent::getFolder('old-multibucket/' . $internalFolder); try {
} catch (NotFoundException $e) { return parent::getFolder('old-multibucket/' . $internalFolder);
// not in multibucket fallback #1 } catch (NotFoundException $e) {
} // not in multibucket fallback
try { }
return parent::getFolder('old-multibucket/' . $name);
} catch (NotFoundException $e) {
// not in multibucket fallback #2
} }
try { try {

View File

@ -71,22 +71,29 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
} }
public function testMultibucketObjectStorage() { public function testMultibucketObjectStorage() {
$objectstoreConfig = [
'class' => S3::class,
'arguments' => [
'bucket' => 'abc',
'num_buckets' => 64,
'key' => 'KEY',
'secret' => 'SECRET',
'hostname' => 'IP',
'port' => 'PORT',
'use_ssl' => false,
'use_path_style' => true,
],
];
$this->config->expects($this->any()) $this->config->expects($this->any())
->method('getSystemValue') ->method('getSystemValue')
->with('objectstore_multibucket') ->willReturnCallback(function ($config) use ($objectstoreConfig) {
->willReturn([ if ($config === 'objectstore_multibucket') {
'class' => S3::class, return $objectstoreConfig;
'arguments' => [ } elseif ($config === 'objectstore.multibucket.preview-distribution') {
'bucket' => 'abc', return true;
'num_buckets' => 64, }
'key' => 'KEY', return null;
'secret' => 'SECRET', });
'hostname' => 'IP',
'port' => 'PORT',
'use_ssl' => false,
'use_path_style' => true,
],
]);
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('instanceid') ->with('instanceid')