user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 11/11] v2writable: reuse read-only shard counting code
Date: Wed,  2 Sep 2020 11:04:21 +0000
Message-ID: <20200902110421.30905-12-e@80x24.org> (raw)
In-Reply-To: <20200902110421.30905-1-e@80x24.org>

We'll also fix the read-only code to ensure we notice missing
Xapian shards, since gaps would throw off our expectation that
Xapian document IDs and NNTP article numbers are interchangeable.
---
 lib/PublicInbox/Search.pm     |  5 ++++-
 lib/PublicInbox/V2Writable.pm | 23 +++--------------------
 2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index b07f4ea6..fb35b747 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -7,6 +7,7 @@ package PublicInbox::Search;
 use strict;
 use parent qw(Exporter);
 our @EXPORT_OK = qw(mdocid);
+use List::Util qw(max);
 
 # values for searching, changing the numeric value breaks
 # compatibility with old indices (so don't change them it)
@@ -203,7 +204,9 @@ sub _xdb ($) {
 
 		# We need numeric sorting so shard[0] is first for reading
 		# Xapian metadata, if needed
-		for (sort { $a <=> $b } grep(/\A[0-9]+\z/, readdir($dh))) {
+		my $last = max(grep(/\A[0-9]+\z/, readdir($dh)));
+		return if !defined($last);
+		for (0..$last) {
 			my $shard_dir = "$dir/$_";
 			if (-d $shard_dir && -r _) {
 				push @xdb, $X{Database}->new($shard_dir);
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index c8334645..a1f6048f 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -65,28 +65,11 @@ sub nproc_shards ($) {
 
 sub count_shards ($) {
 	my ($self) = @_;
-	my $n = 0;
-	my $xpfx = $self->{xpfx};
-
 	# always load existing shards in case core count changes:
 	# Also, shard count may change while -watch is running
-	# due to "xcpdb --reshard"
-	if (-d $xpfx) {
-		my $XapianDatabase;
-		foreach my $shard (<$xpfx/*>) {
-			-d $shard && $shard =~ m!/[0-9]+\z! or next;
-			$XapianDatabase //= do {
-				require PublicInbox::Search;
-				PublicInbox::Search::load_xapian();
-				$PublicInbox::Search::X{Database};
-			};
-			eval {
-				$XapianDatabase->new($shard)->close;
-				$n++;
-			};
-		}
-	}
-	$n;
+	my $srch = $self->{ibx}->search or return 0;
+	delete $self->{ibx}->{search};
+	$srch->{nshard} // 0
 }
 
 sub new {

      parent reply	other threads:[~2020-09-02 11:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 11:04 [PATCH 00/11] cleanups, mostly indexing related Eric Wong
2020-09-02 11:04 ` [PATCH 01/11] msgmap: note how we use ->created_at Eric Wong
2020-09-02 11:04 ` [PATCH 02/11] disambiguate OverIdx and Over by field name Eric Wong
2020-09-02 11:04 ` [PATCH 03/11] use more idiomatic internal API for ->over access Eric Wong
2020-09-02 11:04 ` [PATCH 04/11] search: remove special case for blank query Eric Wong
2020-09-02 11:04 ` [PATCH 05/11] tests: add "use strict" and declare v5.10.1 compatibility Eric Wong
2020-09-02 11:04 ` [PATCH 06/11] search: replace ->query with ->mset Eric Wong
2020-09-02 11:04 ` [PATCH 07/11] search: remove {over_ro} field Eric Wong
2020-09-02 11:04 ` [PATCH 08/11] imap: drop old, pre-Parse::RecDescent search parser Eric Wong
2020-09-02 11:04 ` [PATCH 09/11] wwwaltid: drop unused sqlite3_missing function Eric Wong
2020-09-02 11:04 ` [PATCH 10/11] overidx: document column uses Eric Wong
2020-09-02 11:04 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200902110421.30905-12-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git