Skip to content

Commit

Permalink
Reorder info command text output so most recent backup is output last.
Browse files Browse the repository at this point in the history
After a stanza-upgrade backups for the old cluster are displayed until they expire.  Cluster info was output newest to oldest which meant after an upgrade the most recent backup would no longer be output last.

Update the text output ordering so the most recent backup is always output last.

Contributed by Cynthia Shang.
Suggested by Ryan Lambert.
  • Loading branch information
cmwshang authored and dwsteele committed Dec 14, 2018
1 parent 205525b commit 35bbb5b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
14 changes: 14 additions & 0 deletions doc/xml/release.xml
Expand Up @@ -45,6 +45,15 @@
</release-bug-list>

<release-improvement-list>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="ryan.lambert"/>
<release-item-contributor id="cynthia.shang"/>
</release-item-contributor-list>

<p>Reorder <cmd>info</cmd> command text output so most recent backup is output last.</p>
</release-item>

<release-item>
<p>Change file ownership only when required.</p>
</release-item>
Expand Down Expand Up @@ -6122,6 +6131,11 @@
<contributor-id type="github">rdunklau</contributor-id>
</contributor>

<contributor id="ryan.lambert">
<contributor-name-display>Ryan Lambert</contributor-name-display>
<contributor-id type="github">rustprooflabs</contributor-id>
</contributor>

<contributor id="sarah.conway">
<contributor-name-display>Sarah Conway</contributor-name-display>
<contributor-id type="github">xenophenes</contributor-id>
Expand Down
15 changes: 7 additions & 8 deletions lib/pgBackRest/Info.pm
Expand Up @@ -192,13 +192,14 @@ sub formatText
# Output stanza name and status
$strOutput .= (defined($strOutput) ? "\n" : '') . $self->formatTextStanza($oStanzaInfo) . "\n";

# Initialize the flag to indicate the first DB in the INFO_BACKUP_SECTION_DB is the current database
my $bDbCurrent = true;
# Get the current DB info (always last element in the array)
my $hDbCurrent = @{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}}[-1];

# Loop through the DB history array for the stanza from newest to oldest
foreach my $hDbInfo (reverse @{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}})
# Loop through the DB history array for the stanza from oldest to newest
foreach my $hDbInfo (@{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}})
{
if ($bDbCurrent)

if ($hDbInfo->{&INFO_HISTORY_ID} == $hDbCurrent->{&INFO_HISTORY_ID})
{
$strOutput .= "\n db (current)";
}
Expand Down Expand Up @@ -237,7 +238,7 @@ sub formatText

if (defined($strOutputArchive) || defined($strOutputBackup))
{
if (!$bDbCurrent)
if ($hDbInfo->{&INFO_HISTORY_ID} != $hDbCurrent->{&INFO_HISTORY_ID})
{
$strOutput .= "\n db (prior)";
}
Expand All @@ -252,8 +253,6 @@ sub formatText
$strOutput .= $strOutputBackup;
}
}

$bDbCurrent = false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/command/info/info.c
Expand Up @@ -412,8 +412,8 @@ formatTextDb(const KeyValue *stanzaInfo, String *resultStr)
VariantList *archiveSection = kvGetList(stanzaInfo, varNewStr(KEY_ARCHIVE_STR));
VariantList *backupSection = kvGetList(stanzaInfo, varNewStr(STANZA_KEY_BACKUP_STR));

