Skip to content

Commit 0876029

Browse files
committed
Fix number of segments of a large object
The total number of segments was determined with round($streamSize/$segmentSize). In cases like $streamSize=24 and $segmentSize=10 this resulted in one segment too few that was uploaded. This has been fixed by simply omitting round().
1 parent eec8fb4 commit 0876029

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ObjectStore/v1/Models/Container.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ public function createLargeObject(array $data): StorageObject
226226
$service->createContainer(['name' => $segmentContainer]);
227227
}
228228

229-
$promises = [];
230-
$count = 0;
229+
$promises = [];
230+
$count = 0;
231+
$totalSegments = $stream->getSize() / $segmentSize;
231232

232-
while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) {
233+
while (!$stream->eof() && $count < $totalSegments) {
233234
$promises[] = $this->model(StorageObject::class)->createAsync([
234235
'name' => sprintf('%s/%d', $segmentPrefix, ++$count),
235236
'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize),

tests/unit/ObjectStore/v1/Models/ContainerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function test_other_exceptions_are_thrown()
213213
public function test_it_chunks_according_to_provided_segment_size()
214214
{
215215
/** @var \GuzzleHttp\Psr7\Stream $stream */
216-
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'Z')));
216+
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')));
217217

218218
$data = [
219219
'name' => 'object',
@@ -235,6 +235,7 @@ public function test_it_chunks_according_to_provided_segment_size()
235235

236236
$this->setupMock('PUT', 'segments', null, [], new Response(201));
237237

238+
// The stream has size 24 so we expect three segments.
238239
$this->setupMock('PUT', 'segments/objectPrefix/1', $stream->read(10), [], new Response(201));
239240
$this->setupMock('PUT', 'segments/objectPrefix/2', $stream->read(10), [], new Response(201));
240241
$this->setupMock('PUT', 'segments/objectPrefix/3', $stream->read(10), [], new Response(201));

0 commit comments

Comments
 (0)