1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +02:00

pgBackRest is now pure C.

Remove embedded Perl from the distributed binary.  This includes code, configure, Makefile, and packages.  The distributed binary is now pure C.

Remove storagePathEnforceSet() from the C Storage object which allowed Perl to write outside of the storage base directory.  Update mock/all and real/all integration tests to use storageLocal() where they were violating this rule.

Remove "c" option that allowed the remote to tell if it was being called from C or Perl.

Code to convert options to JSON for passing to Perl (perl/config.c) has been moved to LibC since it is still required for Perl integration tests.

Update build and installation instructions in the user guide.

Remove all Perl unit tests.

Remove obsolete Perl code.  In particular this included all the Perl protocol code which required modifications to the Perl storage, manifest, and db objects that are still required for integration testing but only run locally.  Any remaining Perl code is required for testing, documentation, or code generation.

Rename perlReq to binReq in define.yaml to indicate that the binary is required for a test.  This had been the actual meaning for quite some time but the key was never renamed.
This commit is contained in:
David Steele
2019-12-13 17:55:41 -05:00
parent 1f2ce45e6b
commit f0ef73db70
80 changed files with 239 additions and 22415 deletions

View File

@ -1,180 +0,0 @@
####################################################################################################################################
# Protocol File
####################################################################################################################################
package pgBackRest::Protocol::Storage::File;
use parent 'pgBackRest::Common::Io::Base';
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
use Exporter qw(import);
our @EXPORT = qw();
use pgBackRest::Common::Exception;
use pgBackRest::Common::Log;
####################################################################################################################################
# CONSTRUCTOR
####################################################################################################################################
sub new
{
my $class = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$oProtocol, # Master or minion protocol
$oFileIo, # File whose results will be returned via protocol
) =
logDebugParam
(
__PACKAGE__ . '->new', \@_,
{name => 'oProtocol', trace => true},
{name => 'oFileIo', required => false, trace => true},
);
# Create class
my $self = $class->SUPER::new($oProtocol->io()->id() . ' file');
bless $self, $class;
# Set variables
$self->{oProtocol} = $oProtocol;
$self->{oFileIo} = $oFileIo;
# Set read/write
$self->{bWrite} = false;
# Initialize EOF to false
$self->eofSet(false);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'self', value => $self}
);
}
####################################################################################################################################
# eof - have reads reached eof?
####################################################################################################################################
sub eof
{
return shift->{bEOF};
}
####################################################################################################################################
# eofSet - set eof
####################################################################################################################################
sub eofSet
{
my $self = shift;
my $bEOF = shift;
$self->{bEOF} = $bEOF;
}
####################################################################################################################################
# read - read block from protocol
####################################################################################################################################
sub read
{
my $self = shift;
my $rtBuffer = shift;
# After EOF always return 0
return 0 if $self->eof();
my $lBlockSize;
# Read the block header and make sure it's valid
my $strBlockHeader = $self->{oProtocol}->io()->readLine();
if ($strBlockHeader !~ /^BRBLOCK[0-9]+$/)
{
confess &log(ERROR, "invalid block header '${strBlockHeader}'", ERROR_FILE_READ);
}
# Get block size from the header
$lBlockSize = substr($strBlockHeader, 7);
# Read block if size > 0
if ($lBlockSize > 0)
{
$self->{oProtocol}->io()->read($rtBuffer, $lBlockSize, true);
}
else
{
$self->eofSet(true);
}
# Return the block size
return $lBlockSize;
}
####################################################################################################################################
# write - write block to protocol
####################################################################################################################################
sub write
{
my $self = shift;
my $rtBuffer = shift;
# Set write
$self->{bWrite} = true;
# Get the buffer size
my $lBlockSize = defined($rtBuffer) ? length($$rtBuffer) : 0;
# Write if size > 0 (0 ends the copy stream so it should only be done in close())
if ($lBlockSize > 0)
{
# Write block header to the protocol stream
$self->{oProtocol}->io()->writeLine("BRBLOCK${lBlockSize}");
# Write block if size
$self->{oProtocol}->io()->write($rtBuffer);
}
return length($$rtBuffer);
}
####################################################################################################################################
# close - set the result hash
####################################################################################################################################
sub close
{
my $self = shift;
# Close if protocol is defined (to prevent this from running more than once)
if (defined($self->{oProtocol}))
{
# If writing output terminator
if ($self->{bWrite})
{
$self->{oProtocol}->io()->writeLine("BRBLOCK0");
}
# On master read the results
if ($self->{oProtocol}->master())
{
($self->{rhResult}) = $self->{oProtocol}->outputRead();
# Minion will send one more output message after file is closed which can be ignored
$self->{oProtocol}->outputRead();
}
# On minion write the results
else
{
$self->{oProtocol}->outputWrite($self->{oFileIo}->resultAll());
}
# Delete protocol to prevent close from running again
delete($self->{oProtocol});
}
}
1;

