user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 7/9] v2: pass smsg in more places
Date: Fri, 20 Mar 2020 08:18:19 +0000	[thread overview]
Message-ID: <20200320081821.21715-8-e@yhbt.net> (raw)
In-Reply-To: <20200320081821.21715-1-e@yhbt.net>

We can pass fewer order-dependent args to V2Writable::do_idx and
SearchIdxShard::index_raw by passing the smsg object, instead.
---
 lib/PublicInbox/SearchIdxShard.pm | 27 ++++++----------
 lib/PublicInbox/V2Writable.pm     | 52 +++++++++++++++++++------------
 2 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm
index d29e6090..21e81b16 100644
--- a/lib/PublicInbox/SearchIdxShard.pm
+++ b/lib/PublicInbox/SearchIdxShard.pm
@@ -67,20 +67,19 @@ sub shard_worker_loop ($$$$$) {
 			$self->remove_by_oid($oid, $mid);
 		} else {
 			chomp $line;
-			my ($len, $artnum, $oid, $mid0, $autime, $cotime) =
+			my ($bytes, $num, $blob, $mid, $autime, $cotime) =
 							split(/ /, $line);
 			$self->begin_txn_lazy;
-			my $n = read($r, my $msg, $len) or die "read: $!\n";
-			$n == $len or die "short read: $n != $len\n";
+			my $n = read($r, my $msg, $bytes) or die "read: $!\n";
+			$n == $bytes or die "short read: $n != $bytes\n";
 			my $mime = PublicInbox::MIME->new(\$msg);
-			$artnum = int($artnum);
 			$self->{autime} = $autime;
 			$self->{cotime} = $cotime;
 			my $smsg = bless {
-				bytes => $len,
-				num => $artnum,
-				blob => $oid,
-				mid => $mid0,
+				bytes => $bytes,
+				num => $num + 0,
+				blob => $blob,
+				mid => $mid,
 			}, 'PublicInbox::Smsg';
 			$self->add_message($mime, $smsg);
 		}
@@ -90,23 +89,17 @@ sub shard_worker_loop ($$$$$) {
 
 # called by V2Writable
 sub index_raw {
-	my ($self, $bytes, $msgref, $artnum, $oid, $mid0, $mime, $times) = @_;
+	my ($self, $msgref, $mime, $smsg, $times) = @_;
 	my $at = $times->{autime} // time;
 	my $ct = $times->{cotime} // time;
 	if (my $w = $self->{w}) {
-		print $w "$bytes $artnum $oid $mid0 $at $ct\n", $$msgref or
-			die "failed to write shard $!\n";
+		print $w join(' ', @$smsg{qw(bytes num blob mid)}, $at, $ct),
+			"\n", $$msgref or die "failed to write shard $!\n";
 	} else {
 		$$msgref = undef;
 		$self->begin_txn_lazy;
 		$self->{autime} = $at;
 		$self->{cotime} = $ct;
-		my $smsg = bless {
-			bytes => $bytes,
-			num => $artnum,
-			blob => $oid,
-			mid => $mid0,
-		}, 'PublicInbox::Smsg';
 		$self->add_message($mime, $smsg);
 	}
 }
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 34dd139b..b5332da4 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -148,18 +148,12 @@ sub add {
 }
 
 # indexes a message, returns true if checkpointing is needed
-sub do_idx ($$$$$$$) {
-	my ($self, $msgref, $mime, $len, $num, $oid, $mid0) = @_;
-	my $smsg = bless {
-		bytes => $len,
-		num => $num,
-		blob => $oid,
-		mid => $mid0,
-	}, 'PublicInbox::Smsg';
+sub do_idx ($$$$) {
+	my ($self, $msgref, $mime, $smsg) = @_;
 	$self->{over}->add_overview($mime, $smsg, $self);
-	my $idx = idx_shard($self, $num % $self->{shards});
-	$idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime, $self);
-	my $n = $self->{transact_bytes} += $len;
+	my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
+	$idx->index_raw($msgref, $mime, $smsg, $self);
+	my $n = $self->{transact_bytes} += $smsg->{bytes};
 	$n >= (PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards});
 }
 
