user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 18/20] xapcmd: favor 'shard' over 'part' in local variables
Date: Sat, 15 Jun 2019 08:47:14 +0000
Message-ID: <20190615084716.3075-19-e@80x24.org> (raw)
In-Reply-To: <20190615084716.3075-1-e@80x24.org>

Yet another step to keeping our naming consistent with Xapian
terminology.
---
 lib/PublicInbox/Xapcmd.pm | 70 +++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 5e4ac87..819d782 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -17,13 +17,13 @@ our @COMPACT_OPT = qw(jobs|j=i quiet|q blocksize|b=s no-full|n fuller|F);
 
 sub commit_changes ($$$) {
 	my ($ibx, $tmp, $opt) = @_;
-	my $new_parts = $opt->{reshard};
+	my $reshard = $opt->{reshard};
 	my $reindex = $opt->{reindex};
 	my $im = $ibx->importer(0);
 	$im->lock_acquire if !$opt->{-coarse_lock};
 
 	$SIG{INT} or die 'BUG: $SIG{INT} not handled';
-	my @old_part;
+	my @old_shard;
 
 	while (my ($old, $new) = each %$tmp) {
 		my @st = stat($old);
@@ -41,7 +41,7 @@ sub commit_changes ($$$) {
 		}
 
 		if (!defined($new)) { # culled shard
-			push @old_part, $old;
+			push @old_shard, $old;
 			next;
 		}
 
@@ -58,7 +58,7 @@ sub commit_changes ($$$) {
 				die "failed to remove $prev: $!\n";
 		}
 	}
-	remove_tree(@old_part);
+	remove_tree(@old_shard);
 	$tmp->done;
 	if (!$opt->{-coarse_lock}) {
 		$opt->{-skip_lock} = 1;
@@ -66,9 +66,9 @@ sub commit_changes ($$$) {
 		if ($im->can('count_shards')) {
 			my $pr = $opt->{-progress};
 			my $n = $im->count_shards;
-			if (defined $new_parts && $n != $new_parts) {
+			if (defined $reshard && $n != $reshard) {
 				die
-"BUG: counted $n shards after resharding to $new_parts";
+"BUG: counted $n shards after resharding to $reshard";
 			}
 			my $prev = $im->{shards};
 			if ($pr && $prev != $n) {
@@ -171,17 +171,17 @@ sub run {
 	my $tmp = PublicInbox::Xtmpdirs->new;
 	my $v = $ibx->{version} ||= 1;
 	my @q;
-	my $new_parts = $opt->{reshard};
-	if (defined $new_parts && $new_parts <= 0) {
+	my $reshard = $opt->{reshard};
+	if (defined $reshard && $reshard <= 0) {
 		die "--reshard must be a positive number\n";
 	}
 
 	# we want temporary directories to be as deep as possible,
 	# so v2 shards can keep "xap$SCHEMA_VERSION" on a separate FS.
 	if ($v == 1) {
-		if (defined $new_parts) {
+		if (defined $reshard) {
 			warn
-"--reshard=$new_parts ignored for v1 $ibx->{mainrepo}\n";
+"--reshard=$reshard ignored for v1 $ibx->{mainrepo}\n";
 		}
 		my $old_parent = dirname($old);
 		same_fs_or_die($old_parent, $old);
@@ -191,28 +191,28 @@ sub run {
 		push @q, [ $old, $wip ];
 	} else {
 		opendir my $dh, $old or die "Failed to opendir $old: $!\n";
-		my @old_parts;
+		my @old_shards;
 		while (defined(my $dn = readdir($dh))) {
 			if ($dn =~ /\A[0-9]+\z/) {
-				push @old_parts, $dn;
+				push @old_shards, $dn;
 			} elsif ($dn eq '.' || $dn eq '..') {
 			} elsif ($dn =~ /\Aover\.sqlite3/) {
 			} else {
 				warn "W: skipping unknown dir: $old/$dn\n"
 			}
 		}
-		die "No Xapian parts found in $old\n" unless @old_parts;
+		die "No Xapian shards found in $old\n" unless @old_shards;
 
-		my ($src, $max_part);
-		if (!defined($new_parts) || $new_parts == scalar(@old_parts)) {
+		my ($src, $max_shard);
+		if (!defined($reshard) || $reshard == scalar(@old_shards)) {
 			# 1:1 copy
-			$max_part = scalar(@old_parts) - 1;
+			$max_shard = scalar(@old_shards) - 1;
 		} else {
 			# M:N copy
-			$max_part = $new_parts - 1;
-			$src = [ map { "$old/$_" } @old_parts ];
+			$max_shard = $reshard - 1;
+			$src = [ map { "$old/$_" } @old_shards ];
 		}
-		foreach my $dn (0..$max_part) {
+		foreach my $dn (0..$max_shard) {
 			my $tmpl = "$dn-XXXXXXXX";
 			my $wip = tempdir($tmpl, DIR => $old);
 			same_fs_or_die($old, $wip);
@@ -220,7 +220,7 @@ sub run {
 			push @q, [ $src // $cur , $wip ];
 			$tmp->{$cur} = $wip;
 		}
-		# mark old parts to be unlinked
+		# mark old shards to be unlinked
 		if ($src) {
 			$tmp->{$_} ||= undef for @$src;
 		}
@@ -305,7 +305,7 @@ sub compact ($$) {
 }
 
 sub cpdb_loop ($$$;$$) {
-	my ($src, $dst, $pr_data, $cur_part, $new_parts) = @_;
+	my ($src, $dst, $pr_data, $cur_shard, $reshard) = @_;
 	my ($pr, $fmt, $nr, $pfx);
 	if ($pr_data) {
 		$pr = $pr_data->{pr};
@@ -326,9 +326,9 @@ sub cpdb_loop ($$$;$$) {
 		eval {
 			for (; $it != $end; $it++) {
 				my $docid = $it->get_docid;
-				if (defined $new_parts) {
-					my $dst_part = $docid % $new_parts;
-					next if $dst_part != $cur_part;
+				if (defined $reshard) {
+					my $dst_shard = $docid % $reshard;
+					next if $dst_shard != $cur_shard;
 				}
 				my $doc = $src->get_document($docid);
 				$dst->replace_document($docid, $doc);
@@ -350,14 +350,14 @@ sub cpdb_loop ($$$;$$) {
 sub cpdb ($$) {
 	my ($args, $opt) = @_;
 	my ($old, $new) = @$args;
-	my ($src, $cur_part);
-	my $new_parts;
+	my ($src, $cur_shard);
+	my $reshard;
 	if (ref($old) eq 'ARRAY') {
-		($cur_part) = ($new =~ m!xap[0-9]+/([0-9]+)\b!);
-		defined $cur_part or
+		($cur_shard) = ($new =~ m!xap[0-9]+/([0-9]+)\b!);
+		defined $cur_shard or
 			die "BUG: could not extract shard # from $new";
-		$new_parts = $opt->{reshard};
-		defined $new_parts or die 'BUG: got array src w/o --reshard';
+		$reshard = $opt->{reshard};
+		defined $reshard or die 'BUG: got array src w/o --reshard';
 
 		# resharding, M:N copy means have full read access
 		foreach (@$old) {
@@ -410,8 +410,8 @@ sub cpdb ($$) {
 				# we can only estimate when resharding,
 				# because removed spam causes slight imbalance
 				my $est = '';
-				if (defined $cur_part && $new_parts > 1) {
-					$tot = int($tot/$new_parts);
+				if (defined $cur_shard && $reshard > 1) {
+					$tot = int($tot/$reshard);
 					$est = 'around ';
 				}
 				my $fmt = "$pfx % ".length($tot)."u/$tot\n";
@@ -422,15 +422,15 @@ sub cpdb ($$) {
 		};
 	} while (cpdb_retryable($src, $pfx));
 
-	if (defined $new_parts) {
+	if (defined $reshard) {
 		# we rely on document IDs matching NNTP article number,
-		# so we can't have the combined DB support rewriting
+		# so we can't have the Xapian sharding DB support rewriting
 		# document IDs.  Thus we iterate through each shard
 		# individually.
 		$src = undef;
 		foreach (@$old) {
 			my $old = Search::Xapian::Database->new($_);
-			cpdb_loop($old, $dst, $pr_data, $cur_part, $new_parts);
+			cpdb_loop($old, $dst, $pr_data, $cur_shard, $reshard);
 		}
 	} else {
 		cpdb_loop($src, $dst, $pr_data);
-- 
EW


  parent reply index

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 ` [PATCH 14/20] v2writable: rename local vars to match Xapian terminology Eric Wong
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 ` Eric Wong [this message]
2019-06-15  8:47 ` [PATCH 19/20] t/xcpdb-reshard: use 'shard' term in local variables Eric Wong
2019-06-15  8:47 ` [PATCH 20/20] comments: replace "partition" with "shard" Eric Wong

Reply instructions:

You may reply publically 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-19-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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git