Skip to content

Commit a35edaa

Browse files
authored
Merge pull request #44252 from nextcloud/enh/s3-connectivity
feat(ObjectStore): Make the S3 `concurrency` option configurable
2 parents 45efd28 + 32dee2f commit a35edaa

5 files changed

Lines changed: 65 additions & 31 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@
14191419
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
14201420
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
14211421
'OC\\Files\\ObjectStore\\S3' => $baseDir . '/lib/private/Files/ObjectStore/S3.php',
1422+
'OC\\Files\\ObjectStore\\S3ConfigTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',
14221423
'OC\\Files\\ObjectStore\\S3ConnectionTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ConnectionTrait.php',
14231424
'OC\\Files\\ObjectStore\\S3ObjectTrait' => $baseDir . '/lib/private/Files/ObjectStore/S3ObjectTrait.php',
14241425
'OC\\Files\\ObjectStore\\S3Signature' => $baseDir . '/lib/private/Files/ObjectStore/S3Signature.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14521452
'OC\\Files\\ObjectStore\\ObjectStoreScanner' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreScanner.php',
14531453
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
14541454
'OC\\Files\\ObjectStore\\S3' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3.php',
1455+
'OC\\Files\\ObjectStore\\S3ConfigTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConfigTrait.php',
14551456
'OC\\Files\\ObjectStore\\S3ConnectionTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ConnectionTrait.php',
14561457
'OC\\Files\\ObjectStore\\S3ObjectTrait' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3ObjectTrait.php',
14571458
'OC\\Files\\ObjectStore\\S3Signature' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/S3Signature.php',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
7+
*
8+
* @author Ferdinand Thiessen <opensource@fthiessen.de>
9+
*
10+
* @license GNU AGPL-3.0-or-later
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OC\Files\ObjectStore;
28+
29+
/**
30+
* Shared configuration between ConnectionTrait and ObjectTrait to ensure both to be in sync
31+
*/
32+
trait S3ConfigTrait {
33+
protected array $params;
34+
35+
protected string $bucket;
36+
37+
/** Maximum number of concurrent multipart uploads */
38+
protected int $concurrency;
39+
40+
protected int $timeout;
41+
42+
protected string $proxy;
43+
44+
protected string $storageClass;
45+
46+
protected int $uploadPartSize;
47+
48+
private int $putSizeLimit;
49+
50+
private int $copySizeLimit;
51+
52+
private bool $useMultipartCopy = true;
53+
}

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,13 @@
4444
use Psr\Log\LoggerInterface;
4545

4646
trait S3ConnectionTrait {
47-
/** @var array */
48-
protected $params;
47+
use S3ConfigTrait;
4948

50-
/** @var S3Client */
51-
protected $connection;
49+
protected string $id;
5250

53-
/** @var string */
54-
protected $id;
51+
protected bool $test;
5552

56-
/** @var string */
57-
protected $bucket;
58-
59-
/** @var int */
60-
protected $timeout;
61-
62-
/** @var string */
63-
protected $proxy;
64-
65-
/** @var string */
66-
protected $storageClass;
67-
68-
/** @var int */
69-
protected $uploadPartSize;
70-
71-
/** @var int */
72-
private $putSizeLimit;
73-
74-
/** @var int */
75-
private $copySizeLimit;
76-
77-
private bool $useMultipartCopy = true;
78-
79-
protected $test;
53+
protected ?S3Client $connection = null;
8054

8155
protected function parseParams($params) {
8256
if (empty($params['bucket'])) {
@@ -87,6 +61,8 @@ protected function parseParams($params) {
8761

8862
$this->test = isset($params['test']);
8963
$this->bucket = $params['bucket'];
64+
// Default to 5 like the S3 SDK does
65+
$this->concurrency = $params['concurrency'] ?? 5;
9066
$this->proxy = $params['proxy'] ?? false;
9167
$this->timeout = $params['timeout'] ?? 15;
9268
$this->storageClass = !empty($params['storageClass']) ? $params['storageClass'] : 'STANDARD';
@@ -118,7 +94,7 @@ public function getProxy() {
11894
* @throws \Exception if connection could not be made
11995
*/
12096
public function getConnection() {
121-
if (!is_null($this->connection)) {
97+
if ($this->connection !== null) {
12298
return $this->connection;
12399
}
124100

lib/private/Files/ObjectStore/S3ObjectTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
use Psr\Http\Message\StreamInterface;
3737

3838
trait S3ObjectTrait {
39+
use S3ConfigTrait;
40+
3941
/**
4042
* Returns the connection
4143
*
@@ -127,6 +129,7 @@ protected function writeSingle(string $urn, StreamInterface $stream, string $mim
127129
protected function writeMultiPart(string $urn, StreamInterface $stream, string $mimetype = null): void {
128130
$uploader = new MultipartUploader($this->getConnection(), $stream, [
129131
'bucket' => $this->bucket,
132+
'concurrency' => $this->concurrency,
130133
'key' => $urn,
131134
'part_size' => $this->uploadPartSize,
132135
'params' => [

0 commit comments

Comments
 (0)