74 |
|
|
75 |
my $session; |
my $session; |
76 |
|
|
77 |
|
sub all_ports { keys %{ $session->{port} } } |
78 |
|
|
79 |
sub to_all { |
sub to_all { |
80 |
my $data = shift; |
my $data = shift; |
81 |
foreach my $port ( keys %{ $session->{port} } ) { |
foreach my $port ( all_ports ) { |
82 |
warn ">>>> [$port]\n" if $debug; |
warn ">>>> [$port]\n" if $debug; |
83 |
Storable::store_fd( $data, $session->{port}->{$port} ); |
Storable::store_fd( $data, $session->{port}->{$port} ); |
84 |
} |
} |
90 |
|
|
91 |
warn "# load_shard $shard\n"; |
warn "# load_shard $shard\n"; |
92 |
|
|
93 |
my @shards = glob "$shard/*"; |
$shard .= '/*' if -d $shard; |
94 |
|
|
95 |
|
my @shards = glob $shard; |
96 |
|
|
97 |
if ( ! @shards ) { |
if ( ! @shards ) { |
98 |
warn "no shards for $shard\n"; |
warn "no shards for $shard\n"; |
99 |
return; |
return; |
100 |
} |
} |
101 |
|
|
102 |
$info->{shard}->{$_} = 'wait' foreach @shards; |
foreach my $s ( @shards ) { |
103 |
warn "loading shard $shard from ", dump( @shards ); |
if ( my $node = $info->{shard}->{$s} ) { |
104 |
|
next if $node =~ m{^\d+$}; # not node number |
105 |
push @shard_load_queue, @shards; |
} |
106 |
|
$info->{shard}->{$s} = 'wait'; |
107 |
|
push @shard_load_queue, $s; |
108 |
|
warn "queued $s for loading\n"; |
109 |
|
} |
110 |
to_all { load => $shard }; |
to_all { load => $shard }; |
111 |
|
$info->{pending}->{$_} = 'load' foreach all_ports; |
112 |
} |
} |
113 |
|
|
114 |
sub run_view { |
sub run_view { |
121 |
Sack::Merge->clean; |
Sack::Merge->clean; |
122 |
delete( $info->{view} ); |
delete( $info->{view} ); |
123 |
delete( $info->{merge} ); |
delete( $info->{merge} ); |
124 |
|
delete( $info->{shard} ); |
125 |
|
$info->{pending}->{$_} = 'view' foreach all_ports; |
126 |
to_all { code => $code, view => $path }; |
to_all { code => $code, view => $path }; |
127 |
}; |
}; |
128 |
|
|
129 |
|
our @responses; |
130 |
|
|
131 |
while (1) { |
while (1) { |
132 |
for my $sock ($sel->can_read(1)) { |
for my $sock ($sel->can_read(1)) { |
133 |
if ($sock == $lsn) { |
if ($sock == $lsn) { |
172 |
warn "ERROR: $@" if $@; |
warn "ERROR: $@" if $@; |
173 |
} |
} |
174 |
|
|
175 |
print $send "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"; |
my $refresh = $param->{refresh}; |
176 |
|
$refresh = 1 if keys %{ $info->{pending} }; |
177 |
|
|
178 |
|
print $send "HTTP/1.0 200 OK\r\nContent-Type: text/html" |
179 |
|
, ( $refresh ? "\r\nRefresh: $refresh" : '' ) |
180 |
|
, "\r\n\r\n" |
181 |
|
, ( $refresh ? qq|<span style="color: #888; float:right">$refresh</span>| : '' ) |
182 |
|
; |
183 |
|
|
184 |
print $send qq| |
print $send qq| |
185 |
|
|
191 |
|
|
192 |
|
|
193 |
.forked { |
.forked { |
194 |
color: #f00; |
// text-decoration: line-through; |
195 |
} |
} |
196 |
|
|
197 |
.ping { |
.ping { |
198 |
|
color: #ff0; |
199 |
|
} |
200 |
|
|
201 |
|
.load { |
202 |
|
color: #f00; |
203 |
|
} |
204 |
|
|
205 |
|
.view { |
206 |
|
color: #00f; |
207 |
|
} |
208 |
|
|
209 |
|
.ready { |
210 |
color: #0f0; |
color: #0f0; |
211 |
} |
} |
212 |
|
|
213 |
.shards { |
.shards { |
214 |
font-family: monospace; |
font-family: monospace; |
215 |
line-height: 0.8em; |
// line-height: 0.8em; |
216 |
color: #0f0; |
color: #0f0; |
217 |
} |
} |
218 |
|
|
229 |
|
|
230 |
|; |
|; |
231 |
|
|
232 |
|
my $out = Sack::Merge->out; |
233 |
|
if ( my $li = join("\n", map { qq|<li><input type=checkbox name=filter value="$_"><a href="/out/$_" target="$_">$_</a>| } keys %$out ) ) { |
234 |
|
print $send qq|<h1>Results</h1><form method="get" target="gnuplot" action="/gnuplot/"><ul>$li</ul><input type=submit value="Show checked"></form><img src="/gnuplot/">\n|; |
235 |
|
} |
236 |
|
|
237 |
print $send qq|<h1>Views</h1><ul>| |
print $send qq|<h1>Views</h1><ul>| |
238 |
, join("\n", map { |
, join("\n", map { |
239 |
my $view = $_; |
my $view = $_; |
254 |
$shard += $affected; |
$shard += $affected; |
255 |
$total += $affected; |
$total += $affected; |
256 |
} |
} |
257 |
my $merge = $info->{merge}->{$view}->{$node}; |
my $merge = $info->{merge}->{$view}->{$node} || '?'; |
258 |
$html .= qq|<tr><td><tt>$node</tt></td><td>$shard</td><td>$h</td><td>$total</td><td>$merge</td></tr>\n|; |
$html .= qq|<tr><td><tt>$node</tt></td><td>$shard</td><td>$h</td><td>$total</td><td>$merge</td></tr>\n|; |
259 |
} |
} |
260 |
|
|
265 |
, qq|</ul>| |
, qq|</ul>| |
266 |
; |
; |
267 |
|
|
268 |
my $out = Sack::Merge->out; |
print $send qq|<h1>Nodes</h1>|; |
269 |
if ( my $li = join("\n", map { qq|<li><a href="/out/$_" target="$_">$_</a>| } keys %$out ) ) { |
foreach my $node ( keys %{ $info->{node} } ) { |
270 |
print $send qq|<h1>Results</h1><ul>$li</ul><img src="/gnuplot/">\n|; |
my $class = join(' ' |
271 |
|
, map { $_->[0] } @{ $info->{node}->{$node} } |
272 |
|
); |
273 |
|
$class .= ' ' . ( $info->{pending}->{$node} || 'ready' ); |
274 |
|
print $send qq|<tt class="$class">$node</tt>\n|; |
275 |
} |
} |
276 |
|
|
277 |
print $send qq|<h1>Nodes</h1> |
print $send qq|<h1>Shards</h1><ul>|; |
|
|, join("\n", map { |
|
|
my $class = join(' ', map { $_->[0] } @{ $info->{node}->{$_} }); |
|
|
qq|<span class="$class">$_</span>|; |
|
|
} sort keys %{ $info->{node} } ); |
|
|
|
|
|
print $send qq|<h1>Data</h1><ul>|; |
|
278 |
foreach my $path ( glob '/tmp/sack/*' ) { |
foreach my $path ( glob '/tmp/sack/*' ) { |
279 |
print $send qq|<li><a href="$path">$path</a><div class="shards">|; |
print $send qq|<li><a href="$path">$path</a><div class="shards">|; |
280 |
foreach my $s ( sort grep { m/$path/ } keys %{ $info->{shard} } ) { |
foreach my $s ( sort grep { m/$path/ } keys %{ $info->{shard} } ) { |
281 |
my $i = $info->{shard}->{$s}; |
my $i = $info->{shard}->{$s}; |
282 |
print $send qq|<span class=$i>$i</span> |; |
print $send qq|<span class="$i" title="$s">$i</span> |; |
283 |
} |
} |
284 |
print $send qq|</div>|; |
print $send qq|</div>|; |
285 |
} |
} |
318 |
load_shard $1; |
load_shard $1; |
319 |
} elsif ( $repl =~ m{view\s*(\S+)?} ) { |
} elsif ( $repl =~ m{view\s*(\S+)?} ) { |
320 |
run_view $1; |
run_view $1; |
|
} elsif ( $repl =~ m{debug\s*(.+)?} ) { |
|
|
to_all { debug => $1 }; |
|
321 |
} elsif ( $repl =~ m{out} ) { |
} elsif ( $repl =~ m{out} ) { |
322 |
my $out = Sack::Merge->out; |
my $out = Sack::Merge->out; |
323 |
warn "out ",dump( $out ); |
warn "out ",dump( $out ); |
329 |
to_all { exit => 1 }; |
to_all { exit => 1 }; |
330 |
sleep 1; |
sleep 1; |
331 |
exit; |
exit; |
332 |
|
} elsif ( $repl eq '.' ) { |
333 |
|
$response->{'.'} = [ @responses ]; |
334 |
|
@responses = (); |
335 |
|
} elsif ( $repl =~ m{(\w+)\s*(.+)?} ) { |
336 |
|
to_all { $1 => $2 }; |
337 |
} else { |
} else { |
338 |
$response->{error}->{unknown} = $data; |
$response->{error}->{repl} = $repl; |
339 |
} |
} |
340 |
Storable::store_fd( $response, $sock ); |
Storable::store_fd( $response, $sock ); |
341 |
} elsif ( $data->{ping} ) { |
} elsif ( $data->{ping} ) { |
351 |
Storable::store_fd( { path => $path, shard => $shard }, $sock ); |
Storable::store_fd( { path => $path, shard => $shard }, $sock ); |
352 |
} else { |
} else { |
353 |
warn "no more shards for [", $data->{port}, "]\n"; |
warn "no more shards for [", $data->{port}, "]\n"; |
354 |
|
delete $info->{pending}->{ $data->{port} }; |
355 |
} |
} |
356 |
} elsif ( exists $data->{out} ) { |
} elsif ( exists $data->{out} ) { |
357 |
my $added = Sack::Merge->add( $data->{out} ) if defined $data->{out}; |
my $added = Sack::Merge->add( $data->{out} ) if defined $data->{out}; |
358 |
$info->{merge}->{ $data->{view} }->{ $data->{port} } = $added; |
$info->{merge}->{ $data->{view} }->{ $data->{port} } = $added; |
359 |
$info->{view }->{ $data->{view} }->{ $data->{port} } = $data->{on_shard}; |
$info->{view }->{ $data->{view} }->{ $data->{port} } = $data->{on_shard}; |
360 |
|
# refresh shard allocation |
361 |
|
$info->{shard}->{ $_ } = $data->{port} foreach keys %{ $data->{on_shard} }; |
362 |
|
delete $info->{pending}->{ $data->{port} }; |
363 |
|
} elsif ( exists $data->{port} ) { |
364 |
|
push @responses, $data; |
365 |
|
warn "# ",dump($data),$/; |
366 |
} else { |
} else { |
367 |
warn "UNKNOWN ",dump($data); |
warn "UNKNOWN ",dump($data); |
368 |
} |
} |