70 |
} |
} |
71 |
} |
} |
72 |
|
|
73 |
|
my @shard_paths; |
74 |
|
|
75 |
while (1) { |
while (1) { |
76 |
for my $sock ($sel->can_read(1)) { |
for my $sock ($sel->can_read(1)) { |
77 |
if ($sock == $lsn) { |
if ($sock == $lsn) { |
90 |
$sock->close; |
$sock->close; |
91 |
} else { |
} else { |
92 |
warn "<<<< ", dump($data), $/; |
warn "<<<< ", dump($data), $/; |
93 |
if ( $data->{repl} ) { |
|
94 |
my $response = { repl => $$ }; |
if ( my $path = $data->{shard} ) { |
95 |
if ( $data->{repl} =~ m/ping/ ) { |
push @{ $info->{shard}->{ $data->{port} } }, $path; |
96 |
|
} |
97 |
|
|
98 |
|
if ( my $repl = $data->{repl} ) { |
99 |
|
my $response = { repl_pid => $$ }; |
100 |
|
if ( $repl =~ m/ping/ ) { |
101 |
to_all { ping => 1 }; |
to_all { ping => 1 }; |
102 |
} elsif ( $data->{repl} =~ m/info/ ) { |
} elsif ( $repl =~ m/info/ ) { |
103 |
$response->{info} = $info; |
$response->{info} = $info; |
104 |
|
} elsif ( $repl =~ m{load\s*(\S+)?} ) { |
105 |
|
my $name = $1 || 'shard'; |
106 |
|
@shard_paths = glob "/tmp/sack/$name/*"; |
107 |
|
warn "loading shards ", dump( @shard_paths ); |
108 |
|
to_all { load => $name }; |
109 |
|
} elsif ( $repl =~ m{view\s*(\S+)?} ) { |
110 |
|
my $path = $1 || '/srv/Sack/views/00.demo.pl'; |
111 |
|
my $code = read_file $path; |
112 |
|
to_all { view => $code, path => $path }; |
113 |
|
$response->{view}->{$path}->{running}; |
114 |
|
} elsif ( $repl =~ m{debug\s*(.+)?} ) { |
115 |
|
to_all { debug => $1 }; |
116 |
} else { |
} else { |
117 |
$response->{error}->{unknown} = $data; |
$response->{error}->{unknown} = $data; |
118 |
} |
} |
121 |
my $port = $data->{port}; |
my $port = $data->{port}; |
122 |
info $port => 'ping', $port; |
info $port => 'ping', $port; |
123 |
$session->{port}->{ $data->{port} } = $sock; |
$session->{port}->{ $data->{port} } = $sock; |
124 |
|
} elsif ( $data->{load} eq 'shard' ) { |
125 |
|
if ( my $path = shift @shard_paths ) { |
126 |
|
warn "retrieve $path ", -s $path; |
127 |
|
my $shard = Storable::retrieve $path; |
128 |
|
warn ">>>> [", $data->{port}, "] sending shard $path\n"; |
129 |
|
Storable::store_fd( { path => $path, shard => $shard }, $sock ); |
130 |
|
} else { |
131 |
|
warn "no more shards for [", $data->{port}, "]\n"; |
132 |
|
} |
133 |
|
} else { |
134 |
|
warn "UNKNOWN ",dump($data); |
135 |
} |
} |
136 |
} |
} |
137 |
} |
} |