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.30'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
91680
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
57
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
50
|
|
10
|
2
|
|
|
2
|
|
238
|
use JSON::MaybeXS (); |
|
2
|
|
|
|
|
4205
|
|
|
2
|
|
|
|
|
43
|
|
11
|
2
|
|
|
2
|
|
480
|
use Getopt::Long qw( GetOptions ); |
|
2
|
|
|
|
|
8198
|
|
|
2
|
|
|
|
|
11
|
|
12
|
2
|
|
|
2
|
|
602
|
use Pod::Usage qw( pod2usage ); |
|
2
|
|
|
|
|
42040
|
|
|
2
|
|
|
|
|
136
|
|
13
|
2
|
|
|
2
|
|
18
|
use feature 'say'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1688
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub main { |
16
|
5
|
|
|
5
|
0
|
29892
|
my $class = shift; |
17
|
5
|
|
|
|
|
22
|
local @ARGV = @_; |
18
|
5
|
|
|
|
|
11
|
my %servers; |
19
|
5
|
|
|
|
|
9
|
my $default_port = 9001; |
20
|
5
|
|
|
|
|
12
|
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
|
|
|
|
52
|
) || pod2usage(1); |
30
|
5
|
50
|
|
|
|
2238
|
my $digits = shift @ARGV or die "no number of digits given"; |
31
|
5
|
|
|
|
|
13
|
my @all; |
32
|
5
|
|
|
|
|
175
|
while (<>) { |
33
|
14
|
|
|
|
|
34
|
chomp; |
34
|
14
|
|
|
|
|
29
|
s/#.*$//; # remove comments |
35
|
14
|
50
|
|
|
|
47
|
next if /^\s*$/; # skip empty lines |
36
|
14
|
|
|
|
|
43
|
my ($host,$disk) = split; |
37
|
14
|
|
|
|
|
23
|
my $port; |
38
|
14
|
100
|
|
|
|
37
|
$port = $1 if $host =~ s/:(\d+)$//; |
39
|
14
|
|
|
|
|
26
|
$host =~ tr/a-zA-Z0-9.\-//dc; |
40
|
14
|
100
|
|
|
|
28
|
$host = join ':', $host, $port if $port; |
41
|
14
|
50
|
33
|
|
|
47
|
die "could not parse line : \"$_\"" unless $host && $disk; |
42
|
14
|
|
|
|
|
45
|
$servers{$host}{$disk} = []; |
43
|
14
|
|
|
|
|
80
|
push @all, $servers{$host}{$disk}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
11
|
my $i = 0; |
47
|
5
|
|
|
|
|
21
|
for my $bucket (0..16**$digits-1) { |
48
|
1040
|
|
|
|
|
1797
|
my $b = sprintf( '%0'.$digits.'x',$bucket); |
49
|
1040
|
|
|
|
|
1193
|
push @{ $all[$i] }, "$b"; |
|
1040
|
|
|
|
|
1728
|
|
50
|
1040
|
|
|
|
|
1227
|
$i++; |
51
|
1040
|
100
|
|
|
|
1741
|
$i = 0 if $i==@all; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
153
|
say '---'; |
55
|
5
|
|
|
|
|
37
|
say 'servers :'; |
56
|
5
|
|
|
|
|
31
|
for my $host (sort keys %servers) { |
57
|
8
|
100
|
|
|
|
76
|
say "- url : $protocol://" . ($host =~ /:\d+$/ ? $host : join(':', $host, $default_port)); |
58
|
8
|
|
|
|
|
39
|
say " disks :"; |
59
|
8
|
|
|
|
|
16
|
for my $root (sort keys %{ $servers{$host} }) { |
|
8
|
|
|
|
|
40
|
|
60
|
14
|
|
|
|
|
69
|
say " - root : $root"; |
61
|
14
|
|
|
|
|
60
|
print " buckets : ["; |
62
|
14
|
|
|
|
|
26
|
my $i = 1; |
63
|
14
|
|
|
|
|
25
|
for my $bucket (@{ $servers{$host}{$root} }) { |
|
14
|
|
|
|
|
41
|
|
64
|
1040
|
100
|
|
|
|
2070
|
print "\n " if $i++%14 == 0; |
65
|
1040
|
|
|
|
|
3594
|
print " $bucket"; |
66
|
1040
|
100
|
|
|
|
1460
|
print "," unless $i==@{ $servers{$host}{$root} }+1; |
|
1040
|
|
|
|
|
4782
|
|
67
|
|
|
|
|
|
|
} |
68
|
14
|
|
|
|
|
145
|
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 |