fixed ordering of snapshots with the same creation timestamp

This commit is contained in:
Christoph Klaffl 2019-05-15 16:47:51 +02:00
parent 8d8df7e533
commit 522bdecd53
No known key found for this signature in database
GPG Key ID: FC1C525C2A47CC28
1 changed files with 20 additions and 1 deletions

21
syncoid
View File

@ -1393,6 +1393,8 @@ sub getsnaps() {
# this is a little obnoxious. get guid,creation returns guid,creation on two separate lines
# as though each were an entirely separate get command.
my %creationtimes=();
foreach my $line (@rawsnaps) {
# only import snap guids from the specified filesystem
if ($line =~ /\Q$fs\E\@.*guid/) {
@ -1413,7 +1415,24 @@ sub getsnaps() {
$creation =~ s/^.*\tcreation\t*(\d*).*/$1/;
my $snap = $line;
$snap =~ s/^.*\@(.*)\tcreation.*$/$1/;
$snaps{$type}{$snap}{'creation'}=$creation;
# the accuracy of the creation timestamp is only for a second, but
# snapshots in the same second are highly likely. The list command
# has an ordered output so we append another three digit running number
# to the creation timestamp and make sure those are ordered correctly
# for snapshot with the same creation timestamp
my $counter = 0;
my $creationsuffix;
while ($counter < 999) {
$creationsuffix = sprintf("%s%03d", $creation, $counter);
if (!defined $creationtimes{$creationsuffix}) {
$creationtimes{$creationsuffix} = 1;
last;
}
$counter += 1;
}
$snaps{$type}{$snap}{'creation'}=$creationsuffix;
}
}