1####################################################################################################################################
2# HostDbTest.pm - Database host
3####################################################################################################################################
4package pgBackRestTest::Env::Host::HostDbCommonTest;
5use parent 'pgBackRestTest::Env::Host::HostBackupTest';
6
7####################################################################################################################################
8# Perl includes
9####################################################################################################################################
10use strict;
11use warnings FATAL => qw(all);
12use Carp qw(confess);
13
14use Exporter qw(import);
15    our @EXPORT = qw();
16use File::Basename qw(dirname);
17use Storable qw(dclone);
18
19use pgBackRestDoc::Common::Exception;
20use pgBackRestDoc::Common::Ini;
21use pgBackRestDoc::Common::Log;
22use pgBackRestDoc::Common::String;
23use pgBackRestDoc::ProjectInfo;
24
25use pgBackRestTest::Common::DbVersion;
26use pgBackRestTest::Common::ExecuteTest;
27use pgBackRestTest::Common::HostGroupTest;
28use pgBackRestTest::Common::RunTest;
29use pgBackRestTest::Common::StorageRepo;
30use pgBackRestTest::Common::Wait;
31use pgBackRestTest::Env::Host::HostBackupTest;
32use pgBackRestTest::Env::Host::HostBaseTest;
33use pgBackRestTest::Env::Manifest;
34
35####################################################################################################################################
36# Test WAL size
37####################################################################################################################################
38use constant PG_WAL_SIZE_TEST                                       => 16777216;
39
40####################################################################################################################################
41# Host defaults
42####################################################################################################################################
43use constant HOST_PATH_SPOOL                                        => 'spool';
44use constant HOST_PATH_DB                                           => 'db';
45use constant HOST_PATH_DB_BASE                                      => 'base';
46
47####################################################################################################################################
48# new
49####################################################################################################################################
50sub new
51{
52    my $class = shift;          # Class name
53
54    # Assign function parameters, defaults, and log debug info
55    my
56    (
57        $strOperation,
58        $oParam,
59    ) =
60        logDebugParam
61        (
62            __PACKAGE__ . '->new', \@_,
63            {name => 'oParam', required => false, trace => true},
64        );
65
66    # Get host group
67    my $oHostGroup = hostGroupGet();
68
69    # Is standby?
70    my $bStandby = defined($$oParam{bStandby}) && $$oParam{bStandby} ? true : false;
71
72    my $self = $class->SUPER::new(
73        {
74            strName => $bStandby ? HOST_DB_STANDBY : HOST_DB_PRIMARY,
75            strImage => $$oParam{strImage},
76            strBackupDestination => $$oParam{strBackupDestination},
77            oLogTest => $$oParam{oLogTest},
78            bSynthetic => $$oParam{bSynthetic},
79            bRepoLocal => $oParam->{bRepoLocal},
80            bRepoEncrypt => $oParam->{bRepoEncrypt},
81        });
82    bless $self, $class;
83
84    # Set parameters
85    $self->{bStandby} = $bStandby;
86
87    $self->{strDbPath} = $self->testPath() . '/' . HOST_PATH_DB;
88    $self->{strDbBasePath} = $self->dbPath() . '/' . HOST_PATH_DB_BASE;
89    $self->{strTablespacePath} = $self->dbPath() . '/tablespace';
90
91    storageTest()->pathCreate($self->dbBasePath(), {strMode => '0700', bCreateParent => true});
92
93    $self->{strSpoolPath} = $self->testPath() . '/' . HOST_PATH_SPOOL;
94    storageTest()->pathCreate($self->spoolPath());
95
96    # Initialize linkRemap Hashes
97    $self->{hLinkRemap} = {};
98
99    # Return from function and log return values if any
100    return logDebugReturn
101    (
102        $strOperation,
103        {name => 'self', value => $self, trace => true}
104    );
105}
106
107####################################################################################################################################
108# archivePush
109####################################################################################################################################
110sub archivePush
111{
112    my $self = shift;
113
114    # Assign function parameters, defaults, and log debug info
115    my
116    (
117        $strOperation,
118        $strWalPath,
119        $strArchiveTestFile,
120        $iArchiveNo,
121        $iExpectedError,
122        $bAsync,
123        $strOptionalParam,
124    ) =
125        logDebugParam
126        (
127            __PACKAGE__ . '->archivePush', \@_,
128            {name => 'strWalPath'},
129            {name => 'strArchiveTestFile', required => false},
130            {name => 'iArchiveNo', required => false},
131            {name => 'iExpectedError', required => false},
132            {name => 'bAsync', default => true},
133            {name => 'strOptionalParam', required => false},
134        );
135
136    my $strSourceFile;
137
138    if (defined($strArchiveTestFile))
139    {
140        $strSourceFile = "${strWalPath}/" . uc(sprintf('0000000100000001%08x', $iArchiveNo));
141
142        storageTest()->copy($strArchiveTestFile, storageTest()->openWrite($strSourceFile, {bPathCreate => true}));
143
144        storageTest()->pathCreate("${strWalPath}/archive_status/", {bIgnoreExists => true, bCreateParent => true});
145        storageTest()->put("${strWalPath}/archive_status/" . uc(sprintf('0000000100000001%08x', $iArchiveNo)) . '.ready');
146    }
147
148    $self->executeSimple(
149        $self->backrestExe() .
150        ' --config=' . $self->backrestConfig() .
151        ' --log-level-console=warn --archive-push-queue-max=' . int(2 * PG_WAL_SIZE_TEST) .
152        ' --stanza=' . $self->stanza() .
153        ($bAsync ? '' : ' --no-archive-async') .
154        " archive-push" . (defined($strSourceFile) ? " ${strSourceFile}" : '') .
155        (defined($strOptionalParam) ? " ${strOptionalParam}" : ''),
156        {iExpectedExitStatus => $iExpectedError, oLogTest => $self->{oLogTest}, bLogOutput => $self->synthetic()});
157
158    # Return from function and log return values if any
159    return logDebugReturn($strOperation);
160}
161
162####################################################################################################################################
163# linkRemap
164####################################################################################################################################
165sub linkRemap
166{
167    my $self = shift;
168
169    # Assign function parameters, defaults, and log debug info
170    my
171    (
172        $strOperation,
173        $strTarget,
174        $strDestination
175    ) =
176        logDebugParam
177        (
178            __PACKAGE__ . '->linkRemap', \@_,
179            {name => 'strTarget'},
180            {name => 'strDestination'},
181        );
182
183    ${$self->{hLinkRemap}}{$strTarget} = $strDestination;
184
185    # Return from function and log return values if any
186    return logDebugReturn($strOperation);
187}
188
189####################################################################################################################################
190# Getters
191####################################################################################################################################
192sub dbPath {return shift->{strDbPath};}
193
194sub dbBasePath
195{
196    my $self = shift;
197    my $iIndex = shift;
198
199    return $self->{strDbBasePath} . (defined($iIndex) ? "-${iIndex}" : '');
200}
201
202sub spoolPath {return shift->{strSpoolPath}}
203sub standby {return shift->{bStandby}}
204
205sub tablespacePath
206{
207    my $self = shift;
208    my $iTablespace = shift;
209    my $iIndex = shift;
210
211    return
212        $self->{strTablespacePath} .
213        (defined($iTablespace) ? "/ts${iTablespace}" .
214        (defined($iIndex) ? "-${iIndex}" : '') : '');
215}
216
2171;
218