Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 28947f0

Browse files
committed
PLATFORM-5417| add maxThreads parameter to S3Put
1 parent 29ee284 commit 28947f0

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

docker/maintenance/cronjob-template.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ spec:
3131
value: sjc
3232
- name: WIKIA_ENVIRONMENT
3333
value: prod
34-
- name: S4CMD_NUM_THREADS
35-
value: 2
3634
resources:
3735
limits:
3836
cpu: "6"

extensions/wikia/WikiFactory/Close/maintenance.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ public function execute() {
161161
try {
162162
foreach( $this->tarFiles( $dbname, $cityid ) as $source ) {
163163
if ( is_string( $source ) ) {
164-
$res = DumpsOnDemand::putToAmazonS3( $source, !$hide, MimeMagic::singleton()->guessMimeType( $source ) );
164+
$res = DumpsOnDemand::putToAmazonS3( $source, !$hide, MimeMagic::singleton()
165+
->guessMimeType( $source ), 2 );
165166
if ( !$res ) {
166167
$this->error( "putToAmazonS3 command failed - Can't copy images to remote host. Please, fix that and rerun",
167168
[ 'dump_size_bytes' => filesize( $source ), ] );

extensions/wikia/WikiFactory/Dumps/DumpsOnDemand.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ static public function getPath( $sName ) {
170170
*
171171
* @param string $sPath
172172
* @param bool $bPublic
173-
* @param string|null $sMimeType
174-
* if $sMimeType is set then the specified mime tipe is set, otherwise
173+
* @param null $sMimeType
174+
* if $sMimeType is set then the specified mime type is set, otherwise
175175
* let AmazonS3 decide on mime type.
176+
* @param int $iMaxThreads set the maximum number of threads used by the s3 upload tool
176177
* @return bool
177-
* @throws Exception
178178
*/
179-
static public function putToAmazonS3( $sPath, $bPublic = true, $sMimeType = null ) {
179+
static public function putToAmazonS3( $sPath, $bPublic = true, $sMimeType = null, $iMaxThreads = 0 ) {
180180
$time = wfTime();
181181
$size = filesize( $sPath );
182182

@@ -186,6 +186,7 @@ static public function putToAmazonS3( $sPath, $bPublic = true, $sMimeType = null
186186
}
187187
$s3->setContentDisposition( 'attachment' );
188188
$s3->setForce();
189+
$s3->setMaxThreads( $iMaxThreads );
189190

190191
if ( !is_null( $sMimeType ) ) {
191192
$s3->setContentType( $sMimeType );

lib/Wikia/src/s3/S3Put.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class S3Put {
2323
private $contentDisposition = null;
2424
/** @var bool */
2525
private $force = false;
26+
/** @var ?integer */
27+
private $maxThreads = null;
2628

2729
/**
2830
* Makes the upcoming upload public
@@ -34,6 +36,18 @@ public function setPublic() {
3436
return $this;
3537
}
3638

39+
/**
40+
* Set the maximum number of threads to be utilized by the upload tool.
41+
* Useful when working in resource restricted environments.
42+
*
43+
* @param int $newMaxThreads
44+
* @return $this
45+
*/
46+
public function setMaxThreads( int $newMaxThreads ) {
47+
$this->maxThreads = $newMaxThreads;
48+
return $this;
49+
}
50+
3751
/**
3852
* Sets the Content-Type header for the upcoming upload.
3953
*
@@ -92,10 +106,14 @@ public function execute( string $localPath, string $bucket, string $remotePath )
92106
);
93107

94108
try {
95-
$out = wfShellExec( $cmd, $result, [
109+
$env = [
96110
'S3_ACCESS_KEY' => $wgAWSAccessKey,
97111
'S3_SECRET_KEY' => $wgAWSSecretKey
98-
] );
112+
];
113+
if ( $this->maxThreads ) {
114+
$env['S4CMD_NUM_THREADS'] = $this->maxThreads;
115+
}
116+
$out = wfShellExec( $cmd, $result, $env );
99117
} catch ( \Exception $e ) {
100118
throw new S3Exception( 'Error while executing s4cmd:' . $e->getMessage() );
101119
}

0 commit comments

Comments
 (0)