79 |
} |
} |
80 |
} |
} |
81 |
|
|
82 |
my @shard_paths; |
our @shard_load_queue; |
83 |
|
sub load_shard { |
84 |
|
my $shard = shift @_ || return; |
85 |
|
|
86 |
|
warn "# load_shard $shard\n"; |
87 |
|
|
88 |
|
my @shards = glob "$shard/*"; |
89 |
|
|
90 |
|
if ( ! @shards ) { |
91 |
|
warn "no shards for $shard\n"; |
92 |
|
return; |
93 |
|
} |
94 |
|
|
95 |
|
$info->{shard}->{$_} = 'wait' foreach @shards; |
96 |
|
warn "loading shard $shard from ", dump( @shards ); |
97 |
|
|
98 |
|
push @shard_load_queue, @shards; |
99 |
|
to_all { load => $shard }; |
100 |
|
} |
101 |
|
|
102 |
while (1) { |
while (1) { |
103 |
for my $sock ($sel->can_read(1)) { |
for my $sock ($sel->can_read(1)) { |
120 |
print $send "HTTP/1.0 302 $method\r\nLocation: /\r\n\r\n"; |
print $send "HTTP/1.0 302 $method\r\nLocation: /\r\n\r\n"; |
121 |
return 1; |
return 1; |
122 |
} elsif ( $method =~ m{^/tmp/sack} ) { |
} elsif ( $method =~ m{^/tmp/sack} ) { |
123 |
@shard_paths = glob "$method/*"; |
load_shard $method; |
|
warn "loading shard $method from ", dump( @shard_paths ); |
|
|
to_all { load => $method }; |
|
124 |
print $send "HTTP/1.0 302 $method\r\nLocation: /\r\n\r\n"; |
print $send "HTTP/1.0 302 $method\r\nLocation: /\r\n\r\n"; |
125 |
return 1; |
return 1; |
126 |
} elsif ( $method =~ m{^/out/(.+)} ) { |
} elsif ( $method =~ m{^/out/(.+)} ) { |
157 |
qq|<span class="$class">$_</span>|; |
qq|<span class="$class">$_</span>|; |
158 |
} sort keys %{ $info->{node} } ); |
} sort keys %{ $info->{node} } ); |
159 |
|
|
160 |
print $send qq|<h1>Data</h1><ul>| |
print $send qq|<h1>Data</h1><ul>|; |
161 |
, join("\n", map { qq|<li><a href="$_">$_</a>| } glob '/tmp/sack/*' ) |
foreach my $path ( glob '/tmp/sack/*' ) { |
162 |
, qq|</ul>| |
print $send qq|<li><a href="$path">$path</a><br><tt>|; |
163 |
; |
foreach my $s ( sort grep { m/$path/ } keys %{ $info->{shard} } ) { |
164 |
|
print $send $info->{shard}->{$s}, ' '; |
165 |
|
} |
166 |
|
print $send qq|</tt>|; |
167 |
|
} |
168 |
|
print $send qq|</ul>|; |
169 |
|
|
170 |
print $send '<pre>', dump($info), '</pre>'; |
print $send '<pre>', dump($info), '</pre>'; |
171 |
|
|
192 |
} elsif ( $repl =~ m/info/ ) { |
} elsif ( $repl =~ m/info/ ) { |
193 |
$response->{info} = $info; |
$response->{info} = $info; |
194 |
} elsif ( $repl =~ m{load\s*(\S+)?} ) { |
} elsif ( $repl =~ m{load\s*(\S+)?} ) { |
195 |
my $name = $1 || 'shard'; |
load_shard $1; |
|
@shard_paths = glob "/tmp/sack/$name/*"; |
|
|
warn "loading shard $name from ", dump( @shard_paths ); |
|
|
to_all { load => $name }; |
|
196 |
} elsif ( $repl =~ m{view\s*(\S+)?} ) { |
} elsif ( $repl =~ m{view\s*(\S+)?} ) { |
197 |
my $path = $1 || '/srv/Sack/views/00.demo.pl'; |
my $path = $1 || '/srv/Sack/views/00.demo.pl'; |
198 |
my $code = read_file $path; |
my $code = read_file $path; |
217 |
info $port => 'ping', $port; |
info $port => 'ping', $port; |
218 |
$session->{port}->{ $data->{port} } = $sock; |
$session->{port}->{ $data->{port} } = $sock; |
219 |
} elsif ( $data->{load} eq 'shard' ) { |
} elsif ( $data->{load} eq 'shard' ) { |
220 |
if ( my $path = shift @shard_paths ) { |
if ( my $path = shift @shard_load_queue ) { |
221 |
warn "retrieve $path ", -s $path; |
$info->{shard}->{$path} = 'read'; |
222 |
my $shard = Storable::retrieve $path; |
my $shard = Storable::retrieve $path; |
223 |
|
$info->{shard}->{$path} = 'send'; |
224 |
warn ">>>> [", $data->{port}, "] sending shard $path\n"; |
warn ">>>> [", $data->{port}, "] sending shard $path\n"; |
225 |
Storable::store_fd( { path => $path, shard => $shard }, $sock ); |
Storable::store_fd( { path => $path, shard => $shard }, $sock ); |
226 |
} else { |
} else { |