unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] index: update [extindex "all"] by default, support -E
@ 2020-12-23 23:02 Eric Wong
  2020-12-24  0:56 ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2020-12-23 23:02 UTC (permalink / raw)
  To: meta

In most cases, this ensures users will only have to opt-in to
using -extindex once and won't have to issue extra commands
to keep external indices up-to-date when using
public-inbox-index.

Since we support arbitrary numbers of external indices for
ease-of-development, we'll support repeating "-E"
("--update-extindex=") in case users want to test changes in
parallel.
---
 Documentation/public-inbox-index.pod | 19 ++++++++++-
 script/public-inbox-index            | 47 ++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/Documentation/public-inbox-index.pod b/Documentation/public-inbox-index.pod
index 0848e860..2c34aabc 100644
--- a/Documentation/public-inbox-index.pod
+++ b/Documentation/public-inbox-index.pod
@@ -162,6 +162,23 @@ See L<public-inbox-init(1)/--skip-docdata> for description and caveats.
 
 Available in public-inbox 1.6.0+.
 
+=item --update-extindex=EXTINDEX, -E
+
+Update the given external index (L<public-inbox-extindex-format(5)>.
+Either the configured section name (e.g. C<all>) or a directory name
+may be specified.
+
+Defaults to C<all> if C<[extindex "all"]> is configured,
+otherwise no external indices are updated.
+
+May be specified multiple times in rare cases multiple external
+indices are configured.
+
+=item --no-update-extindex
+
+Do not update the C<all> external index by default.  This negates
+all uses of C<-E> / C<--update-extindex=> on the command-line.
+
 =back
 
 =head1 FILES
@@ -297,4 +314,4 @@ License: AGPL-3.0+ L<https://www.gnu.org/licenses/agpl-3.0.txt>
 
 =head1 SEE ALSO
 
-L<Search::Xapian>, L<DBD::SQLite>
+L<Search::Xapian>, L<DBD::SQLite>, L<public-inbox-extindex-format(5)>
diff --git a/script/public-inbox-index b/script/public-inbox-index
index 8a61817c..f10bb5ad 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -17,7 +17,7 @@ options:
 
   --no-fsync          speed up indexing, risk corruption on power outage
   -L LEVEL            `basic', `medium', or `full' (default: full)
-  -E EIDX             update EIDX (e.g. `all')
+  -E EXTINDEX         update extindex (default: `all')
   --all               index all configured inboxes
   --compact | -c      run public-inbox-compact(1) after indexing
   --sequential-shard  index Xapian shards sequentially for slow storage
@@ -32,12 +32,16 @@ options:
 BYTES may use `k', `m', and `g' suffixes (e.g. `10m' for 10 megabytes)
 See public-inbox-index(1) man page for full documentation.
 EOF
-my $opt = { quiet => -1, compact => 0, max_size => undef, fsync => 1 };
+my $opt = {
+	quiet => -1, compact => 0, max_size => undef, fsync => 1,
+	'update-extindex' => [], # ":s@" optional arg sets '' if no arg given
+};
 GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i prune
 		fsync|sync! xapian_only|xapian-only
 		indexlevel|index-level|L=s max_size|max-size=s
 		batch_size|batch-size=s
 		sequential_shard|seq-shard|sequential-shard
+		no-update-extindex update-extindex|E=s@
 		skip-docdata all help|h))
 	or die $help;
 if ($opt->{help}) { print $help; exit 0 };
@@ -56,7 +60,31 @@ my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
 PublicInbox::Admin::require_or_die('-index');
 unless (@ibxs) { print STDERR $help; exit 1 }
 
+my (@eidx_dir, %eidx_seen);
+my $update_extindex = $opt->{'update-extindex'};
+if (!scalar(@$update_extindex) && (my $ALL = $cfg->ALL)) {
+	# extindex and normal inboxes may have different owners
+	push(@$update_extindex, 'all') if -w $ALL->{topdir};
+}
+@$update_extindex = () if $opt->{'no-update-extindex'};
+if (scalar @$update_extindex) {
+	PublicInbox::Admin::require_or_die('-search');
+	require PublicInbox::ExtSearchIdx;
+}
+for my $ei_name (@$update_extindex) {
+	my $es = $cfg->lookup_ei($ei_name);
+	my $topdir;
+	if (!$es && -d $ei_name) { # allow dirname or config section name
+		$topdir = $ei_name;
+	} elsif ($es) {
+		$topdir = $es->{topdir};
+	} else {
+		die "extindex `$ei_name' not configured or found\n";
+	}
+	$eidx_seen{$topdir} //= push(@eidx_dir, $topdir);
+}
 my $mods = {};
+my @eidx_unconfigured;
 foreach my $ibx (@ibxs) {
 	# detect_indexlevel may also set $ibx->{-skip_docdata}
 	my $detected = PublicInbox::Admin::detect_indexlevel($ibx);
@@ -64,7 +92,14 @@ foreach my $ibx (@ibxs) {
 	$ibx->{indexlevel} //= $opt->{indexlevel} // ($opt->{xapian_only} ?
 			'full' : $detected);
 	PublicInbox::Admin::scan_ibx_modules($mods, $ibx);
+	if (@eidx_dir && $ibx->{-unconfigured}) {
+		push @eidx_unconfigured, "  $ibx->{inboxdir}\n";
+	}
 }
+warn <<EOF if @eidx_unconfigured;
+The following inboxes are unconfigured and will not be updated in
+@$update_extindex:\n@eidx_unconfigured
+EOF
 
 # "Search::Xapian" includes SWIG "Xapian", too:
 $opt->{compact} = 0 if !$mods->{'Search::Xapian'};
@@ -96,4 +131,12 @@ EOL
 		local $copt->{jobs} = 0 if $ibx_opt->{sequential_shard};
 		PublicInbox::Xapcmd::run($ibx, 'compact', $copt);
 	}
