user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: [PATCH] msgmap: mid_insert: use plain "INSERT" to detect duplicates
  2019-06-24 23:38  6% ` [PATCH] msgmap: mid_insert: use plain "INSERT" to detect duplicates Eric Wong
@ 2019-06-25  3:48  7%   ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-06-25  3:48 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

Pushed to `master' with this warning fix squashed in since I
used `$max' elsewhere:

diff --git a/t/msgmap.t b/t/msgmap.t
index 2d018219..20985ce8 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -30,8 +30,8 @@ $@ = undef;
 my $ret = $d->mid_insert('a@b');
 is($ret, undef, 'duplicate mid_insert in undef result');
 is($d->num_for('a@b'), $mid2num{'a@b'}, 'existing number not clobbered');
-my $max = (sort(keys %num2mid))[-1];
-is($d->mid_insert('ok@unique'), $max + 1,
+my $next = (sort(keys %num2mid))[-1];
+is($d->mid_insert('ok@unique'), $next + 1,
 	'got expected num after failing mid_insert');
 

^ permalink raw reply related	[relevance 7%]

* [PATCH] msgmap: mid_insert: use plain "INSERT" to detect duplicates
  @ 2019-06-24 23:38  6% ` Eric Wong
  2019-06-25  3:48  7%   ` Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-06-24 23:38 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

"INSERT OR IGNORE" still bumps the auto-increment counter in
SQLite, which causes gaps to appear in NNTP article numbering.

This bug appeared in v2 repos where V2Writable may call ->add
repeatedly on the same message.  This bug is apparent with
public-inbox-watch and work-in-progress IMAP watchers which may
rescan and (attempt to) reinsert the same message on mailbox
changes.

Most uses of public-inbox-mda were not affected, unless the
same message is actually delivered multiple times to the mda.
v1 is not affected, either, since deduplication is only based
on Message-ID and msgmap never sees the duplicate.

Reported-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 lib/PublicInbox/Msgmap.pm | 4 ++--
 t/msgmap.t                | 3 +++
 t/v2writable.t            | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 0035c9e3..5a89b85a 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -126,9 +126,9 @@ sub mid_insert {
 	my ($self, $mid) = @_;
 	my $dbh = $self->{dbh};
 	my $sth = $dbh->prepare_cached(<<'');
-INSERT OR IGNORE INTO msgmap (mid) VALUES (?)
+INSERT INTO msgmap (mid) VALUES (?)
 
-	return if $sth->execute($mid) == 0;
+	return unless eval { $sth->execute($mid) };
 	my $num = $dbh->last_insert_id(undef, undef, 'msgmap', 'num');
 	$self->num_highwater($num) if defined($num);
 	$num;
diff --git a/t/msgmap.t b/t/msgmap.t
index 4dddd0a8..2d018219 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -30,6 +30,9 @@ $@ = undef;
 my $ret = $d->mid_insert('a@b');
 is($ret, undef, 'duplicate mid_insert in undef result');
 is($d->num_for('a@b'), $mid2num{'a@b'}, 'existing number not clobbered');
+my $max = (sort(keys %num2mid))[-1];
+is($d->mid_insert('ok@unique'), $max + 1,
+	'got expected num after failing mid_insert');
 
 foreach my $n (keys %num2mid) {
 	is($d->mid_for($n), $num2mid{$n}, "num:$n maps correctly");
diff --git a/t/v2writable.t b/t/v2writable.t
index 88df2d64..8f32fbe5 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -118,6 +118,8 @@ if ('ensure git configs are correct') {
 	$mime->header_set('References', '<zz-mid@b>');
 	ok($im->add($mime), 'message with multiple Message-ID');
 	$im->done;
+	my ($total, undef) = $ibx->over->recent;
+	is($ibx->mm->num_highwater, $total, 'got expected highwater value');
 	my $srch = $ibx->search;
 	my $mset1 = $srch->reopen->query('m:abcde@1', { mset => 1 });
 	is($mset1->size, 1, 'message found by first MID');
-- 
EW


^ permalink raw reply related	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-06-24 15:59     Q: Did you do something to message number recently? Eric W. Biederman
2019-06-24 23:38  6% ` [PATCH] msgmap: mid_insert: use plain "INSERT" to detect duplicates Eric Wong
2019-06-25  3:48  7%   ` Eric Wong

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