summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-11-19 17:26:44 +0100
committerGitHub <noreply@github.com>2021-11-19 17:26:44 +0100
commitc42a8901261d5d93da53613bdba8165e503f9b72 (patch)
treec87426ac53b3cc105c55190639e742481c91e7e8 /lib/private/Files
parent1efdd6ccae289d0ef3995cfbb95272f5015dcc9a (diff)
parent6ab2feaa54078b1b3cb372a9d9493195a7b7c533 (diff)
downloadnextcloud-server-c42a8901261d5d93da53613bdba8165e503f9b72.tar.gz
nextcloud-server-c42a8901261d5d93da53613bdba8165e503f9b72.zip
Merge pull request #29622 from nextcloud/feat/objectstore_multibucket-shift
Implement multibucket shift for ObjectStore
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Mount/ObjectHomeMountProvider.php2
-rw-r--r--lib/private/Files/ObjectStore/Mapper.php17
2 files changed, 16 insertions, 3 deletions
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);
}
}