mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Inflate performance improvement for gzip filter and full unit test coverage.
This commit is contained in:
parent
04e55fe71b
commit
b8746f368d
@ -57,6 +57,10 @@
|
||||
<release-item>
|
||||
<p>Simplify try..catch..finally names.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Inflate performance improvement for gzip filter.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-core-list>
|
||||
|
||||
@ -78,6 +82,10 @@
|
||||
<release-item>
|
||||
<p>Update Debian/Ubuntu containers to download latest version of <file>pip</file>.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Full unit test coverage for gzip filter.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-test-list>
|
||||
</release>
|
||||
|
@ -156,29 +156,26 @@ sub read
|
||||
else
|
||||
{
|
||||
# If the local buffer size is not large enough to satisfy the request and there is still data to decompress
|
||||
if ($self->{lUncompressedBufferSize} < $iSize)
|
||||
while ($self->{lUncompressedBufferSize} < $iSize && !$self->parent()->eof())
|
||||
{
|
||||
while ($self->{lUncompressedBufferSize} < $iSize)
|
||||
if (!defined($self->{tCompressedBuffer}) || length($self->{tCompressedBuffer}) == 0)
|
||||
{
|
||||
if (!defined($self->{tCompressedBuffer}) || length($self->{tCompressedBuffer}) == 0)
|
||||
{
|
||||
$self->parent()->read(\$self->{tCompressedBuffer}, $self->{lCompressBufferMax});
|
||||
}
|
||||
|
||||
my $iZLibStatus = $self->{oZLib}->inflate($self->{tCompressedBuffer}, $self->{tUncompressedBuffer});
|
||||
$self->{lUncompressedBufferSize} = length($self->{tUncompressedBuffer});
|
||||
|
||||
last if $iZLibStatus == Z_STREAM_END;
|
||||
|
||||
$self->errorCheck($iZLibStatus);
|
||||
$self->parent()->read(\$self->{tCompressedBuffer}, $self->{lCompressBufferMax});
|
||||
}
|
||||
|
||||
my $iZLibStatus = $self->{oZLib}->inflate($self->{tCompressedBuffer}, $self->{tUncompressedBuffer});
|
||||
$self->{lUncompressedBufferSize} = length($self->{tUncompressedBuffer});
|
||||
|
||||
last if $iZLibStatus == Z_STREAM_END;
|
||||
|
||||
$self->errorCheck($iZLibStatus);
|
||||
}
|
||||
|
||||
# Actual size is the lesser of the local buffer size or requested size - if the local buffer is smaller than the requested
|
||||
# size it means that there was nothing more to be read
|
||||
my $iActualSize = $self->{lUncompressedBufferSize} < $iSize ? $self->{lUncompressedBufferSize} : $iSize;
|
||||
|
||||
# Append the to the request buffer
|
||||
# Append to the request buffer
|
||||
$$rtBuffer .= substr($self->{tUncompressedBuffer}, 0, $iActualSize);
|
||||
|
||||
# Truncate local buffer
|
||||
@ -206,7 +203,7 @@ sub write
|
||||
$self->errorCheck($self->{oZLib}->deflate($$rtBuffer, $self->{tCompressedBuffer}));
|
||||
|
||||
# Only write when buffer is full
|
||||
if (defined($self->{tCompressedBuffer}) && length($self->{tCompressedBuffer}) > $self->{lCompressBufferMax})
|
||||
if (length($self->{tCompressedBuffer}) > $self->{lCompressBufferMax})
|
||||
{
|
||||
$self->parent()->write(\$self->{tCompressedBuffer});
|
||||
$self->{tCompressedBuffer} = undef;
|
||||
@ -260,6 +257,8 @@ sub close
|
||||
# Close io
|
||||
return $self->parent()->close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -329,7 +329,7 @@ my $oTestDef =
|
||||
|
||||
&TESTDEF_COVERAGE =>
|
||||
{
|
||||
'Storage/Filter/Gzip' => TESTDEF_COVERAGE_PARTIAL,
|
||||
'Storage/Filter/Gzip' => TESTDEF_COVERAGE_FULL,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -63,7 +63,8 @@ sub run
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $oGzipIo = $self->testResult(
|
||||
sub {new pgBackRest::Storage::Filter::Gzip($oDriver->openWrite($strFileGz))}, '[object]', 'new write compress');
|
||||
sub {new pgBackRest::Storage::Filter::Gzip($oDriver->openWrite($strFileGz), {lCompressBufferMax => 4})},
|
||||
'[object]', 'new write compress');
|
||||
|
||||
my $tBuffer = substr($strFileContent, 0, 2);
|
||||
$self->testResult(sub {$oGzipIo->write(\$tBuffer)}, 2, ' write 2 bytes');
|
||||
@ -125,6 +126,7 @@ sub run
|
||||
$self->testResult(sub {$oGzipIo->read(\$tBuffer, 2)}, 0, ' read 0 bytes');
|
||||
|
||||
$self->testResult(sub {$oGzipIo->close()}, true, ' close');
|
||||
$self->testResult(sub {$oGzipIo->close()}, false, ' close again');
|
||||
$self->testResult($tBuffer, $strFileContent, ' check content');
|
||||
|
||||
storageTest()->remove($strFileGz);
|
||||
|
Loading…
Reference in New Issue
Block a user