Re: lexical.pm last_use_label ignores "storage" field on tapelist

Jean-Louis Martineau <[email protected]> Mon, 12 Mar 2018 14:49:02 +0000
Newsgroups gmane.comp.archivers.amanda.devel
Message-ID <CY4PR06MB339853F1748757C2F38A5FCEC8D30@CY4PR06MB3398.namprd06.prod.outlook.com>
Nathan,

try this patch.

Jean-Louis
________________________________________
From: [email protected] <[email protected]> on behalf of Nathan Stratton Treadway <[email protected]>
Sent: March 12, 2018 8:38 AM
To: [email protected]
Subject: Re: lexical.pm last_use_label ignores "storage" field on tapelist

On Sun, Mar 11, 2018 at 19:58:07 -0400, Nathan Stratton Treadway wrote:
> I have two storages defined in my test environment, "TestBackup" with
> tables labeled TESTBACKUP-01 through TESTBACKUP-21 and "TestOffsite" with
> tapes labeled TESTBACKUP-101 through TESTBACKUP-109.
>
> I'm using the lexical taper scan algorithm (for both storages), and the
> TestBackup storage is a vtape array constantly left mounted (so all 21
> vtapes are always available).
>
> I noticed that when left to its own devices (for the "TestBackup"
> storage), Amanda seemed to jump right to tape TESTBACKUP-11 as soon as
> it was available for use (i.e. once it rolled out of the Tapecycle
> count).
>
> In attempting to track this down within at lexical.pm<http://lexical.pm>, I see that that
> the last_use_label() function ignores the storage parameter when
> searching the tapelist -- which means that in my case $last_label is
> always set to "TESTBACKUP-10x", and thus when the TestBackup tables are
> sorted lexically compared to that, TESTBACKUP-11 always comes up "next".

Looking back at my Amanda mail reports, I see that this cross-storage
label issue also explains why amdump frequently skips over
TESTBACKUP-109 and jumps to TESTBACKUP-101, even though "amcheck ...
-ostorage=TestOffsite" run right beforehand says the next run will write
to 109:

* when amcheck is run, TESTBACKUP-108 is the most recent tape in the
tapelist file, and the lexical taperscan correctly picks 109 as
the next tape "after" the current one.
* when amdump runs, it write to TESTBACKUP-03 (or TESTBACKUP-20 or
whatever), thus making that the most recent entry in the tapelist
file. Then when it starts up the the vault-storage phase, all of
the TESTBACKUP-10x tape labels sort either before or after that new
"last used" label, and TESTBACKUP-101 is chosen from the front of
the resulting list.


Nathan



----------------------------------------------------------------------------
Nathan Stratton Treadway - [email protected] - Mid-Atlantic region
Ray Ontko & Co. - Software consulting services - http://www.ontko.com/<http://www.ontko.com/>
GPG Key: http://www.ontko.com/~nathanst/gpg_key.txt<http://www.ontko.com/~nathanst/gpg_key.txt> ID: 1023D/ECFB6239
Key fingerprint = 6AD8 485E 20B9 5C71 231C 0C32 15F3 ADCD ECFB 6239
This message is the property of CARBONITE, INC. and may contain confidential or privileged information.
If this message has been delivered to you by mistake, then do not copy or deliver this message to anyone.  Instead, destroy it and notify me by reply e-mail
lexical.diff (text/x-patch, 977 B)
diff --git a/perl/Amanda/Taper/Scan/lexical.pm b/perl/Amanda/Taper/Scan/lexical.pm
index 030f8fd..53e8413 100644
--- a/perl/Amanda/Taper/Scan/lexical.pm
+++ b/perl/Amanda/Taper/Scan/lexical.pm
@@ -78,6 +78,22 @@ sub last_use_label {
     my $label = $tles->[0]->{'label'};
 }
 
+sub last_use_label_from_pool {
+    my $self = shift;
+
+    my $tles = $self->{'tapelist'}->{tles};
+    my $count = @{$tles};
+    for (my $i = 0; $i < $count ; $i++) {
+	my $tle = $tles->[$i];
+	if ($tle->{'datestamp'} != '0' &&
+	    (!defined $tle->{'pool'} ||
+	      $tle->{'pool'} eq $self->{'tapepool'})) {
+	    return $tle->{'label'};
+	}
+    }
+    return undef;
+}
+
 sub analyze {
     my $self = shift;
     my $inventory  = shift;
@@ -93,7 +109,7 @@ sub analyze {
     my @unknown;
     my @error;
 
-    my $last_label = $self->last_use_label();
+    my $last_label = $self->last_use_label_from_pool();
 
     for my $i (0..(scalar(@$inventory)-1)) {
 	my $sl = $inventory->[$i];