| Line 29... |
Line 29... |
| 29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
| 30 |
#
|
30 |
#
|
| 31 |
# v1.3.0 20250511 RWR
|
31 |
# v1.3.0 20250511 RWR
|
| 32 |
# Added balance function. If called, will attempt to balance a cluster so that the variance is lower than balance_max_variance
|
32 |
# Added balance function. If called, will attempt to balance a cluster so that the variance is lower than balance_max_variance
|
| 33 |
# (new entry in config file). --dryrun will simply display the commands sent, and --nodryrun will execute them.
|
33 |
# (new entry in config file). --dryrun will simply display the commands sent, and --nodryrun will execute them.
|
| - |
|
34 |
#
|
| - |
|
35 |
# v1.3.0 20250514 RWR
|
| - |
|
36 |
# Modified so it will not issue error codes if we have done iterations but not perfectly in balance. Also, added message
|
| - |
|
37 |
# 'already in balance' if it is as good as we can get it.
|
| - |
|
38 |
#
|
| 34 |
|
39 |
|
| 35 |
|
40 |
|
| 36 |
|
41 |
|
| 37 |
package cluster;
|
42 |
package cluster;
|
| 38 |
|
43 |
|
| Line 40... |
Line 45... |
| 40 |
use strict;
|
45 |
use strict;
|
| 41 |
|
46 |
|
| 42 |
# define the version number
|
47 |
# define the version number
|
| 43 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
48 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
| 44 |
use version;
|
49 |
use version;
|
| 45 |
our $VERSION = version->declare("1.3.0");
|
50 |
our $VERSION = version->declare("1.3.1");
|
| 46 |
|
51 |
|
| 47 |
|
52 |
|
| 48 |
use Data::Dumper;
|
53 |
use Data::Dumper;
|
| 49 |
|
54 |
|
| 50 |
use Exporter;
|
55 |
use Exporter;
|
| Line 351... |
Line 356... |
| 351 |
}
|
356 |
}
|
| 352 |
|
357 |
|
| 353 |
# simulates performing migrations. Simply moves entries from $from to $to in $main::statusDB->{'nodePopulation'}
|
358 |
# simulates performing migrations. Simply moves entries from $from to $to in $main::statusDB->{'nodePopulation'}
|
| 354 |
sub doActions {
|
359 |
sub doActions {
|
| 355 |
my $actions = shift;
|
360 |
my $actions = shift;
|
| 356 |
my $return;
|
361 |
my $return = '';
|
| 357 |
for ( my $i = 0; $i < @$actions; $i++ ) {
|
362 |
for ( my $i = 0; $i < @$actions; $i++ ) {
|
| 358 |
my ($domain, $source, $target, $size ) = split( "\t", $actions->[$i] );
|
363 |
my ($domain, $source, $target, $size ) = split( "\t", $actions->[$i] );
|
| 359 |
$return .= &main::migrate( $domain, $target, $source );
|
364 |
$return .= &main::migrate( $domain, $target, $source );
|
| 360 |
delete $main::statusDB->{'nodePopulation'}->{$source}->{'running'}->{$domain};
|
365 |
delete $main::statusDB->{'nodePopulation'}->{$source}->{'running'}->{$domain};
|
| 361 |
$main::statusDB->{'nodePopulation'}->{$target}->{'running'}->{$domain} = time;
|
366 |
$main::statusDB->{'nodePopulation'}->{$target}->{'running'}->{$domain} = time;
|
| Line 369... |
Line 374... |
| 369 |
# of it (see https://en.wikipedia.org/wiki/Standard_deviation). If that is
|
374 |
# of it (see https://en.wikipedia.org/wiki/Standard_deviation). If that is
|
| 370 |
# over about a 10, we move things around, if possible, then check our variance
|
375 |
# over about a 10, we move things around, if possible, then check our variance
|
| 371 |
# again.
|
376 |
# again.
|
| 372 |
sub balance {
|
377 |
sub balance {
|
| 373 |
&main::readDB();
|
378 |
&main::readDB();
|
| 374 |
my $return;
|
379 |
my $return = '';
|
| 375 |
# get the current cluster status
|
380 |
# get the current cluster status
|
| 376 |
my $cluster = &getClusterStats();
|
381 |
my $cluster = &getClusterStats();
|
| 377 |
#die Dumper( $cluster ) . "\n";
|
382 |
#die Dumper( $cluster ) . "\n";
|
| 378 |
# show user what it looks like at first
|
383 |
# show user what it looks like at first
|
| 379 |
print "=== Starting Status ===\n\n" . &showBalanceReport( $cluster) unless $main::config->{'flags'}->{'quiet'};
|
384 |
print "=== Starting Status ===\n\n" . &showBalanceReport( $cluster) unless $main::config->{'flags'}->{'quiet'};
|
| Line 382... |
Line 387... |
| 382 |
my $iterations = defined $main::config->{ 'balance_max_iterations'} && $main::config->{ 'balance_max_iterations'} ? $main::config->{ 'balance_max_iterations'} : 10;
|
387 |
my $iterations = defined $main::config->{ 'balance_max_iterations'} && $main::config->{ 'balance_max_iterations'} ? $main::config->{ 'balance_max_iterations'} : 10;
|
| 383 |
$main::config->{ 'balance_max_variance'} = 1.1 unless defined $main::config->{ 'balance_max_variance'};
|
388 |
$main::config->{ 'balance_max_variance'} = 1.1 unless defined $main::config->{ 'balance_max_variance'};
|
| 384 |
# continue until our variance is where we want it, or we have tried too many times.
|
389 |
# continue until our variance is where we want it, or we have tried too many times.
|
| 385 |
while ( $iterations-- && $cluster->{'cluster'}->{'variance'} > $main::config->{ 'balance_max_variance'} ) {
|
390 |
while ( $iterations-- && $cluster->{'cluster'}->{'variance'} > $main::config->{ 'balance_max_variance'} ) {
|
| 386 |
my $actions = &moveThings( $cluster );
|
391 |
my $actions = &moveThings( $cluster );
|
| 387 |
$return .= &doActions( $actions );
|
392 |
if ( my $output = &doActions( $actions ) ) {
|
| - |
|
393 |
$return .= $output;
|
| - |
|
394 |
} else {
|
| - |
|
395 |
last;
|
| 388 |
|
396 |
}
|
| 389 |
#print Dumper( $actions ) . "\n"; die;
|
397 |
#print Dumper( $actions ) . "\n"; die;
|
| 390 |
# rerun stats
|
398 |
# rerun stats
|
| 391 |
$cluster = &getClusterStats();
|
399 |
$cluster = &getClusterStats();
|
| 392 |
print &showBalanceReport( $cluster) if $main::config->{'flags'}->{'verbose'} > 1;
|
400 |
print &showBalanceReport( $cluster) if $main::config->{'flags'}->{'verbose'} > 1;
|
| 393 |
}
|
401 |
}
|
| 394 |
print "=== Ending Status ===\n\n" . &showBalanceReport( $cluster) unless $main::config->{'flags'}->{'quiet'};
|
402 |
print "=== Ending Status ===\n\n" . &showBalanceReport( $cluster) unless $main::config->{'flags'}->{'quiet'};
|
| 395 |
return $return;
|
403 |
return $return ? $return : "Already Balanced: No actions to take\n";
|
| 396 |
} # balance
|
404 |
} # balance
|
| 397 |
|
405 |
|
| 398 |
# finds node which needs to lose ($from) and gain ($to) the most. Then, goes through $from and finds the largest
|
406 |
# finds node which needs to lose ($from) and gain ($to) the most. Then, goes through $from and finds the largest
|
| 399 |
# domain which will fit on $to until exhausted.
|
407 |
# domain which will fit on $to until exhausted.
|
| 400 |
# as each domain is found, appends to $actions (array pointer). The format of each entry is a tab separated
|
408 |
# as each domain is found, appends to $actions (array pointer). The format of each entry is a tab separated
|