Skip to content

Commit

Permalink
Merge pull request #9 from andrii-suse/fix_deadlocks_stable
Browse files Browse the repository at this point in the history
Fix deadlocks stable
  • Loading branch information
darix authored Apr 2, 2020
2 parents d547fb8 + 66c6fb6 commit 6dacb59
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions tools/scanner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@


#$sql = "SELECT COUNT(*) FROM temp1";
$sql = "SELECT COUNT(mirr_del_byid($row->{id}, id)) FROM temp1";
$sql = "SELECT COUNT(mirr_del_byid($row->{id}, id) order by id) FROM temp1";
print "$sql\n" if $sqlverbose;
$ary_ref = $dbh->selectall_arrayref($sql) or die $dbh->errstr();
my $purge_file_count = defined($ary_ref->[0]) ? $ary_ref->[0][0] : 0;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ sub getfileid
# callback function
sub rsync_cb
{
my ($priv, $name, $len, $mode, $mtime, @info) = @_;
my ($priv, $name, $len, $mode, $mtime) = @_;
return 0 if $name eq '.' or $name eq '..';
my $r = 0;

Expand All @@ -1072,7 +1072,7 @@ sub rsync_cb
}
}

$r = [$name, $len, $mode, $mtime, @info];
$r = [$name, $len, $mode, $mtime];
printf "%s: rsync ADD: %03o %12.0f %-25s %-50s\n", $priv->{identifier}, ($mode & 0777), $len, scalar(localtime $mtime), $name if $verbose > 2;
}
}
Expand All @@ -1082,6 +1082,9 @@ sub rsync_cb
}
elsif($mode == 0755) {
printf "%s: rsync dir: %03o %12.0f %-25s %-50s\n", $priv->{identifier}, ($mode & 0777), $len, scalar(localtime $mtime), $name if $verbose > 1;
if($do_transaction) { # commit every directory to reduce chance of deadlocks
$dbh->commit or die "$DBI::errstr";
}
}
elsif($mode == 020777) {
printf "%s: rsync link: %03o %12.0f %-25s %-50s\n", $priv->{identifier}, ($mode & 0777), $len, scalar(localtime $mtime), $name if $verbose > 2;
Expand Down Expand Up @@ -1118,7 +1121,7 @@ sub rsync_readdir
$peer->{counter} = 0;
$path .= "/". $d if length $d;
eval{
rsync_get_filelist($identifier, $peer, $path, 0, \&rsync_cb, $peer)
rsync_get_filelist($identifier, $peer, $path, 0, \&rsync_cb, $peer, 1)
};
return $peer->{counter};
}
Expand Down Expand Up @@ -1198,7 +1201,7 @@ sub muxread

sub rsync_get_filelist
{
my ($identifier, $peer, $syncroot, $norecurse, $callback, $priv) = @_;
my ($identifier, $peer, $syncroot, $norecurse, $callback, $priv, $sorted) = @_;
my $syncaddr = $peer->{addr};
my $syncport = $peer->{port};

Expand Down Expand Up @@ -1296,26 +1299,30 @@ sub rsync_get_filelist
}
$mtime = unpack('V', muxread($identifier, *S, 4)) unless $flags & 0x80;
$mode = unpack('V', muxread($identifier, *S, 4)) unless $flags & 0x02;
my @info = ();
my $mmode = $mode & 07777;
if(($mode & 0170000) == 0100000) {
$mmode |= 0x1000;
} elsif (($mode & 0170000) == 0040000) {
$mmode |= 0x0000;
} elsif (($mode & 0170000) == 0120000) {
$mmode |= 0x2000;
my $ln = muxread($identifier, *S, unpack('V', muxread($identifier, *S, 4)));
@info = ($ln);
muxread($identifier, *S, unpack('V', muxread($identifier, *S, 4)));
} else {
print "$name: unknown mode: $mode\n";
next;
}
if($callback) {
my $r = &$callback($priv, $name, $len, $mmode, $mtime, @info);
push @filelist, $r if $r;
# sort and process buffer when folder changes
if ($callback && $sorted && !($mmode & 0x1000)) {
for my $file (sort {$a->[0] cmp $b->[0]} @filelist) {
&$callback($priv, $file->[0], $file->[1], $file->[2], $file->[3], $file->[4]);
}
@filelist = ();
}
if(!$sorted && $callback) {
&$callback($priv, $name, $len, $mmode, $mtime);
}
else {
push @filelist, [$name, $len, $mmode, $mtime, @info];
push @filelist, [$name, $len, $mmode, $mtime];
}
}
my $io_error = unpack('V', muxread($identifier, *S, 4));
Expand All @@ -1327,7 +1334,15 @@ sub rsync_get_filelist
swrite(*S, pack('V', -1)); # goodbye
}
close(S);
return @filelist;
if ($callback && $sorted) {
# sort and process remaining buffer
for my $file (sort {$a->[0] cmp $b->[0]} @filelist) {
&$callback($priv, $file->[0], $file->[1], $file->[2], $file->[3]);
}
}
return undef if $callback;
return @filelist unless $sorted;
return sort {$a->[0] cmp $b->[0]} @filelist;
}


Expand Down

0 comments on commit 6dacb59

Please sign in to comment.