Skip to content
Permalink
Browse files

Merge pull request #382 from phreaker0/fix-snapshot-ordering

fixed ordering of snapshots with the same creation timestamp
  • Loading branch information...
jimsalterjrs committed May 15, 2019
2 parents dd47dd5 + 522bdec commit e320462c69e44be21ec6f0327c37579571631f80
Showing with 20 additions and 1 deletion.
  1. +20 −1 syncoid
21 syncoid
@@ -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;
}
}

0 comments on commit e320462

Please sign in to comment.
You can’t perform that action at this time.