/[BackupPC]/trunk/bin/BackupPC_updatedb
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_updatedb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 114 by dpavlin, Sun Sep 11 11:48:16 2005 UTC revision 116 by dpavlin, Sun Sep 11 12:39:24 2005 UTC
# Line 41  my $beenThere = {}; Line 41  my $beenThere = {};
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  if ($index_path) {  my $use_hest = $Conf{HyperEstraierIndex};
46          $index_path = $TopDir . '/' . $index_path;  my ($index_path, $index_node_url);
47          $index_path =~ s#//#/#g;  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 });
# Line 88  sub curr_time { Line 95  sub curr_time {
95  }  }
96    
97  my $hest_db;  my $hest_db;
98    my $hest_node;
99    
100  sub signal {  sub signal {
101          my($sig) = @_;          my($sig) = @_;
# Line 106  sub hest_update { Line 114  sub hest_update {
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();
# Line 113  sub hest_update { Line 126  sub hest_update {
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 " 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:";          print " increment is " . EST_CHUNK . " files:";
142    
143          my $results = 0;          my $results = 0;
# Line 179  sub hest_update { Line 200  sub hest_update {
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
# Line 203  sub hest_update { Line 224  sub hest_update {
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",

Legend:
Removed from v.114  
changed lines
  Added in v.116

  ViewVC Help
Powered by ViewVC 1.1.26