View File

@ -14,8 +14,6 @@ use File::Basename qw(basename);
use pgBackRest::Common::Log;
use pgBackRest::Config::Config;
use pgBackRest::LibC qw(:storage);
use pgBackRest::Protocol::Helper;
use pgBackRest::Protocol::Storage::Remote;
use pgBackRest::Storage::Helper;
####################################################################################################################################
@ -45,35 +43,24 @@ sub storageDb
my
(
$strOperation,
$iRemoteIdx,
) =
logDebugParam
(
__PACKAGE__ . '::storageDb', \@_,
{name => 'iRemoteIdx', optional => true, default => cfgOptionValid(CFGOPT_HOST_ID) ? cfgOption(CFGOPT_HOST_ID) : 1,
trace => true},
);
# Create storage if not defined
if (!defined($hStorage->{&STORAGE_DB}{$iRemoteIdx}))
if (!defined($hStorage->{&STORAGE_DB}))
{
if (isDbLocal({iRemoteIdx => $iRemoteIdx}))
{
$hStorage->{&STORAGE_DB}{$iRemoteIdx} = new pgBackRest::Storage::Storage(
STORAGE_DB, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
}
else
{
$hStorage->{&STORAGE_DB}{$iRemoteIdx} = new pgBackRest::Protocol::Storage::Remote(
protocolGet(CFGOPTVAL_REMOTE_TYPE_DB, $iRemoteIdx));
}
$hStorage->{&STORAGE_DB} = new pgBackRest::Storage::Storage(
STORAGE_DB, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
}
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'oStorageDb', value => $hStorage->{&STORAGE_DB}{$iRemoteIdx}, trace => true},
{name => 'oStorageDb', value => $hStorage->{&STORAGE_DB}, trace => true},
);
}
@ -99,17 +86,8 @@ sub storageRepo
# Create storage if not defined
if (!defined($hStorage->{&STORAGE_REPO}))
{
if (isRepoLocal())
{
$hStorage->{&STORAGE_REPO} = new pgBackRest::Storage::Storage(
STORAGE_REPO, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
}
else
{
# Create remote storage
$hStorage->{&STORAGE_REPO} = new pgBackRest::Protocol::Storage::Remote(
protocolGet(CFGOPTVAL_REMOTE_TYPE_BACKUP));
}
$hStorage->{&STORAGE_REPO} = new pgBackRest::Storage::Storage(
STORAGE_REPO, {lBufferMax => cfgOption(CFGOPT_BUFFER_SIZE)});
}
# Return from function and log return values if any

View File

@ -1,342 +0,0 @@
####################################################################################################################################
# Remote Storage
####################################################################################################################################
package pgBackRest::Protocol::Storage::Remote;
use parent 'pgBackRest::Storage::Base';
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
use JSON::PP;
use pgBackRest::Common::Exception;
use pgBackRest::Common::Log;
use pgBackRest::Config::Config;
use pgBackRest::Protocol::Helper;
use pgBackRest::Protocol::Storage::File;
use pgBackRest::Storage::Base;
####################################################################################################################################
# new
####################################################################################################################################
sub new
{
my $class = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$oProtocol,
) =
logDebugParam
(
__PACKAGE__ . '->new', \@_,
{name => 'oProtocol'},
);
# Init parent
my $self = $class->SUPER::new({lBufferMax => $oProtocol->io()->bufferMax()});
bless $self, $class;
# Set variables
$self->{oProtocol} = $oProtocol;
# Create JSON object
$self->{oJSON} = JSON::PP->new()->allow_nonref();
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'self', value => $self}
);
}
####################################################################################################################################
# exists
####################################################################################################################################
sub exists
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strPathExp,
) =
logDebugParam
(
__PACKAGE__ . '->exists', \@_,
{name => 'strPathExp'},
);
my $bExists = $self->{oProtocol}->cmdExecute(OP_STORAGE_EXISTS, [$strPathExp]);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'bExists', value => $bExists}
);
}
####################################################################################################################################
# hashSize
####################################################################################################################################
sub hashSize
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strPathExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->hashSize', \@_,
{name => 'strPathExp'},
{name => 'rhParam', required => false},
);
my ($strHash, $lSize) = $self->{oProtocol}->cmdExecute(OP_STORAGE_HASH_SIZE, [$strPathExp, $rhParam]);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'strHash', value => $strHash},
{name => 'lSize', value => $lSize}
);
}
####################################################################################################################################
# list
####################################################################################################################################
sub list
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strPathExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->list', \@_,
{name => 'strPathExp'},
{name => 'rhParam', required => false},
);
my @stryFileList = $self->{oProtocol}->cmdExecute(OP_STORAGE_LIST, [$strPathExp, $rhParam]);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'stryFileList', value => \@stryFileList}
);
}
####################################################################################################################################
# manifest
####################################################################################################################################
sub manifest
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strPathExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->manifest', \@_,
{name => 'strPathExp'},
{name => 'rhParam', required => false},
);
my $hManifest = $self->{oJSON}->decode($self->{oProtocol}->cmdExecute(OP_STORAGE_MANIFEST, [$strPathExp, $rhParam]));
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'hManifest', value => $hManifest, trace => true}
);
}
####################################################################################################################################
# openRead
####################################################################################################################################
sub openRead
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strFileExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->openRead', \@_,
{name => 'strFileExp'},
{name => 'rhParam', required => false},
);
my $oSourceFileIo =
$self->{oProtocol}->cmdExecute(OP_STORAGE_OPEN_READ, [$strFileExp, $rhParam]) ?
new pgBackRest::Protocol::Storage::File($self->{oProtocol}) : undef;
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'oFileIo', value => $oSourceFileIo, trace => true},
);
}
####################################################################################################################################
# openWrite
####################################################################################################################################
sub openWrite
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strFileExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->openWrite', \@_,
{name => 'strFileExp'},
{name => 'rhParam', required => false},
);
# Open the remote file
$self->{oProtocol}->cmdWrite(OP_STORAGE_OPEN_WRITE, [$strFileExp, $rhParam]);
my $oDestinationFileIo = new pgBackRest::Protocol::Storage::File($self->{oProtocol});
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'oFileIo', value => $oDestinationFileIo, trace => true},
);
}
####################################################################################################################################
# pathGet
####################################################################################################################################
sub pathGet
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strPathExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->pathGet', \@_,
{name => 'strPathExp', required => false},
{name => 'rhParam', required => false},
);
my $strPath = $self->{oProtocol}->cmdExecute(OP_STORAGE_PATH_GET, [$strPathExp, $rhParam]);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'strPath', value => $strPath}
);
}
####################################################################################################################################
# move
####################################################################################################################################
sub move
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
$strSourcePathExp,
$strDestinationPathExp,
$rhParam,
) =
logDebugParam
(
__PACKAGE__ . '->move', \@_,
{name => 'strSourcePathExp'},
{name => 'strDestinationPathExp'},
{name => 'rhParam', required => false},
);
$self->{oProtocol}->cmdExecute(OP_STORAGE_MOVE, [$strSourcePathExp, $strDestinationPathExp, $rhParam], false);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation
);
}
####################################################################################################################################
# cipherPassUser
####################################################################################################################################
sub cipherPassUser
{
my $self = shift;
# Assign function parameters, defaults, and log debug info
my
(
$strOperation,
) =
logDebugParam
(
__PACKAGE__ . '->cipherPassUser', \@_,
);
my $strCipherPassUser = $self->{oProtocol}->cmdExecute(OP_STORAGE_CIPHER_PASS_USER);
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'strCipherPassUser', value => $strCipherPassUser, redact => true}
);
}
####################################################################################################################################
# getters
####################################################################################################################################
sub protocol {shift->{oProtocol}};
1;