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 14/20] v2writable: rename local vars to match Xapian terminology
Date: Sat, 15 Jun 2019 08:47:10 +0000	[thread overview]
Message-ID: <20190615084716.3075-15-e@80x24.org> (raw)
In-Reply-To: <20190615084716.3075-1-e@80x24.org>

---
 lib/PublicInbox/V2Writable.pm | 53 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index a231390..502824c 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -54,22 +54,22 @@ sub nproc_shards ($) {
 
 sub count_shards ($) {
 	my ($self) = @_;
-	my $nparts = 0;
+	my $n = 0;
 	my $xpfx = $self->{xpfx};
 
 	# always load existing partitions in case core count changes:
 	# Also, shard count may change while -watch is running
 	# due to "xcpdb --reshard"
 	if (-d $xpfx) {
-		foreach my $part (<$xpfx/*>) {
-			-d $part && $part =~ m!/[0-9]+\z! or next;
+		foreach my $shard (<$xpfx/*>) {
+			-d $shard && $shard =~ m!/[0-9]+\z! or next;
 			eval {
-				Search::Xapian::Database->new($part)->close;
-				$nparts++;
+				Search::Xapian::Database->new($shard)->close;
+				$n++;
 			};
 		}
 	}
-	$nparts;
+	$n;
 }
 
 sub new {
@@ -134,12 +134,10 @@ sub add {
 sub do_idx ($$$$$$$) {
 	my ($self, $msgref, $mime, $len, $num, $oid, $mid0) = @_;
 	$self->{over}->add_overview($mime, $len, $num, $oid, $mid0);
-	my $npart = $self->{shards};
-	my $part = $num % $npart;
-	my $idx = idx_shard($self, $part);
+	my $idx = idx_shard($self, $num % $self->{shards});
 	$idx->index_raw($len, $msgref, $num, $oid, $mid0, $mime);
 	my $n = $self->{transact_bytes} += $len;
-	$n >= (PublicInbox::SearchIdx::BATCH_BYTES * $npart);
+	$n >= (PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards});
 }
 
 sub _add {
@@ -253,8 +251,8 @@ sub num_for_harder {
 }
 
 sub idx_shard {
-	my ($self, $part) = @_;
-	$self->{idx_shards}->[$part];
+	my ($self, $shard_i) = @_;
+	$self->{idx_shards}->[$shard_i];
 }
 
 # idempotent
@@ -289,9 +287,9 @@ sub idx_init {
 		$over->create;
 
 		# xcpdb can change shard count while -watch is idle
-		my $nparts = count_shards($self);
-		if ($nparts && $nparts != $self->{shards}) {
-			$self->{shards} = $nparts;
+		my $nshards = count_shards($self);
+		if ($nshards && $nshards != $self->{shards}) {
+			$self->{shards} = $nshards;
 		}
 
 		# need to create all parts before initializing msgmap FD
@@ -370,7 +368,6 @@ sub rewrite_internal ($$;$$$) {
 	}
 	my $over = $self->{over};
 	my $cids = content_ids($old_mime);
-	my $parts = $self->{idx_shards};
 	my $removed;
 	my $mids = mids($old_mime->header_obj);
 
@@ -590,7 +587,7 @@ sub barrier_wait {
 	while (scalar keys %$barrier) {
 		defined(my $l = $r->getline) or die "EOF on barrier_wait: $!";
 		$l =~ /\Abarrier (\d+)/ or die "bad line on barrier_wait: $l";
-		delete $barrier->{$1} or die "bad part[$1] on barrier wait";
+		delete $barrier->{$1} or die "bad shard[$1] on barrier wait";
 	}
 }
 
@@ -605,8 +602,8 @@ sub checkpoint ($;$) {
 			$im->checkpoint;
 		}
 	}
-	my $parts = $self->{idx_shards};
-	if ($parts) {
+	my $shards = $self->{idx_shards};
+	if ($shards) {
 		my $dbh = $self->{mm}->{dbh};
 
 		# SQLite msgmap data is second in importance
@@ -617,15 +614,15 @@ sub checkpoint ($;$) {
 
 		# Now deal with Xapian
 		if ($wait) {
-			my $barrier = $self->barrier_init(scalar @$parts);
+			my $barrier = $self->barrier_init(scalar @$shards);
 
 			# each partition needs to issue a barrier command
-			$_->remote_barrier for @$parts;
+			$_->remote_barrier for @$shards;
 
 			# wait for each Xapian partition
 			$self->barrier_wait($barrier);
 		} else {
-			$_->remote_commit for @$parts;
+			$_->remote_commit for @$shards;
 		}
 
 		# last_commit is special, don't commit these until
@@ -652,14 +649,14 @@ sub done {
 	checkpoint($self);
 	my $mm = delete $self->{mm};
 	$mm->{dbh}->commit if $mm;
-	my $parts = delete $self->{idx_shards};
-	if ($parts) {
-		$_->remote_close for @$parts;
+	my $shards = delete $self->{idx_shards};
+	if ($shards) {
+		$_->remote_close for @$shards;
 	}
 	$self->{over}->disconnect;
 	delete $self->{bnote};
 	$self->{transact_bytes} = 0;
-	$self->lock_release if $parts;
+	$self->lock_release if $shards;
 	$self->{-inbox}->git->cleanup;
 }
 
@@ -827,8 +824,8 @@ sub atfork_child {
 	my ($self) = @_;
 	my $fh = delete $self->{reindex_pipe};
 	close $fh if $fh;
-	if (my $parts = $self->{idx_shards}) {
-		$_->atfork_child foreach @$parts;
+	if (my $shards = $self->{idx_shards}) {
+		$_->atfork_child foreach @$shards;
 	}
 	if (my $im = $self->{im}) {
 		$im->atfork_child;
-- 
EW


  parent reply	other threads:[~2019-06-15  8:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-15  8:46 [PATCH 00/20] v2: use consistent terminology Eric Wong
2019-06-15  8:46 ` [PATCH 01/20] doc: rename our Xapian "partitions" to "shards" Eric Wong
2019-06-15  8:46 ` [PATCH 02/20] v2writable: update comments regarding xcpdb --reshard Eric Wong
2019-06-15  8:46 ` [PATCH 03/20] admin|xapcmd: user-facing messages say "shard" Eric Wong
2019-06-15  8:47 ` [PATCH 04/20] rename reference to git epochs as "partitions" Eric Wong
2019-06-15  8:47 ` [PATCH 05/20] searchidxpart: start using "shard" in user-visible places Eric Wong
2019-06-15  8:47 ` [PATCH 06/20] v2writable: count_partitions => count_shards Eric Wong
2019-06-15  8:47 ` [PATCH 07/20] v2writable: rename {partitions} field to {shards} Eric Wong
2019-06-15  8:47 ` [PATCH 08/20] tests: change messages to use "shard" instead of partition Eric Wong
2019-06-15  8:47 ` [PATCH 09/20] inboxwritable: s/partitions/shards/ in local var Eric Wong
2019-06-15  8:47 ` [PATCH 10/20] v2: rename SearchIdxPart => SearchIdxShard Eric Wong
2019-06-15  8:47 ` [PATCH 11/20] xapcmd: update comments referencing "partitions" Eric Wong
2019-06-15  8:47 ` [PATCH 12/20] search*: rename {partition} => {shard} Eric Wong
2019-06-15  8:47 ` [PATCH 13/20] v2writable: avoid "part" in internal subs and fields Eric Wong
2019-06-15  8:47 ` Eric Wong [this message]
2019-06-15  8:47 ` [PATCH 15/20] adminedit: "part" => "shard" for local variables Eric Wong
2019-06-15  8:47 ` [PATCH 16/20] v2writable: use "epoch" consistently when referring to git repos Eric Wong
2019-06-15  8:47 ` [PATCH 17/20] search: use "shard" for local variable Eric Wong
2019-06-15  8:47 ` [PATCH 18/20] xapcmd: favor 'shard' over 'part' in local variables Eric Wong
2019-06-15  8:47 ` [PATCH 19/20] t/xcpdb-reshard: use 'shard' term " Eric Wong
2019-06-15  8:47 ` [PATCH 20/20] comments: replace "partition" with "shard" 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=20190615084716.3075-15-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).