line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Yars::Command::yars_generate_diskmap; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# PODNAME: yars_generate_diskmap |
4
|
|
|
|
|
|
|
# ABSTRACT: generate a mapping from servers + hosts to buckets for yars. |
5
|
|
|
|
|
|
|
our $VERSION = '1.28'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
73368
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
49
|
|
9
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
40
|
|
10
|
2
|
|
|
2
|
|
361
|
use JSON::MaybeXS (); |
|
2
|
|
|
|
|
4301
|
|
|
2
|
|
|
|
|
54
|
|
11
|
2
|
|
|
2
|
|
549
|
use Getopt::Long qw( GetOptions ); |
|
2
|
|
|
|
|
7418
|
|
|
2
|
|
|
|
|
11
|
|
12
|
2
|
|
|
2
|
|
633
|
use Pod::Usage qw( pod2usage ); |
|
2
|
|
|
|
|
35951
|
|
|
2
|
|
|
|
|
174
|
|
13
|
2
|
|
|
2
|
|
15
|
use feature 'say'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1320
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub main { |
16
|
5
|
|
|
5
|
0
|
28626
|
my $class = shift; |
17
|
5
|
|
|
|
|
18
|
local @ARGV = @_; |
18
|
5
|
|
|
|
|
10
|
my %servers; |
19
|
5
|
|
|
|
|
8
|
my $default_port = 9001; |
20
|
5
|
|
|
|
|
9
|
my $protocol = 'http'; |
21
|
|
|
|
|
|
|
GetOptions( |
22
|
|
|
|
|
|
|
'port|p=i' => \$default_port, |
23
|
|
|
|
|
|
|
'protocol=s' => \$protocol, |
24
|
0
|
|
|
0
|
|
0
|
'help|h' => sub { pod2usage({ -verbose => 2}) }, |
25
|
|
|
|
|
|
|
'version' => sub { |
26
|
0
|
|
0
|
0
|
|
0
|
say 'Yars version ', ($Yars::Command::yars_generate_diskmap::VERSION // 'dev'); |
27
|
0
|
|
|
|
|
0
|
exit 1; |
28
|
|
|
|
|
|
|
}, |
29
|
5
|
50
|
|
|
|
33
|
) || pod2usage(1); |
30
|
5
|
50
|
|
|
|
2224
|
my $digits = shift @ARGV or die "no number of digits given"; |
31
|
5
|
|
|
|
|
10
|
my @all; |
32
|
5
|
|
|
|
|
145
|
while (<>) { |
33
|
14
|
|
|
|
|
32
|
chomp; |
34
|
14
|
|
|
|
|
23
|
s/#.*$//; # remove comments |
35
|
14
|
50
|
|
|
|
47
|
next if /^\s*$/; # skip empty lines |
36
|
14
|
|
|
|
|
37
|
my ($host,$disk) = split; |
37
|
14
|
|
|
|
|
24
|
my $port; |
38
|
14
|
100
|
|
|
|
38
|
$port = $1 if $host =~ s/:(\d+)$//; |
39
|
14
|
|
|
|
|
27
|
$host =~ tr/a-zA-Z0-9.\-//dc; |
40
|
14
|
100
|
|
|
|
30
|
$host = join ':', $host, $port if $port; |
41
|
14
|
50
|
33
|
|
|
57
|
die "could not parse line : \"$_\"" unless $host && $disk; |
42
|
14
|
|
|
|
|
39
|
$servers{$host}{$disk} = []; |
43
|
14
|
|
|
|
|
77
|
push @all, $servers{$host}{$disk}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
12
|
my $i = 0; |
47
|
5
|
|
|
|
|
19
|
for my $bucket (0..16**$digits-1) { |
48
|
1040
|
|
|
|
|
1929
|
my $b = sprintf( '%0'.$digits.'x',$bucket); |
49
|
1040
|
|
|
|
|
1421
|
push @{ $all[$i] }, "$b"; |
|
1040
|
|
|
|
|
1770
|
|
50
|
1040
|
|
|
|
|
1474
|
$i++; |
51
|
1040
|
100
|
|
|
|
2131
|
$i = 0 if $i==@all; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
120
|
say '---'; |
55
|
5
|
|
|
|
|
31
|
say 'servers :'; |
56
|
5
|
|
|
|
|
24
|
for my $host (sort keys %servers) { |
57
|
8
|
100
|
|
|
|
66
|
say "- url : $protocol://" . ($host =~ /:\d+$/ ? $host : join(':', $host, $default_port)); |
58
|
8
|
|
|
|
|
43
|
say " disks :"; |
59
|
8
|
|
|
|
|
15
|
for my $root (sort keys %{ $servers{$host} }) { |
|
8
|
|
|
|
|
33
|
|
60
|
14
|
|
|
|
|
77
|
say " - root : $root"; |
61
|
14
|
|
|
|
|
68
|
print " buckets : ["; |
62
|
14
|
|
|
|
|
25
|
my $i = 1; |
63
|
14
|
|
|
|
|
18
|
for my $bucket (@{ $servers{$host}{$root} }) { |
|
14
|
|
|
|
|
37
|
|
64
|
1040
|
100
|
|
|
|
2656
|
print "\n " if $i++%14 == 0; |
65
|
1040
|
|
|
|
|
4623
|
print " $bucket"; |
66
|
1040
|
100
|
|
|
|
1663
|
print "," unless $i==@{ $servers{$host}{$root} }+1; |
|
1040
|
|
|
|
|
5502
|
|
67
|
|
|
|
|
|
|
} |
68
|
14
|
|
|
|
|
133
|
say " ]"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub dense { |
74
|
0
|
|
|
0
|
0
|
|
my %servers = @_; |
75
|
|
|
|
|
|
|
# Alternative unreadable representation |
76
|
0
|
|
|
|
|
|
my @conf; |
77
|
0
|
|
|
|
|
|
for my $host (sort keys %servers) { |
78
|
|
|
|
|
|
|
push @conf, +{ url => "http://$host:9001", disks => [ |
79
|
0
|
|
|
|
|
|
map +{ root => $_, buckets => $servers{$host}{$_} }, keys %{ $servers{$host} } |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
]}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $out = JSON::MaybeXS->new->space_after->encode({ servers => \@conf }); |
84
|
0
|
|
|
|
|
|
$out =~ s/{/\n{/g; |
85
|
0
|
|
|
|
|
|
$out =~ s/\[/\n[/g; |
86
|
0
|
|
|
|
|
|
$out =~ s/\],/],\n/g; |
87
|
0
|
|
|
|
|
|
print $out,"\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Yars::Command::yars_generate_diskmap - code for yars_generate_diskmap |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This module contains the machinery for the command line program L<yars_generate_diskmap> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SEE ALSO |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L<yars_disk_scan> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |