From: Eric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Date: Thu, 5 Apr 2018 21:45:25 +0000 (+0000)
Subject: v2writable: allow tracking parallel versions
X-Git-Tag: v1.1.0-pre1~52
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=5e8be4aa1e6adb321e2b85f8f96ad1e2646c093a;p=public-inbox.git

v2writable: allow tracking parallel versions

For upgrades, this will let users keep an old version
running while performing "public-inbox-index" on the
newest version.
---

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 5c37e169..f5f88431 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -92,9 +92,12 @@ sub last_commit {
 	$self->meta_accessor('last_commit', $commit);
 }
 
-sub last_commit_n {
-	my ($self, $i, $commit) = @_;
-	$self->meta_accessor('last_commit'.$i, $commit);
+# v2 uses this to keep track of how up-to-date Xapian is
+# old versions may be automatically GC'ed away in the future,
+# but it's a trivial amount of storage.
+sub last_commit_xap {
+	my ($self, $version, $i, $commit) = @_;
+	$self->meta_accessor("last_xap$version-$i", $commit);
 }
 
 sub created_at {
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 83238460..ea116f1a 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -71,7 +71,7 @@ sub new {
 		lock_path => "$dir/inbox.lock",
 		# limit each repo to 1GB or so
 		rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
-		last_commit => [],
+		last_commit => [], # git repo -> commit
 	};
 	$self->{partitions} = count_partitions($self) || nproc();
 	bless $self, $class;
@@ -339,15 +339,20 @@ sub purge {
 	$purges;
 }
 
+sub last_commit_part ($$;$) {
+	my ($self, $i, $cmt) = @_;
+	my $v = PublicInbox::Search::SCHEMA_VERSION();
+	$self->{mm}->last_commit_xap($v, $i, $cmt);
+}
+
 sub set_last_commits ($) {
 	my ($self) = @_;
 	defined(my $max_git = $self->{max_git}) or return;
-	my $mm = $self->{mm};
 	my $last_commit = $self->{last_commit};
 	foreach my $i (0..$max_git) {
 		defined(my $cmt = $last_commit->[$i]) or next;
 		$last_commit->[$i] = undef;
-		$mm->last_commit_n($i, $cmt);
+		last_commit_part($self, $i, $cmt);
 	}
 }
 
@@ -673,13 +678,13 @@ sub reindex_oid {
 # only update last_commit for $i on reindex iff newer than current
 sub update_last_commit {
 	my ($self, $git, $i, $cmt) = @_;
-	my $last = $self->{mm}->last_commit_n($i);
+	my $last = last_commit_part($self, $i);
 	if (defined $last && is_ancestor($git, $last, $cmt)) {
 		my @cmd = (qw(rev-list --count), "$last..$cmt");
 		chomp(my $n = $git->qx(@cmd));
 		return if $n ne '' && $n == 0;
 	}
-	$self->{mm}->last_commit_n($i, $cmt);
+	last_commit_part($self, $i, $cmt);
 }
 
 sub git_dir_n ($$) { "$_[0]->{-inbox}->{mainrepo}/git/$_[1].git" }
@@ -688,7 +693,7 @@ sub last_commits {
 	my ($self, $max_git) = @_;
 	my $heads = [];
 	for (my $i = $max_git; $i >= 0; $i--) {
-		$heads->[$i] = $self->{mm}->last_commit_n($i);
+		$heads->[$i] = last_commit_part($self, $i);
 	}
 	$heads;
 }