// For each database find the corresponding archive and backup info
for (unsigned int dbIdx = 0; dbIdx < varLstSize(dbSection); dbIdx++)
// For each database (working from oldest to newest) find the corresponding archive and backup info
for (unsigned int dbIdx = varLstSize(dbSection) - 1; (int)dbIdx >= 0; dbIdx--)
{
KeyValue *pgInfo = varKv(varLstGet(dbSection, dbIdx));
uint64_t dbId = varUInt64(kvGet(pgInfo, varNewStr(DB_KEY_ID_STR)));
Expand Down
11 changes: 5 additions & 6 deletions src/perl/embed.auto.c
Expand Up @@ -10484,11 +10484,12 @@ static const EmbeddedModule embeddedModule[] =
"\n"
"$strOutput .= (defined($strOutput) ? \"\\n\" : '') . $self->formatTextStanza($oStanzaInfo) . \"\\n\";\n"
"\n\n"
"my $bDbCurrent = true;\n"
"my $hDbCurrent = @{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}}[-1];\n"
"\n\n"
"foreach my $hDbInfo (reverse @{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}})\n"
"foreach my $hDbInfo (@{$oStanzaInfo->{&INFO_BACKUP_SECTION_DB}})\n"
"{\n"
"if ($bDbCurrent)\n"
"\n"
"if ($hDbInfo->{&INFO_HISTORY_ID} == $hDbCurrent->{&INFO_HISTORY_ID})\n"
"{\n"
"$strOutput .= \"\\n db (current)\";\n"
"}\n"
Expand Down Expand Up @@ -10525,7 +10526,7 @@ static const EmbeddedModule embeddedModule[] =
"\n"
"if (defined($strOutputArchive) || defined($strOutputBackup))\n"
"{\n"
"if (!$bDbCurrent)\n"
"if ($hDbInfo->{&INFO_HISTORY_ID} != $hDbCurrent->{&INFO_HISTORY_ID})\n"
"{\n"
"$strOutput .= \"\\n db (prior)\";\n"
"}\n"
Expand All @@ -10540,8 +10541,6 @@ static const EmbeddedModule embeddedModule[] =
"$strOutput .= $strOutputBackup;\n"
"}\n"
"}\n"
"\n"
"$bDbCurrent = false;\n"
"}\n"
"}\n"
"\n\n"
Expand Down
12 changes: 6 additions & 6 deletions test/lib/pgBackRestTest/Module/Info/InfoUnitPerlTest.pm
Expand Up @@ -346,6 +346,12 @@ sub run
$hyStanza = $oInfo->stanzaList($self->stanza());
$self->testResult(sub {$oInfo->formatText($hyStanza)},
"stanza: db\n status: ok\n cipher: none\n" .
"\n db (prior)\n" .
" full backup: 20161206-155728F\n" .
" timestamp start/stop: 2016-12-06 15:57:28 / 2016-12-06 15:57:28\n" .
" wal start/stop: n/a\n" .
" database size: 0B, backup size: 0B\n" .
" repository size: 0B, repository backup size: 0B\n" .
"\n db (current)\n" .
" wal archive min/max (9.5-2): 000000010000000000000000 / 000000010000000000000003\n\n" .
" full backup: 20161207-155728F\n" .
Expand All @@ -357,12 +363,6 @@ sub run
" timestamp start/stop: 2016-12-08 15:57:28 / 2016-12-08 15:57:28\n" .
" wal start/stop: 000000010000000000000002 / 000000010000000000000002\n" .
" database size: 0B, backup size: 0B\n" .
" repository size: 0B, repository backup size: 0B\n" .
"\n db (prior)\n" .
" full backup: 20161206-155728F\n" .
" timestamp start/stop: 2016-12-06 15:57:28 / 2016-12-06 15:57:28\n" .
" wal start/stop: n/a\n" .
" database size: 0B, backup size: 0B\n" .
" repository size: 0B, repository backup size: 0B\n",
"formatText() multiple DB versions");

Expand Down
12 changes: 6 additions & 6 deletions test/src/module/command/infoTest.c
Expand Up @@ -327,9 +327,6 @@ testRun(void)
" status: ok\n"
" cipher: none\n"
"\n"
" db (current)\n"
" wal archive min/max (9.4-3): none present\n"
"\n"
" db (prior)\n"
" wal archive min/max (9.4-1): 000000010000000000000002/000000020000000000000003\n"
"\n"
Expand All @@ -338,6 +335,9 @@ testRun(void)
" wal start/stop: n/a\n"
" database size: 25.7MB, backup size: 25.7MB\n"
" repository size: 3MB, repository backup size: 3KB\n"
"\n"
" db (current)\n"
" wal archive min/max (9.4-3): none present\n"
,"text - single stanza, valid backup, no priors, no archives in latest DB");

// backup.info/archive.info files exist, backups exist, archives exist
Expand Down Expand Up @@ -632,9 +632,6 @@ testRun(void)
" status: ok\n"
" cipher: none\n"
"\n"
" db (current)\n"
" wal archive min/max (9.5-2): none present\n"
"\n"
" db (prior)\n"
" wal archive min/max (9.4-1): 000000010000000000000002/000000020000000000000003\n"
"\n"
Expand All @@ -658,6 +655,9 @@ testRun(void)
" repository size: 2.3MB, repository backup size: 346B\n"
" backup reference list: 20181119-152138F, 20181119-152138F_20181119-152152D\n"
"\n"
" db (current)\n"
" wal archive min/max (9.5-2): none present\n"
"\n"
"stanza: stanza2\n"
" status: error (no valid backups)\n"
" cipher: none\n"
Expand Down

1 comment on commit 35bbb5b

@rustprooflabs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray! Thank you! :)

Please sign in to comment.