From 6ab2feaa54078b1b3cb372a9d9493195a7b7c533 Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Wed, 10 Nov 2021 12:21:01 +0100 Subject: Implement multibucket shift for ObjectStore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/private/Files/Mount/ObjectHomeMountProvider.php | 2 +- lib/private/Files/ObjectStore/Mapper.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Mount/ObjectHomeMountProvider.php b/lib/private/Files/Mount/ObjectHomeMountProvider.php index 441f7a2957e..972d3893e66 100644 --- a/lib/private/Files/Mount/ObjectHomeMountProvider.php +++ b/lib/private/Files/Mount/ObjectHomeMountProvider.php @@ -121,7 +121,7 @@ class ObjectHomeMountProvider implements IHomeMountProvider { if (!isset($config['arguments']['bucket'])) { $config['arguments']['bucket'] = ''; } - $mapper = new \OC\Files\ObjectStore\Mapper($user); + $mapper = new \OC\Files\ObjectStore\Mapper($user, $this->config); $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); diff --git a/lib/private/Files/ObjectStore/Mapper.php b/lib/private/Files/ObjectStore/Mapper.php index 74d65454b12..ef3c6878d81 100644 --- a/lib/private/Files/ObjectStore/Mapper.php +++ b/lib/private/Files/ObjectStore/Mapper.php @@ -22,6 +22,7 @@ */ namespace OC\Files\ObjectStore; +use OCP\IConfig; use OCP\IUser; /** @@ -35,13 +36,18 @@ class Mapper { /** @var IUser */ private $user; + /** @var IConfig */ + private $config; + /** * Mapper constructor. * * @param IUser $user + * @param IConfig $config */ - public function __construct(IUser $user) { + public function __construct(IUser $user, IConfig $config) { $this->user = $user; + $this->config = $config; } /** @@ -49,8 +55,15 @@ class Mapper { * @return string */ public function getBucket($numBuckets = 64) { + // Get the bucket config and shift if provided. + // Allow us to prevent writing in old filled buckets + $config = $this->config->getSystemValue('objectstore_multibucket'); + $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) + ? (int)$config['arguments']['min_bucket'] + : 0; + $hash = md5($this->user->getUID()); $num = hexdec(substr($hash, 0, 4)); - return (string)($num % $numBuckets); + return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); } } -- cgit v1.2.3