You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-01-06 08:01:21 +03:00
Fixed an issue that could cause compression to abort on growing files.
Reported by Jesper St John, Aleksandr Rogozin.
This commit is contained in:
@@ -13,6 +13,15 @@
|
||||
<release date="XXXX-XX-XX" version="1.23dev" title="UNDER DEVELOPMENT">
|
||||
<release-core-list>
|
||||
<release-bug-list>
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-ideator id="stjohn.jesper"/>
|
||||
<release-item-ideator id="rogozin.aleksandr"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Fixed an issue that could cause compression to abort on growing files.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-ideator id="cox.william"/>
|
||||
@@ -3286,6 +3295,11 @@
|
||||
<contributor-id type="github">eradman</contributor-id>
|
||||
</contributor>
|
||||
|
||||
<contributor id="rogozin.aleksandr">
|
||||
<contributor-name-display>Aleksandr Rogozin</contributor-name-display>
|
||||
<contributor-id type="github">arogozin</contributor-id>
|
||||
</contributor>
|
||||
|
||||
<contributor id="shang.cynthia">
|
||||
<contributor-name-display>Cynthia Shang</contributor-name-display>
|
||||
<contributor-id type="github">cmwshang</contributor-id>
|
||||
@@ -3301,6 +3315,11 @@
|
||||
<contributor-id type="github">gregscds</contributor-id>
|
||||
</contributor>
|
||||
|
||||
<contributor id="stjohn.jesper">
|
||||
<contributor-name-display>Jesper St John</contributor-name-display>
|
||||
<contributor-id type="github">Underhunden</contributor-id>
|
||||
</contributor>
|
||||
|
||||
<contributor id="vernick.todd">
|
||||
<contributor-name-display>Todd Vernick</contributor-name-display>
|
||||
<contributor-id type="github">gintoddic</contributor-id>
|
||||
|
||||
@@ -55,6 +55,9 @@ sub new
|
||||
# Size tracks number of bytes read and written
|
||||
$self->{lSize} = 0;
|
||||
|
||||
# Initialize EOF to false
|
||||
$self->{bEOF} = false;
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
@@ -63,6 +66,17 @@ sub new
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# eof - have reads reached eof?
|
||||
#
|
||||
# Note that there may be more bytes to be read but this is set to true whenever there is a zero read and back to false on a
|
||||
# non-zero read.
|
||||
####################################################################################################################################
|
||||
sub eof
|
||||
{
|
||||
return shift->{bEOF};
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# read - read data from handle
|
||||
####################################################################################################################################
|
||||
@@ -93,6 +107,9 @@ sub read
|
||||
# Update size
|
||||
$self->{lSize} += $iActualSize;
|
||||
|
||||
# Update EOF
|
||||
$self->{bEOF} = $iActualSize == 0 ? true : false;
|
||||
|
||||
return $iActualSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,8 @@ sub read
|
||||
|
||||
if ($self->{strCompressType} eq STORAGE_COMPRESS)
|
||||
{
|
||||
return 0 if $self->eof();
|
||||
|
||||
my $lSizeBegin = defined($$rtBuffer) ? length($$rtBuffer) : 0;
|
||||
my $lUncompressedSize;
|
||||
my $lCompressedSize;
|
||||
@@ -172,8 +174,8 @@ sub read
|
||||
}
|
||||
}
|
||||
|
||||
# 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.
|
||||
# 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
|
||||
|
||||
@@ -105,12 +105,15 @@ sub run
|
||||
$self->testResult(sub {$oIoHandle->read(\$tContent, $iFileLengthHalf)}, $iFileLengthHalf, ' read part 1');
|
||||
$self->testResult($tContent, substr($strFileContent, 0, $iFileLengthHalf), ' check read');
|
||||
|
||||
$self->testResult(sub {$oIoHandle->eof()}, false, ' not eof');
|
||||
|
||||
$self->testResult(
|
||||
sub {$oIoHandle->read(
|
||||
\$tContent, $iFileLength - $iFileLengthHalf)}, $iFileLength - $iFileLengthHalf, ' read part 2');
|
||||
$self->testResult($tContent, $strFileContent, ' check read');
|
||||
|
||||
$self->testResult(sub {$oIoHandle->read(\$tContent, 1)}, 0, ' eof');
|
||||
$self->testResult(sub {$oIoHandle->read(\$tContent, 1)}, 0, ' zero read');
|
||||
$self->testResult(sub {$oIoHandle->eof()}, true, ' eof');
|
||||
}
|
||||
|
||||
################################################################################################################################
|
||||
|
||||
@@ -182,6 +182,27 @@ sub run
|
||||
$self->testResult(
|
||||
sub {sha1_hex(${storageTest()->get($strFile)})}, '1c7e00fd09b9dd11fc2966590b3e3274645dd031', ' check content');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$tBuffer = undef;
|
||||
|
||||
my $oFile = $self->testResult(
|
||||
sub {storageTest()->openWrite($strFile)}, '[object]', 'open file to extend during compression');
|
||||
|
||||
$oGzipIo = $self->testResult(
|
||||
sub {new pgBackRest::Storage::Filter::Gzip($oDriver->openRead($strFile), {lCompressBufferMax => 4194304})},
|
||||
'[object]', ' new read compress');
|
||||
|
||||
$self->testResult(sub {$oFile->write(\$strFileContent)}, length($strFileContent), ' write first block');
|
||||
$self->testResult(sub {$oGzipIo->read(\$tBuffer, 2000000) > 0}, true, ' read compressed first block (compression done)');
|
||||
|
||||
$self->testResult(sub {$oFile->write(\$strFileContent)}, length($strFileContent), ' write second block');
|
||||
$self->testResult(sub {$oGzipIo->read(\$tBuffer, 2000000)}, 0, ' read compressed = 0');
|
||||
|
||||
$self->testResult(sub {storageTest()->put($strFileGz, $tBuffer) > 0}, true, ' put content');
|
||||
executeTest("gzip -df ${strFileGz}");
|
||||
$self->testResult(
|
||||
sub {${storageTest()->get($strFile)}}, $strFileContent, ' check content');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
storageTest()->put($strFileGz, $strFileContent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user