@@ -186,8 +180,10 @@ sub _add {
 	$cmt = $im->get_mark($cmt);
 	$self->{last_commit}->[$self->{epoch_max}] = $cmt;
 
-	my ($oid, $len, $msgref) = @{$im->{last_object}};
-	if (do_idx($self, $msgref, $mime, $len, $num, $oid, $mid0)) {
+	my $msgref;
+	my $smsg = bless { mid => $mid0, num => $num }, 'PublicInbox::Smsg';
+	($smsg->{blob}, $smsg->{bytes}, $msgref) = @{$im->{last_object}};
+	if (do_idx($self, $msgref, $mime, $smsg)) {
 		$self->checkpoint;
 	}
 
@@ -557,17 +553,21 @@ W: $list
 	}
 
 	# make sure we really got the OID:
-	my ($oid, $type, $len) = $self->{-inbox}->git->check($expect_oid);
-	$oid eq $expect_oid or die "BUG: $expect_oid not found after replace";
+	my ($blob, $type, $bytes) = $self->{-inbox}->git->check($expect_oid);
+	$blob eq $expect_oid or die "BUG: $expect_oid not found after replace";
 
 	# don't leak FDs to Xapian:
 	$self->{-inbox}->git->cleanup;
 
 	# reindex modified messages:
 	for my $smsg (@$need_reindex) {
-		my $num = $smsg->{num};
-		my $mid0 = $smsg->{mid};
-		do_idx($self, \$raw, $new_mime, $len, $num, $oid, $mid0);
+		my $new_smsg = bless {
+			blob => $blob,
+			bytes => $bytes,
+			num => $smsg->{num},
+			mid => $smsg->{mid},
+		}, 'PublicInbox::Smsg';
+		do_idx($self, \$raw, $new_mime, $new_smsg);
 	}
 	$rewritten->{rewrites};
 }
@@ -955,7 +955,13 @@ sub reindex_oid_m ($$$$;$) {
 		}
 	}
 	$sync->{nr}++;
-	if (do_idx($self, $msgref, $mime, $len, $num, $oid, $mid0)) {
+	my $smsg = bless {
+		bytes => $len,
+		num => $num,
+		blob => $oid,
+		mid => $mid0,
+	}, 'PublicInbox::Smsg';
+	if (do_idx($self, $msgref, $mime, $smsg)) {
 		reindex_checkpoint($self, $sync, $git);
 	}
 }
@@ -1051,7 +1057,13 @@ sub reindex_oid ($$$$) {
 	$sync->{mm_tmp}->mid_delete($mid0) or
 		die "failed to delete <$mid0> for article #$num\n";
 	$sync->{nr}++;
-	if (do_idx($self, $msgref, $mime, $len, $num, $oid, $mid0)) {
+	my $smsg = bless {
+		bytes => $len,
+		num => $num,
+		blob => $oid,
+		mid => $mid0,
+	}, 'PublicInbox::Smsg';
+	if (do_idx($self, $msgref, $mime, $smsg)) {
 		reindex_checkpoint($self, $sync, $git);
 	}
 }

  parent reply	other threads:[~2020-03-20  8:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05  3:23 [PATCH] index: use git commit times on missing Date/Received Eric Wong
2020-03-05  5:13 ` Eric Wong
2020-03-20  8:18   ` [PATCH 0/9] preserve time and date of initial commit Eric Wong
2020-03-20  8:18     ` [PATCH 1/9] index: use git commit times on missing Date/Received Eric Wong
2020-03-20  8:18     ` [PATCH 2/9] v2writable: preserve timestamps from import Eric Wong
2020-03-20  8:18     ` [PATCH 3/9] rename PublicInbox::SearchMsg => PublicInbox::Smsg Eric Wong
2020-03-20  8:18     ` [PATCH 4/9] smsg: to_doc_data: use existing fields Eric Wong
2020-03-20  8:18     ` [PATCH 5/9] overidx: parse_references: less error-prone args Eric Wong
2020-03-20  8:18     ` [PATCH 6/9] *idx: pass $smsg in more places instead of many args Eric Wong
2020-03-20  8:18     ` Eric Wong [this message]
2020-03-20  8:18     ` [PATCH 8/9] *idx: pass smsg in even more places Eric Wong
2020-03-20  8:18     ` [PATCH 9/9] v2: SDBM-based multi Message-ID queue Eric Wong

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=20200320081821.21715-8-e@yhbt.net \
    --to=e@yhbt.net \
    --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).