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] extindex: dedupe: reduce SQLite contention and dirty data
Date: Thu,  8 Jul 2021 08:25:19 +0000	[thread overview]
Message-ID: <20210708082519.7987-1-e@80x24.org> (raw)

Complex queries causes SQLite to block readers for longer than
their retry period.  For dedupe, it was also preventing us from
making good use of checkpoints due to the query time.

With many deduplications, checkpoints are necessary to maintain
system health due to having too much data piled up.
---
 lib/PublicInbox/ExtSearchIdx.pm | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index a421e16b..0e27bba6 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -884,19 +884,20 @@ sub eidx_dedupe ($$) {
 	my $iter;
 	my $min_id = 0;
 	local $sync->{-regen_fmt} = "dedupe %u/".$self->{oidx}->max."\n";
+
+	# note: we could write this query more intelligently,
+	# but that causes lock contention with read-only processes
 dedupe_restart:
 	$iter = $self->{oidx}->dbh->prepare(<<EOS);
-SELECT DISTINCT(mid),id FROM msgid WHERE id IN
-(SELECT id FROM id2num WHERE id > ? GROUP BY num HAVING COUNT(num) > 1)
-ORDER BY id
+SELECT mid,id FROM msgid WHERE id > ? ORDER BY id ASC
 EOS
 	$iter->execute($min_id);
 	while (my ($mid, $id) = $iter->fetchrow_array) {
 		last if $sync->{quit};
 		$self->{current_info} = "dedupe $mid";
 		${$sync->{nr}} = $min_id = $id;
-		my ($n, $prv, @smsg);
-		while (my $x = $self->{oidx}->next_by_mid($mid, \$n, \$prv)) {
+		my ($prv, @smsg);
+		while (my $x = $self->{oidx}->next_by_mid($mid, \$id, \$prv)) {
 			push @smsg, $x;
 		}
 		next if scalar(@smsg) < 2;
@@ -918,8 +919,7 @@ EOS
 		# need to wait on every single one
 		$self->git->async_wait_all;
 
-		# is checkpoint needed? $iter is a very expensive query to restart
-		if (0 && checkpoint_due($sync)) {
+		if (checkpoint_due($sync)) {
 			undef $iter;
 			reindex_checkpoint($self, $sync);
 			goto dedupe_restart;

                 reply	other threads:[~2021-07-08  8:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210708082519.7987-1-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).