Skip to content

Commit

Permalink
Merge pull request #255 from biigle/fix-large-object-segments
Browse files Browse the repository at this point in the history
Fix number of segments of a large object
  • Loading branch information
haphan committed Sep 14, 2018
2 parents eec8fb4 + 0876029 commit 3eba351
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/ObjectStore/v1/Models/Container.php
Expand Up @@ -226,10 +226,11 @@ public function createLargeObject(array $data): StorageObject
$service->createContainer(['name' => $segmentContainer]);
}

$promises = [];
$count = 0;
$promises = [];
$count = 0;
$totalSegments = $stream->getSize() / $segmentSize;

while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) {
while (!$stream->eof() && $count < $totalSegments) {
$promises[] = $this->model(StorageObject::class)->createAsync([
'name' => sprintf('%s/%d', $segmentPrefix, ++$count),
'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize),
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/ObjectStore/v1/Models/ContainerTest.php
Expand Up @@ -213,7 +213,7 @@ public function test_other_exceptions_are_thrown()
public function test_it_chunks_according_to_provided_segment_size()
{
/** @var \GuzzleHttp\Psr7\Stream $stream */
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'Z')));
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')));

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

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

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

0 comments on commit 3eba351

Please sign in to comment.