user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] search: avoid setting undef hashtable entries
Date: Sat, 25 Sep 2021 22:16:45 +0000	[thread overview]
Message-ID: <20210925221645.13443-3-e@80x24.org> (raw)
In-Reply-To: <20210925221645.13443-1-e@80x24.org>

`undef' entries still take up a slot in the hash table, and
cause the `exists' check to false-positive in ->cleanup_shards.
This should fully fix the (innocuous) messages introduced in
commit 63d7b8ce (daemons: revamp periodic cleanup task, 2021-09-23)
---
 lib/PublicInbox/AdminEdit.pm |  5 +++--
 lib/PublicInbox/Inbox.pm     | 15 +++++++--------
 lib/PublicInbox/Search.pm    | 12 ++++++------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/lib/PublicInbox/AdminEdit.pm b/lib/PublicInbox/AdminEdit.pm
index 2f6707d8..c8c3d3e8 100644
--- a/lib/PublicInbox/AdminEdit.pm
+++ b/lib/PublicInbox/AdminEdit.pm
@@ -27,8 +27,9 @@ sub check_editable ($) {
 		# Make sure it's purged in that case:
 		$ibx->over or die "no over.sqlite3 in $ibx->{inboxdir}\n";
 
-		# $ibx->{search} is populated by $ibx->over call
-		my $xdir_ro = $ibx->{search}->xdir(1);
+		require PublicInbox::Search;
+		my $xdir_ro = PublicInbox::Search->new($ibx)->xdir(1);
+
 		my $nshard = 0;
 		foreach my $shard (<$xdir_ro/*>) {
 			if (-d $shard && $shard =~ m!/[0-9]+\z!) {
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index c0962af9..3ba92c99 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -167,12 +167,12 @@ sub mm {
 
 sub search {
 	my ($self) = @_;
-	my $srch = $self->{search} //= eval {
+	$self->{search} // eval {
 		_cleanup_later($self);
 		require PublicInbox::Search;
-		PublicInbox::Search->new($self);
+		my $srch = PublicInbox::Search->new($self);
+		(eval { $srch->xdb }) ? ($self->{search} = $srch) : undef;
 	};
-	(eval { $srch->xdb }) ? $srch : undef;
 }
 
 # isrch is preferred for read-only interfaces if available since it
@@ -181,15 +181,14 @@ sub isrch { $_[0]->{isrch} // search($_[0]) }
 
 sub over {
 	my ($self, $req) = @_;
-	$self->{over} //= eval {
-		my $srch = $self->{search} //= do {
-			_cleanup_later($self);
+	$self->{over} // eval {
+		my $srch = $self->{search} // do {
 			require PublicInbox::Search;
 			PublicInbox::Search->new($self);
 		};
 		my $over = PublicInbox::Over->new("$srch->{xpfx}/over.sqlite3");
 		$over->dbh; # may fail
-		$over;
+		$self->{over} = $over;
 	} // ($req ? croak("E: $@") : undef);
 }
 
@@ -293,7 +292,7 @@ sub imap_url { $_[0]->{-imap_url} //= _x_url($_[0], 'imap', $_[1]) }
 sub nntp_usable {
 	my ($self) = @_;
 	my $ret = mm($self) && over($self);
-	$self->{mm} = $self->{over} = $self->{search} = undef;
+	delete @$self{qw(mm over search)};
 	$ret;
 }
 
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index d285c11c..17e202e1 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -234,12 +234,12 @@ sub mset_to_artnums {
 
 sub xdb ($) {
 	my ($self) = @_;
-	$self->{xdb} //= do {
+	$self->{xdb} // do {
 		my @xdb = $self->xdb_shards_flat or return;
 		$self->{nshard} = scalar(@xdb);
 		my $xdb = shift @xdb;
 		$xdb->add_database($_) for @xdb;
-		$xdb;
+		$self->{xdb} = $xdb;
 	};
 }
 
@@ -261,10 +261,10 @@ sub new {
 	my ($class, $ibx) = @_;
 	ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
 	my $xap = $ibx->version > 1 ? 'xap' : 'public-inbox/xapian';
-	bless {
-		xpfx => "$ibx->{inboxdir}/$xap" . SCHEMA_VERSION,
-		altid => $ibx->{altid},
-	}, $class;
+	my $xpfx = "$ibx->{inboxdir}/$xap".SCHEMA_VERSION;
+	my $self = bless { xpfx => $xpfx }, $class;
+	$self->{altid} = $ibx->{altid} if defined($ibx->{altid});
+	$self;
 }
 
 sub reopen {

      parent reply	other threads:[~2021-09-25 22:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-25 22:16 [PATCH 0/2] www: shrink per-inbox hashtable slots Eric Wong
2021-09-25 22:16 ` [PATCH 1/2] extmsg: search_partial: use ->isrch if available Eric Wong
2021-09-25 22:16 ` 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=20210925221645.13443-3-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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

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).