Skip to content

Commit

Permalink
mxmirror: Remove dead code (GroupMirrots*)
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed May 13, 2019
1 parent bf832ee commit 8df9b2d
Showing 1 changed file with 0 additions and 240 deletions.
240 changes: 0 additions & 240 deletions mxmirror/mxmirror
Original file line number Diff line number Diff line change
Expand Up @@ -40,246 +40,6 @@ my $hostip = inet_ntoa(scalar gethostbyname($fullhostname));
my $jbodmap = read_jbodmap($JBODMAP);
my $mirrors = read_mirrormap($MIRRORMAP);

#print Dumper GroupMirrors($mirrors);

#exit;

sub GroupMirrors {
my $list = shift;

my $nrofslots = 100;

my @slots = ();

my $nlist = {};

my @hosts = sort keys %{$list};

my $grpptr = {};

my $groups = [];

my $ngrps=0;


foreach my $host (@hosts) {
my @dest = @{$list->{$host}};
foreach my $dest (@dest) {
my $dhost = $dest->{destination}->{host};
my ($grp, $dgrp);

if(not exists $grpptr->{$host}) {
if(not exists $grpptr->{$dhost}) {
$grp = [ ];
$grpptr->{$dhost} = $grp;
push @{$groups}, $grp;
} else {
$grp = $grpptr->{$dhost};
}
$grpptr->{$host} = $grp;
} else {
$grp = $grpptr->{$host};

if(exists $grpptr->{$dhost}) {
$dgrp = $grpptr->{$dhost};

# merge groups if different
if($grp ne $dgrp) {
push @{$grp}, @{$dgrp};
@{$groups} = grep { $_ ne $dgrp } @{$groups};
}
}
$grpptr->{$dhost} = $grp;
}

push @{$grp}, $dest;

}
}

print Dumper $grpptr;
# exit;

for(my $i=0; $i < @{$groups}; $i++) {
print "group $i\n";

my $grp = $groups->[$i];

my %dummy = ();

foreach my $m (@{$grp}) {
my $host = $m->{source}{host};
my $dhost = $m->{destination}{host};
push @{$dummy{"$host,$dhost"}}, $m;
print " $host -> $dhost\n";
}


print Dumper \%dummy;

@{$grp} = sort { $a->[0]{source}{host} cmp $b->[0]{source}{host} } values %dummy;
# @{$grp} = map { $dummy{$_} } sort keys %dummy;
}

print Dumper $groups;

exit;
return $groups;

}

sub GroupMirrors3 {
my $list = shift;

my $nrofslots = 100;

my @slots = ();

my $nlist = {};

my @hosts = sort keys %{$list};

foreach my $host (@hosts) {
my @dest = @{$list->{$host}};
foreach my $dest (@dest) {
my $dhost = $dest->{destination}->{host};

if(not exists $nlist->{$host}{$dhost} and $host ne $dhost) {
$nlist->{$host}{__cnt}++;
$nlist->{$dhost}{__cnt}++;
push @{$nlist->{$dhost}{__hosts}}, $host;


}

$nlist->{$host}{$dhost} = 1;

# push @{$nlist->{$host}{$dhost}{to}}, $dest;
}
}


foreach my $host (sort {$nlist->{$b}{__cnt} <=> $nlist->{$a}{__cnt} || $a cmp $b} keys %{$nlist}) {


my $cnt = $nlist->{$host}{__cnt};
print "$host $cnt\n";
my $ds = $cnt?$nrofslots/$cnt:1;

my $s = 0;

print "XXXX $host $nlist->{$host}{__cnt} $ds\n";

for($s=0; defined $slots[$s] and $s < $nrofslots; $s++) {

}

print " => first free slot: $s\n";

for(my $i=0; $i < $cnt; $i++) {
$slots[$s] = $host;
print " -> $s : $host\n";
$s += $ds;
}
}

print "RETURN..";
return $nlist;


}
sub GroupMirrors2 {
my $list = shift;

my $a = {};

my @hosts = sort keys %{$list};
foreach my $h (@hosts) {

unless(exists $a->{$h}) {
$a->{$h} = {
name => $h,
destinations => [],
sources => []
}
}
my $this = $a->{$h};

foreach(@{$list->{$h}}) {

my $d = $_->{destination}->{host};

unless(exists $a->{$d}) {
$a->{$d} = {
name => $d,
destinations => [],
sources => []
}
}

my $that = $a->{$d};

push @{$this->{destinations}}, $that;
push @{$that->{sources}}, $this;

}
}

foreach(keys %$a) {
unless(@{$a->{$_}->{destinations}}) {
printf "ENDPOINT: $_\n";
delete $a->{$_}
}
}

my $grps = {};

foreach(keys %$a) {
next unless defined $a->{$_};

my @g = check_a($a->{$_});

my @group = ();

map { push @group, $a->{$_}; delete $a->{$_} } @g;

# print "@g\n";
# print Dumper \@group;

$grps->{"@g"}->{group} = [ @group ];

}

foreach my $g (keys %$grps) {
my $dest = {};
foreach my $host (split / /, $g) {
next unless exists $list->{$host};
printf "$g :: $host\n";
foreach my $m (@{$list->{$host}}) {
$dest->{"$host $m->{destination}->{host}"} = [ $host, $m->{destination}->{host} ];

if($host eq $m->{destination}->{host}) {
$dest->{$host}->{"self-$m->{destination}->{host}"}->{self} = $host;
} else {
$dest->{$host}->{"to-$m->{destination}->{host}"}->{to} = $m->{destination}->{host};
$dest->{$m->{destination}->{host}}->{"from-$host"}->{from} = $host;
}
}
}



print Dumper $dest;

}



return $grps;

}


sub check_a {
my $a = shift;
my $href = shift || {};
Expand Down

0 comments on commit 8df9b2d

Please sign in to comment.