|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
parallel_rebuild_bibios.pl - inserts biblios records from a Koha database into Elasticsearch in parallel. |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
B<parallel_rebuild_biblios.pl> |
| 10 |
[B<-h|--help>] |
| 11 |
[B<-v|--verbose>] |
| 12 |
[B<-j|--jobs>=C<jobs>] |
| 13 |
[B<-b|--batchsize>=C<size>] |
| 14 |
[B<-c|--commit>=C<size>] |
| 15 |
[B<--startbiblionumber>=C<biblionumber>] |
| 16 |
[B<-d|--delete>] |
| 17 |
|
| 18 |
=head1 OPTIONS |
| 19 |
|
| 20 |
=over |
| 21 |
|
| 22 |
=item B<-h|--help> |
| 23 |
|
| 24 |
Print a brief help message. |
| 25 |
|
| 26 |
=item B<-v|--verbose> |
| 27 |
|
| 28 |
Passed to rebuild_elastic_search.pl. Increase verbosity. |
| 29 |
|
| 30 |
=item B<-j|--jobs>=C<N> |
| 31 |
|
| 32 |
Run up to N jobs in parallel. 0 means as many as possible. Default is to run |
| 33 |
one job per CPU core. This is passed directly to parrallel as B<-j>C<N>. Se C<man parrallel> |
| 34 |
for more information about variants of C<N>. |
| 35 |
|
| 36 |
=item B<-b|--batchsize>=C<size> |
| 37 |
|
| 38 |
Specify batch size for batches of biblios passed to rebuild_elastic_search.pl. |
| 39 |
|
| 40 |
=item B<-c|--commit>=C<size> |
| 41 |
|
| 42 |
Passed to rebuild_elastic_search.pl. Specify how many records will be batched up before batch committed to Elasticsearch. |
| 43 |
|
| 44 |
=item B<--startbiblionumber>=C<biblionumber> |
| 45 |
|
| 46 |
Specify starting biblionumber, only biblios with equal or higher biblionumber will be indexed. |
| 47 |
|
| 48 |
=item B<-d|--delete> |
| 49 |
|
| 50 |
Delete the index and recreate it before indexing. |
| 51 |
|
| 52 |
=back |
| 53 |
|
| 54 |
=cut |
| 55 |
|
| 56 |
use Modern::Perl; |
| 57 |
use Getopt::Long; |
| 58 |
use Pod::Usage; |
| 59 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
| 60 |
use C4::Context; |
| 61 |
|
| 62 |
|
| 63 |
#TODO: Is the the correct way of getting koha root? |
| 64 |
my $koha_root = C4::Context->config('intranetdir'); |
| 65 |
|
| 66 |
my ( |
| 67 |
$help, |
| 68 |
$man, |
| 69 |
$verbose, |
| 70 |
$jobs, |
| 71 |
$batch_size, |
| 72 |
$commit_size, |
| 73 |
$start_biblionumber, |
| 74 |
$delete |
| 75 |
); |
| 76 |
|
| 77 |
# Default option values |
| 78 |
$batch_size = 30000; |
| 79 |
GetOptions( |
| 80 |
'h|help' => \$help, |
| 81 |
'man' => \$man, |
| 82 |
'v|verbose' => \$verbose, |
| 83 |
'j|jobs=i' => \$jobs, |
| 84 |
'b|batchsize=i' => \$batch_size, |
| 85 |
'c|commit=i' => \$commit_size, |
| 86 |
'startbiblionumber=i' => \$start_biblionumber, |
| 87 |
'd|delete' => \$delete |
| 88 |
); |
| 89 |
|
| 90 |
pod2usage(1) if $help; |
| 91 |
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; |
| 92 |
|
| 93 |
if ($delete) { |
| 94 |
my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ |
| 95 |
index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX |
| 96 |
}); |
| 97 |
$indexer->drop_index(); |
| 98 |
$indexer->create_index(); |
| 99 |
} |
| 100 |
|
| 101 |
# record_batches.pl options |
| 102 |
my @record_batches_opts; |
| 103 |
if ($start_biblionumber) { |
| 104 |
push @record_batches_opts, "--startbiblionumber=$start_biblionumber"; |
| 105 |
} |
| 106 |
push @record_batches_opts, "--batchsize=$batch_size"; |
| 107 |
my $record_batches_opts = join(' ', @record_batches_opts); |
| 108 |
|
| 109 |
# rebuild_elastic_search.pl options |
| 110 |
my @rebuild_elastic_opts = ('-b'); |
| 111 |
if ($verbose) { |
| 112 |
push @rebuild_elastic_opts, "-v"; |
| 113 |
} |
| 114 |
if ($commit_size) { |
| 115 |
push @rebuild_elastic_opts, "--commit=$commit_size"; |
| 116 |
} |
| 117 |
my $rebuild_elastic_opts = join(' ', @rebuild_elastic_opts); |
| 118 |
|
| 119 |
# parallel options |
| 120 |
my @parallel_opts; |
| 121 |
if ($jobs) { |
| 122 |
push @parallel_opts, "-j$jobs"; |
| 123 |
} |
| 124 |
my $parallel_opts = join(' ', @parallel_opts); |
| 125 |
|
| 126 |
my $command = join('', ( |
| 127 |
"$koha_root/misc/record_batches.pl $record_batches_opts | ", |
| 128 |
"parallel $parallel_opts --colsep ' ' ", |
| 129 |
"$koha_root/misc/search_tools/rebuild_elastic_search.pl $rebuild_elastic_opts --startbiblionumber={1} --endbiblionumber={2}" |
| 130 |
)); |
| 131 |
|
| 132 |
exec $command; |