mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-06-06 23:16:26 +02:00
Decoding a manifest from the JSON provided by C to the hash required by Perl is an expensive process. If manifest() was called on a remote it was being decoded into a hash and then immediately re-encoded into JSON for transmission over the protocol layer. Instead, provide a function for the remote to get the raw JSON which can be transmitted as is and decoded in the calling process instead. This makes remote manifest calls as fast as they were before 2.16, but local calls must still pay the decoding penalty and are therefore slower. This will continue to be true until the Perl storage interface is retired at the end of the C migration. Note that for reasonable numbers of tables there is no detectable difference. The case in question involved 250K tables with a 10 minute decode time (which was being doubled) on a fast workstation.
133 lines
4.7 KiB
Perl
133 lines
4.7 KiB
Perl
####################################################################################################################################
|
|
# PROTOCOL REMOTE MINION MODULE
|
|
####################################################################################################################################
|
|
package pgBackRest::Protocol::Remote::Minion;
|
|
use parent 'pgBackRest::Protocol::Command::Minion';
|
|
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use pgBackRest::Backup::File;
|
|
use pgBackRest::Common::Log;
|
|
use pgBackRest::Common::Io::Buffered;
|
|
use pgBackRest::Common::Wait;
|
|
use pgBackRest::Archive::Get::File;
|
|
use pgBackRest::Check::Check;
|
|
use pgBackRest::Config::Config;
|
|
use pgBackRest::Db;
|
|
use pgBackRest::Protocol::Command::Minion;
|
|
use pgBackRest::Protocol::Helper;
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
####################################################################################################################################
|
|
# CONSTRUCTOR
|
|
####################################################################################################################################
|
|
sub new
|
|
{
|
|
my $class = shift; # Class name
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$iBufferMax, # Maximum buffer size
|
|
$iProtocolTimeout # Protocol timeout
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '->new', \@_,
|
|
{name => 'iBufferMax'},
|
|
{name => 'iProtocolTimeout'}
|
|
);
|
|
|
|
# Init object and store variables
|
|
my $self = $class->SUPER::new(cfgCommandName(CFGCMD_REMOTE), $iBufferMax, $iProtocolTimeout);
|
|
bless $self, $class;
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn
|
|
(
|
|
$strOperation,
|
|
{name => 'self', value => $self}
|
|
);
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# init
|
|
####################################################################################################################################
|
|
sub init
|
|
{
|
|
my $self = shift;
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->init');
|
|
|
|
# Create objects
|
|
my $oStorage = cfgOptionTest(CFGOPT_TYPE, CFGOPTVAL_REMOTE_TYPE_DB) ? storageDb() : storageRepo();
|
|
|
|
my $oCheck = cfgOptionTest(CFGOPT_TYPE, CFGOPTVAL_REMOTE_TYPE_BACKUP) ? new pgBackRest::Check::Check() : undef;
|
|
my $oDb = cfgOptionTest(CFGOPT_TYPE, CFGOPTVAL_REMOTE_TYPE_DB) ? new pgBackRest::Db() : undef;
|
|
|
|
# Create anonymous subs for each command
|
|
my $hCommandMap =
|
|
{
|
|
# ArchiveGet commands
|
|
&OP_ARCHIVE_GET_CHECK => sub {archiveGetCheck(@{shift()})},
|
|
|
|
# Check commands
|
|
&OP_CHECK_BACKUP_INFO_CHECK => sub {$oCheck->backupInfoCheck(@{shift()})},
|
|
|
|
# Db commands
|
|
&OP_DB_CONNECT => sub {$oDb->connect()},
|
|
&OP_DB_EXECUTE_SQL => sub {$oDb->executeSql(@{shift()})},
|
|
&OP_DB_INFO => sub {$oDb->info(@{shift()})},
|
|
|
|
# File commands
|
|
&OP_STORAGE_OPEN_READ => sub
|
|
{
|
|
my $oSourceFileIo = $oStorage->openRead(@{shift()});
|
|
|
|
# If the source file exists
|
|
if (defined($oSourceFileIo) && (!defined($oSourceFileIo->{oStorageCRead}) || $oSourceFileIo->open()))
|
|
{
|
|
$self->outputWrite(true);
|
|
|
|
$oStorage->copy(
|
|
$oSourceFileIo, new pgBackRest::Protocol::Storage::File($self, $oSourceFileIo), {bSourceOpen => true});
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
},
|
|
&OP_STORAGE_OPEN_WRITE => sub
|
|
{
|
|
my $oDestinationFileIo = $oStorage->openWrite(@{shift()});
|
|
$oStorage->copy(new pgBackRest::Protocol::Storage::File($self, $oDestinationFileIo), $oDestinationFileIo);
|
|
},
|
|
|
|
&OP_STORAGE_CIPHER_PASS_USER => sub {$oStorage->cipherPassUser()},
|
|
&OP_STORAGE_EXISTS => sub {$oStorage->exists(@{shift()})},
|
|
&OP_STORAGE_LIST => sub {$oStorage->list(@{shift()})},
|
|
&OP_STORAGE_MANIFEST => sub {$oStorage->manifestJson(@{shift()})},
|
|
&OP_STORAGE_MOVE => sub {$oStorage->move(@{shift()})},
|
|
&OP_STORAGE_PATH_GET => sub {$oStorage->pathGet(@{shift()})},
|
|
&OP_STORAGE_HASH_SIZE => sub {$oStorage->hashSize(@{shift()})},
|
|
|
|
# Wait command
|
|
&OP_WAIT => sub {waitRemainder(@{shift()})},
|
|
};
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn
|
|
(
|
|
$strOperation,
|
|
{name => 'hCommandMap', value => $hCommandMap}
|
|
);
|
|
}
|
|
|
|
1;
|