+	next if $ibx->{-unconfigured};
+	last if $ibx_opt->{quit};
+	for my $dir (@eidx_dir) {
+		my $eidx = PublicInbox::ExtSearchIdx->new($dir);
+		$eidx->attach_inbox($ibx);
+		$eidx->eidx_sync($ibx_opt);
+		last if $ibx_opt->{quit};
+	}
 }

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] index: update [extindex "all"] by default, support -E
  2020-12-23 23:02 [PATCH] index: update [extindex "all"] by default, support -E Eric Wong
@ 2020-12-24  0:56 ` Kyle Meyer
  2020-12-24  3:28   ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2020-12-24  0:56 UTC (permalink / raw)
  To: Eric Wong; +Cc: meta

Eric Wong writes:

> +=item --update-extindex=EXTINDEX, -E
> +
> +Update the given external index (L<public-inbox-extindex-format(5)>.
> +Either the configured section name (e.g. C<all>) or a directory name
> +may be specified.
> +
> +Defaults to C<all> if C<[extindex "all"]> is configured,
> +otherwise no external indices are updated.
> +
> +May be specified multiple times in rare cases multiple external
> +indices are configured.

s/cases/& where/ ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] index: update [extindex "all"] by default, support -E
  2020-12-24  0:56 ` Kyle Meyer
@ 2020-12-24  3:28   ` Eric Wong
  2020-12-24  3:34     ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2020-12-24  3:28 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: meta

Kyle Meyer <kyle@kyleam.com> wrote:
> Eric Wong writes:
> 
> > +=item --update-extindex=EXTINDEX, -E
> > +
> > +Update the given external index (L<public-inbox-extindex-format(5)>.
> > +Either the configured section name (e.g. C<all>) or a directory name
> > +may be specified.
> > +
> > +Defaults to C<all> if C<[extindex "all"]> is configured,
> > +otherwise no external indices are updated.
> > +
> > +May be specified multiple times in rare cases multiple external
> > +indices are configured.
> 
> s/cases/& where/ ?

I guess, though I think "when" works, too, but maybe "where"
sounds better *shrug*

diff --git a/Documentation/public-inbox-index.pod b/Documentation/public-inbox-index.pod
index 2c34aabc..2d5df930 100644
--- a/Documentation/public-inbox-index.pod
+++ b/Documentation/public-inbox-index.pod
@@ -171,8 +171,8 @@ may be specified.
 Defaults to C<all> if C<[extindex "all"]> is configured,
 otherwise no external indices are updated.
 
-May be specified multiple times in rare cases multiple external
-indices are configured.
+May be specified multiple times in rare cases where multiple
+external indices are configured.
 
 =item --no-update-extindex
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] index: update [extindex "all"] by default, support -E
  2020-12-24  3:28   ` Eric Wong
@ 2020-12-24  3:34     ` Kyle Meyer
  0 siblings, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2020-12-24  3:34 UTC (permalink / raw)
  To: Eric Wong; +Cc: meta

Eric Wong writes:

> Kyle Meyer <kyle@kyleam.com> wrote:
>> Eric Wong writes:
>> > +May be specified multiple times in rare cases multiple external
>> > +indices are configured.
>> 
>> s/cases/& where/ ?
>
> I guess, though I think "when" works, too, but maybe "where"
> sounds better *shrug*

"when" sounds fine to me too.  I was in between and didn't choose
"where" for any principled reason :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-24  3:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 23:02 [PATCH] index: update [extindex "all"] by default, support -E Eric Wong
2020-12-24  0:56 ` Kyle Meyer
2020-12-24  3:28   ` Eric Wong
2020-12-24  3:34     ` Kyle Meyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).