41 |
|
|
42 |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
43 |
my $user = $Conf{SearchUser} || ''; |
my $user = $Conf{SearchUser} || ''; |
44 |
my $index_path = $Conf{HyperEstraierIndex}; |
|
45 |
$index_path = $TopDir . '/' . $index_path; |
my $use_hest = $Conf{HyperEstraierIndex}; |
46 |
$index_path =~ s#//#/#g; |
my ($index_path, $index_node_url); |
47 |
if ($index_path) { |
if ($use_hest) { |
48 |
use HyperEstraier; |
use HyperEstraier; |
49 |
|
if ($use_hest =~ m#^http://#) { |
50 |
|
$index_node_url = $use_hest; |
51 |
|
} else { |
52 |
|
$index_path = $TopDir . '/' . $index_path; |
53 |
|
$index_path =~ s#//#/#g; |
54 |
|
} |
55 |
} |
} |
56 |
|
print "-- $use_hest : $index_path OR $index_node_url --\n"; |
57 |
|
|
58 |
|
|
59 |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
95 |
} |
} |
96 |
|
|
97 |
my $hest_db; |
my $hest_db; |
98 |
|
my $hest_node; |
99 |
|
|
100 |
sub signal { |
sub signal { |
101 |
my($sig) = @_; |
my($sig) = @_; |
114 |
|
|
115 |
my ($host_id, $share_id, $num) = @_; |
my ($host_id, $share_id, $num) = @_; |
116 |
|
|
117 |
|
unless ($use_hest) { |
118 |
|
print STDERR "HyperEstraier support not enabled in configuration\n"; |
119 |
|
return; |
120 |
|
} |
121 |
|
|
122 |
print curr_time," updating HyperEstraier:"; |
print curr_time," updating HyperEstraier:"; |
123 |
|
|
124 |
my $t = time(); |
my $t = time(); |
126 |
my $offset = 0; |
my $offset = 0; |
127 |
my $added = 0; |
my $added = 0; |
128 |
|
|
129 |
print " opening index $index_path"; |
print " opening index $use_hest"; |
130 |
$hest_db = HyperEstraier::Database->new(); |
if ($index_path) { |
131 |
$hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); |
$hest_db = HyperEstraier::Database->new(); |
132 |
|
$hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); |
133 |
print " increment is " . EST_CHUNK . " files"; |
print " directly"; |
134 |
|
} elsif ($index_node_url) { |
135 |
|
$hest_node ||= HyperEstraier::Node->new($index_node_url); |
136 |
|
$hest_node->set_auth('admin', 'admin'); |
137 |
|
print " via node URL"; |
138 |
|
} else { |
139 |
|
die "don't know how to use HyperEstraier Index $use_hest"; |
140 |
|
} |
141 |
|
print " increment is " . EST_CHUNK . " files:"; |
142 |
|
|
143 |
my $results = 0; |
my $results = 0; |
144 |
|
|
145 |
do { |
do { |
146 |
|
|
147 |
my $where = ''; |
my $where = ''; |
148 |
|
my @data; |
149 |
if ($host_id && $share_id && $num) { |
if ($host_id && $share_id && $num) { |
150 |
$where = qq{ |
$where = qq{ |
151 |
WHERE |
WHERE |
153 |
shares.id = ? AND |
shares.id = ? AND |
154 |
files.backupnum = ? |
files.backupnum = ? |
155 |
}; |
}; |
156 |
|
@data = ( $host_id, $share_id, $num ); |
157 |
} |
} |
158 |
|
|
159 |
my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset); |
my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset); |
180 |
$limit |
$limit |
181 |
}); |
}); |
182 |
|
|
183 |
$sth->execute(@_); |
$sth->execute(@data); |
184 |
$results = $sth->rows; |
$results = $sth->rows; |
185 |
|
|
186 |
if ($results == 0) { |
if ($results == 0) { |
187 |
print " - no more files\n"; |
print " - no new files\n"; |
188 |
last; |
last; |
189 |
} |
} |
190 |
|
|
200 |
my $fid = $row->{'fid'} || die "no fid?"; |
my $fid = $row->{'fid'} || die "no fid?"; |
201 |
my $uri = 'file:///' . $fid; |
my $uri = 'file:///' . $fid; |
202 |
|
|
203 |
my $id = $hest_db->uri_to_id($uri); |
my $id = ($hest_db || $hest_node)->uri_to_id($uri); |
204 |
next unless ($id == -1); |
next unless ($id == -1); |
205 |
|
|
206 |
# create a document object |
# create a document object |
224 |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
225 |
|
|
226 |
# register the document object to the database |
# register the document object to the database |
227 |
$hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); |
if ($hest_db) { |
228 |
|
$hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); |
229 |
|
} elsif ($hest_node) { |
230 |
|
$hest_node->put_doc($doc); |
231 |
|
} else { |
232 |
|
die "not supported"; |
233 |
|
} |
234 |
$added++; |
$added++; |
235 |
} |
} |
236 |
|
|
237 |
print " $added"; |
print " $added"; |
238 |
$hest_db->sync(); |
$hest_db->sync() if ($index_path); |
239 |
|
|
240 |
$offset += EST_CHUNK; |
$offset += EST_CHUNK; |
241 |
|
|
242 |
} while ($results == EST_CHUNK); |
} while ($results == EST_CHUNK); |
243 |
|
|
244 |
print ", close"; |
if ($index_path) { |
245 |
$hest_db->close(); |
print ", close"; |
246 |
|
$hest_db->close(); |
247 |
|
} |
248 |
|
|
249 |
my $dur = (time() - $t) || 1; |
my $dur = (time() - $t) || 1; |
250 |
printf(" [%.2f/s dur: %s]\n", |
printf(" [%.2f/s dur: %s]\n", |
481 |
fmt_time($dur) |
fmt_time($dur) |
482 |
); |
); |
483 |
|
|
484 |
hest_update($hostID, $shareID, $backupNum); |
hest_update($hostID, $shareID, $backupNum) if ($nf + $nd > 0); |
485 |
} |
} |
486 |
|
|
487 |
} |
} |