fixed syncoid regression in #112 (sort creation, match guid)

This commit is contained in:
jimsalterjrs 2017-07-17 09:44:07 -04:00
parent 00cb721922
commit 2bf3547eb5
2 changed files with 25 additions and 7 deletions

View File

@ -1,3 +1,6 @@
1.4.14 fixed significant regression in syncoid - now pulls creation AND guid on each snap; sorts by
creation and matches by guid. regression reported in #112 by @da-me, thank you!
1.4.13 Syncoid will now continue trying to replicate other child datasets after one dataset fails replication 1.4.13 Syncoid will now continue trying to replicate other child datasets after one dataset fails replication
when called recursively. Eg syncoid -r source/parent target/parent when source/parent/child1 has been when called recursively. Eg syncoid -r source/parent target/parent when source/parent/child1 has been
deleted and replaced with an imposter will no longer prevent source/parent/child2 from successfully deleted and replaced with an imposter will no longer prevent source/parent/child2 from successfully

29
syncoid
View File

@ -4,7 +4,7 @@
# from http://www.gnu.org/licenses/gpl-3.0.html on 2014-11-17. A copy should also be available in this # from http://www.gnu.org/licenses/gpl-3.0.html on 2014-11-17. A copy should also be available in this
# project's Git repository at https://github.com/jimsalterjrs/sanoid/blob/master/LICENSE. # project's Git repository at https://github.com/jimsalterjrs/sanoid/blob/master/LICENSE.
my $version = '1.4.13'; my $version = '1.4.14';
use strict; use strict;
use warnings; use warnings;
@ -629,7 +629,7 @@ sub readablebytes {
sub getoldestsnapshot { sub getoldestsnapshot {
my $snaps = shift; my $snaps = shift;
foreach my $snap ( sort { $snaps{'source'}{$a}{'guid'}<=>$snaps{'source'}{$b}{'guid'} } keys %{ $snaps{'source'} }) { foreach my $snap ( sort { $snaps{'source'}{$a}{'creation'}<=>$snaps{'source'}{$b}{'creation'} } keys %{ $snaps{'source'} }) {
# return on first snap found - it's the oldest # return on first snap found - it's the oldest
return $snap; return $snap;
} }
@ -643,7 +643,7 @@ sub getoldestsnapshot {
sub getnewestsnapshot { sub getnewestsnapshot {
my $snaps = shift; my $snaps = shift;
foreach my $snap ( sort { $snaps{'source'}{$b}{'guid'}<=>$snaps{'source'}{$a}{'guid'} } keys %{ $snaps{'source'} }) { foreach my $snap ( sort { $snaps{'source'}{$b}{'creation'}<=>$snaps{'source'}{$a}{'creation'} } keys %{ $snaps{'source'} }) {
# return on first snap found - it's the newest # return on first snap found - it's the newest
print "NEWEST SNAPSHOT: $snap\n"; print "NEWEST SNAPSHOT: $snap\n";
return $snap; return $snap;
@ -774,7 +774,7 @@ sub pruneoldsyncsnaps {
sub getmatchingsnapshot { sub getmatchingsnapshot {
my ($targetsize, $snaps) = shift; my ($targetsize, $snaps) = shift;
foreach my $snap ( sort { $snaps{'source'}{$b}{'guid'}<=>$snaps{'source'}{$a}{'guid'} } keys %{ $snaps{'source'} }) { foreach my $snap ( sort { $snaps{'source'}{$b}{'creation'}<=>$snaps{'source'}{$a}{'creation'} } keys %{ $snaps{'source'} }) {
if (defined $snaps{'target'}{$snap}{'guid'}) { if (defined $snaps{'target'}{$snap}{'guid'}) {
if ($snaps{'source'}{$snap}{'guid'} == $snaps{'target'}{$snap}{'guid'}) { if ($snaps{'source'}{$snap}{'guid'} == $snaps{'target'}{$snap}{'guid'}) {
return $snap; return $snap;
@ -871,15 +871,18 @@ sub getsnaps() {
if ($rhost ne '') { $rhost = "$sshcmd $rhost"; } if ($rhost ne '') { $rhost = "$sshcmd $rhost"; }
my $getsnapcmd = "$rhost $mysudocmd $zfscmd get -Hpd 1 -t snapshot guid $fs |"; my $getsnapcmd = "$rhost $mysudocmd $zfscmd get -Hpd 1 -t snapshot guid,creation $fs |";
if ($debug) { print "DEBUG: getting list of snapshots on $fs using $getsnapcmd...\n"; } if ($debug) { print "DEBUG: getting list of snapshots on $fs using $getsnapcmd...\n"; }
open FH, $getsnapcmd; open FH, $getsnapcmd;
my @rawsnaps = <FH>; my @rawsnaps = <FH>;
close FH; close FH;
# this is a little obnoxious. get guid,creation returns guid,creation on two separate lines
# as though each were an entirely separate get command.
foreach my $line (@rawsnaps) { foreach my $line (@rawsnaps) {
# only import snaps from the specified filesystem # only import snap guids from the specified filesystem
if ($line =~ /$fs\@/) { if ($line =~ /$fs\@.*guid/) {
chomp $line; chomp $line;
my $guid = $line; my $guid = $line;
$guid =~ s/^.*\sguid\s*(\d*).*/$1/; $guid =~ s/^.*\sguid\s*(\d*).*/$1/;
@ -889,6 +892,18 @@ sub getsnaps() {
} }
} }
foreach my $line (@rawsnaps) {
# only import snap creations from the specified filesystem
if ($line =~ /$fs\@.*creation/) {
chomp $line;
my $creation = $line;
$creation =~ s/^.*\screation\s*(\d*).*/$1/;
my $snap = $line;
$snap =~ s/^\S*\@(\S*)\s*creation.*$/$1/;
$snaps{$type}{$snap}{'creation'}=$creation;
}
}
return %snaps; return %snaps;
} }