/[Search-Estraier]/trunk/scripts/estcp-mt.pl
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/scripts/estcp-mt.pl

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

trunk/scripts/estcp.pl revision 84 by dpavlin, Tue Jan 17 11:43:38 2006 UTC trunk/scripts/estcp-mt.pl revision 87 by dpavlin, Sat Jan 21 17:37:07 2006 UTC
# Line 5  use Search::Estraier; Line 5  use Search::Estraier;
5  use URI::Escape qw/uri_escape/;  use URI::Escape qw/uri_escape/;
6  use Time::HiRes;  use Time::HiRes;
7  use POSIX qw/strftime/;  use POSIX qw/strftime/;
8    use Config;
9    use threads;
10    use Thread::Queue;
11    
12  =head1 NAME  =head1 NAME
13    
# Line 12  estcp.pl - copy Hyper Estraier index fro Line 15  estcp.pl - copy Hyper Estraier index fro
15    
16  =cut  =cut
17    
18    die "Your perl isn't compiled with support for ithreads\n" unless ($Config{useithreads});
19    
20    
21  my ($from,$to) = @ARGV;  my ($from,$to) = @ARGV;
22    
23  die "usage: $0 http://localhost:1978/node/from http://remote.example.com:1978/node/to\n" unless ($from && $to);  die "usage: $0 http://localhost:1978/node/from http://remote.example.com:1978/node/to\n" unless ($from && $to);
# Line 31  my $to_n = new Search::Estraier::Node( Line 37  my $to_n = new Search::Estraier::Node(
37          debug => $debug,          debug => $debug,
38  );  );
39    
40  print "Copy from ",$from_n->name," (",$from_n->label,") to ",$to_n->name," (",$to_n->label,") - ",$from_n->doc_num," documents (",$from_n->word_num," words, ",$from_n->size," bytes)\n";  unless(eval{ $to_n->name }) {
41            if ($to =~ m#^(http://.+)/node/([^/]+)$#) {
42                    my ($url,$name) = ($1,$2);
43                    print "Creating '$name' on $url\n";
44                    $to_n->shuttle_url( $url . '/master?action=nodeadd',
45                            'application/x-www-form-urlencoded',
46                            'name=' . uri_escape($name) . '&label=' . uri_escape( $name ),
47                            undef,
48                    );
49            } else {
50                    die "can't extract node name from $to\n";
51            }
52    }
53    
54    # total processed elements
55    my $i : shared = 1;
56    
57    my $q_id = Thread::Queue->new;
58    my $q_drafts = Thread::Queue->new;
59    
60    my $get_thr = threads->new( sub {
61            while (my $id = $q_id->dequeue) {
62                    #warn "get ", $id || 'undef',"\n";
63                    if ($id < 0) {
64                            $q_drafts->enqueue( '' );       # abort put thread
65                            last;
66                    };
67                    print STDERR "get_thr, id: $id\n" if ($debug);
68                    my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );
69                    $q_drafts->enqueue( $doc_draft );
70            }
71    } );
72    
73    my $t = time();
74    my $t_refresh = time();
75  my $doc_num = $from_n->doc_num || 1;  my $doc_num = $from_n->doc_num || 1;
76    
77    my $put_thr = threads->new( sub {
78            while (my $doc_draft = $q_drafts->dequeue) {
79                    last unless ($doc_draft);
80                    print STDERR "put_thr, $doc_draft\n" if ($debug);
81                    $to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n";
82    
83                    $i++;
84                    if (time() - $t_refresh > 3) {
85                            my $rate = ( $i / ((time() - $t) || 1) );
86                            printf("%d records, %1.2f%% [%1.2f rec/s] estimated finish: %s\n",
87                                    $i,
88                                    ($i * 100 / $doc_num),
89                                    $rate,
90                                    strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))),
91                            );
92                            $t_refresh = time();
93                    }
94    
95            }
96    } );
97    
98    print "Copy from ",$from_n->name," (",$from_n->label,") to ",$to_n->name," (",$to_n->label,") - ",$from_n->doc_num," documents (",$from_n->word_num," words, ",$from_n->size," bytes)\n";
99    
100  my $prev;  my $prev;
 my $i = 0;  
101  my $more = 1;  my $more = 1;
102    
 my $t = time();  
   
103  while($more) {  while($more) {
104          my $res;          my $res;
105          $from_n->shuttle_url( $from_n->{url} . '/list',          $from_n->shuttle_url( $from_n->{url} . '/list',
# Line 57  while($more) { Line 116  while($more) {
116    
117                  #$to_n->put_doc( $from_n->get_doc( $id ));                  #$to_n->put_doc( $from_n->get_doc( $id ));
118    
119                  my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );                  #my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );
120                  $to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n";                  #$to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n";
121    
122                  $i++;                  $q_id->enqueue( $id );
123          }          }
124          warn "$prev\n";          warn "$prev\n" if ($debug);
   
         my $rate = ( $i / (time() - $t) );  
         printf("%d records, %1.2f%% [%1.2f rec/s] estimated finish: %s\n",  
                 $i,  
                 ($i * 100 / $doc_num),  
                 $rate,  
                 strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))),  
         );  
125    
126  }  }
127    $q_id->enqueue( -1 );   # last one
128    
129    $get_thr->join;
130    $put_thr->join;
131    
132  print "Copy completed.\n";  printf "Copy of %d records completed [%1.2f rec/s]\n", $i,
133            ( $i / ((time() - $t) || 1) );
134    

Legend:
Removed from v.84  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.26