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: |
* [PATCH 87/95] lei_mirror: eliminate circular references
  2022-11-28  5:30  7% [PATCH 00/95] clone: multi-inbox/repo support Eric Wong
@ 2022-11-28  5:32  4% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-11-28  5:32 UTC (permalink / raw)
  To: meta

...by using local-ized globals.  While non-globals could work,
eliminating the {todo} and {fgrp_todo} refs in all sub-refs
is more error-prone and the `local' construct is convenient.

This allows us to get rid of the `delete $fgrp->{-fini}' call
in pack_refs and eliminates the indiscriminate reaping of all
processes before calling fgrp_fetch_all.  This means we can
fully depend on DESTROY to provide predictable dependency
handling while supporting parallelization.

Global $TODO and $FGRP_TODO now become SCALAR refs on
consumption so they can act as assertions to detect future bugs.
---
 lib/PublicInbox/LeiMirror.pm | 43 ++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 47db9ccd..b30cc519 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -21,6 +21,8 @@ use PublicInbox::OnDestroy;
 use Digest::SHA qw(sha256_hex sha1_hex);
 
 our $LIVE; # pid => callback
+our $FGRP_TODO; # objstore -> [ fgrp mirror objects ]
+our $TODO; # reference => [ non-fgrp mirror objects ]
 
 sub keep_going ($) {
 	$LIVE && (!$_[0]->{lei}->{child_error} ||
@@ -324,7 +326,6 @@ sub fgrp_update {
 sub pack_dst { # packs lightweight satellite repos
 	my ($fgrp) = @_;
 	pack_refs($fgrp, $fgrp->{cur_dst});
-	delete($fgrp->{-fini}) // die 'BUG: no {-fini}'; # call v1_done
 }
 
 sub pack_refs {
@@ -362,7 +363,8 @@ sub fgrpv_done {
 
 sub fgrp_fetch_all {
 	my ($self) = @_;
-	my $todo = delete $self->{fgrp_todo} or return;
+	my $todo = $FGRP_TODO;
+	$FGRP_TODO = \'BUG on further use';
 	keys(%$todo) or return;
 
 	# Rely on the fgrptmp remote groups in the config file rather
@@ -510,7 +512,7 @@ sub resume_fetch {
 }
 
 sub fgrp_enqueue {
-	my ($fgrp) = @_;
+	my ($fgrp, $end) = @_; # $end calls fgrp_fetch_all
 	return if !keep_going($fgrp);
 	my $opt = { 2 => $fgrp->{lei}->{2} };
 	# --no-tags is required to avoid conflicts
@@ -523,12 +525,11 @@ sub fgrp_enqueue {
 		$fgrp->{dry_run} ? $fgrp->{lei}->qerr("# @cmd @kv") :
 				run_die([@cmd, @kv], undef, $opt);
 	}
-	$fgrp->{fgrp_todo} // die 'BUG: no fgrp_todo';
-	push @{$fgrp->{fgrp_todo}->{$fgrp->{-osdir}}}, $fgrp;
+	push @{$FGRP_TODO->{$fgrp->{-osdir}}}, $fgrp;
 }
 
 sub clone_v1 {
-	my ($self, $nohang) = @_;
+	my ($self, $end) = @_;
 	my $lei = $self->{lei};
 	my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
 	my $uri = URI->new($self->{cur_src} // $self->{src});
@@ -540,7 +541,8 @@ sub clone_v1 {
 	my $resume = -d $dst;
 	if (my $fgrp = forkgroup_prep($self, $uri)) {
 		$fgrp->{-fini} = $fini;
-		$resume ? cmp_fp_do($fgrp, \&fgrp_enqueue) : fgrp_enqueue($fgrp)
+		$resume ? cmp_fp_do($fgrp, \&fgrp_enqueue, $end)
+			: fgrp_enqueue($fgrp, $end);
 	} elsif ($resume) {
 		cmp_fp_do($self, \&resume_fetch, $uri, $fini);
 	} else { # normal clone
@@ -562,10 +564,10 @@ sub clone_v1 {
 
 	my $d = $self->{-ent} ? $self->{-ent}->{description} : undef;
 	$self->{'txt.description'} = $d if defined $d;
-	(!defined($d) && !$nohang) and
+	(!defined($d) && !$end) and
 		_get_txt_start($self, 'description', $fini);
 
-	$nohang or do_reap($self, 1); # for non-manifest clone
+	$end or do_reap($self, 1); # for non-manifest clone
 }
 
 sub parse_epochs ($$) {
@@ -785,7 +787,6 @@ sub clone_v2_prep ($$;$) {
 	my $dst = $self->{cur_dst} // $self->{dst};
 	my $want = parse_epochs($lei->{opt}->{epoch}, $v2_epochs);
 	my $task = $m ? bless { %$self }, __PACKAGE__ : $self;
-	delete $task->{todo}; # $self->{todo} still exists
 	my (@skip, $desc);
 	my $fini = PublicInbox::OnDestroy->new($$, \&v2_done, $task);
 	for my $nr (sort { $a <=> $b } keys %$v2_epochs) {
@@ -813,7 +814,7 @@ failed to extract epoch number from $src
 			$etask->{cur_dst} = $edst;
 			$etask->{-is_epoch} = $fini;
 			my $ref = $ent->{reference} // '';
-			push @{$self->{todo}->{$ref}}, $etask;
+			push @{$TODO->{$ref}}, $etask;
 			$self->{any_want}->{$key} = 1;
 		} else { # create a placeholder so users only need to chmod +w
 			init_placeholder($src, $edst, $ent);
@@ -917,7 +918,9 @@ sub multi_inbox ($$$) {
 
 sub clone_all {
 	my ($self, $m) = @_;
-	my $todo = delete $self->{todo};
+	my $todo = $TODO;
+	$TODO = \'BUG on further use';
+	my $end = PublicInbox::OnDestroy->new($$, \&fgrp_fetch_all, $self);
 	{
 		my $nodep = delete $todo->{''};
 
@@ -929,7 +932,7 @@ sub clone_all {
 
 		# handle no-dependency repos, first
 		for (@$nodep) {
-			clone_v1($_, 1);
+			clone_v1($_, $end);
 			return if !keep_going($self);
 		}
 	}
@@ -947,14 +950,16 @@ EOM
 			}
 			my $y = delete $todo->{$x} // next; # already done
 			for (@$y) {
-				clone_v1($_, 1);
+				clone_v1($_, $end);
 				return if !keep_going($self);
 			}
 			last; # restart %$todo iteration
 		}
 	}
-	do_reap($self, 1); # finish all fingerprint checks
-	fgrp_fetch_all($self);
+
+	# $end->DESTROY will call fgrp_fetch_all once all references
+	# in $LIVE are gone, and do_reap will eventually drain $LIVE
+	$end = undef;
 	do_reap($self, 1);
 }
 
@@ -1007,8 +1012,6 @@ sub try_manifest {
 	my ($path_pfx, $n, $multi) = multi_inbox($self, \$path, $m);
 	return $lei->child_error(1, $multi) if !ref($multi);
 	my $v2 = delete $multi->{v2};
-	local $self->{todo} = {};
-	local $self->{fgrp_todo} = {}; # { objstore_dir => [fgrp, ...] }
 	if ($v2) {
 		for my $name (sort keys %$v2) {
 			my $epochs = delete $v2->{$name};
@@ -1054,7 +1057,7 @@ E: `$task->{cur_dst}' must not contain newline
 EOM
 			$task->{cur_src} .= '/';
 			my $dep = $task->{-ent}->{reference} // '';
-			push @{$self->{todo}->{$dep}}, $task; # for clone_all
+			push @{$TODO->{$dep}}, $task; # for clone_all
 			$self->{any_want}->{$name} = 1;
 		}
 	}
@@ -1112,6 +1115,8 @@ sub do_mirror { # via wq_io_do or public-inbox-clone
 			$self->{"-$k"} = $v;
 		}
 		local $LIVE = {};
+		local $TODO = {};
+		local $FGRP_TODO = {};
 		my $iv = $lei->{opt}->{'inbox-version'} //
 			return start_clone_url($self);
 		return clone_v1($self) if $iv == 1;

^ permalink raw reply related	[relevance 4%]

* [PATCH 00/95] clone: multi-inbox/repo support...
@ 2022-11-28  5:30  7% Eric Wong
  2022-11-28  5:32  4% ` [PATCH 87/95] lei_mirror: eliminate circular references Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-11-28  5:30 UTC (permalink / raw)
  To: meta

A large patchset, and not done, yet :P  It's only tested live,
but it seems to work reasonably well against live hosts...

Behavior changes to public-inbox-clone are NOT final; but
public-inbox-fetch|PublicInbox::Fetch will probably become
thin wrappers around LeiMirror.

--include=/--exclude= support now exists with glob support

--keep-going and --dry-run support added, too, since it's
make(1) influenced (more below)

It supports coderepos, too, using --inbox-config=never (default: always);
--project-list=, --manifest=, --objstore=, and --prune.

key differences from grok-pull (grokmirror) for coderepos:

* uses relative paths on the FS (dumb HTTP untested, but dumb
  HTTP is a goal for memory-constrained hosts).  This means
  I can relocate coderepos freely within my FS or do sneakernet
  transfers across machines without having to `perl -ipe s/x/y/'
  on hundreds of info/alternates and config files.

* CLI-only, no extra config files (may generate a Makefile, like
  individual inbox clones)

* objstore repos fetches from remotes directly
  (does not need, use, nor benefit from hardlinks at all)

* no sleep states

It is not a full replacement for grokmirror

* reliant on default `git gc' behavior for repack. This is OK
  since it's only one-way relationships between objstore and
  non-objstore repos.

* no fsck support (probably will be in generated Makefile)

* doesn't generate forkgroups nor manifest.js.gz
  (I may do this for coderepo Xapian indexing)

It relies on parallel git-fetch for objstores, so `-j $NUM'
calculations may end up being ($NUM * $NUM) in the worst case.
Not sure how to best approach this...
Maybe `-j $M,$N' similar to `lei q -j$M,$N` is a solution...

Design note:

This is an exercise in building make(1)-like parallelism using
->DESTROY callbacks for prerequisites; so it's a newish paradigm
for me.  It forced me to fix a reference cycle, already.

TODO: repo|symlink pruning, --exit-code, retry/refetch, manpage updates

Eric Wong (95):
  clone: support multi-inbox clone
  clone: support --include and --exclude with multi-clone
  clone: parallelize v2 epoch clones
  lei_mirror: async config retrieval for v2 w/ manifest
  lei_mirror: rely on DESTROY to index v2 inbox
  lei_mirror: rely on global process reaper
  clone: support parallel v1 clones
  lei_mirror: default to single job by default
  lei_mirror: move directory creation to v2-only path
  lei_mirror: retrieve description text asynchronously, too
  switch inotify/kevent stuff to v5.12
  manifest: update module blurb + v5.12
  lei_mirror: simplify _get_txt_start callers
  lei_mirror: elide description retrieval for v1|coderepo
  lei_mirror: add a hint for skipped epoch permissions
  lei_mirror: consolidate clone process management
  lei_mirror: load File::Path unconditionally
  lei_mirror: load most modules up-front
  lei_mirror: set gitweb.owner from manifest
  clone: support --dry-run / -n flag
  lei_mirror: initialize placeholders with "head" from manifest
  lei_mirror: support {reference} for v1 manifest clones
  lei_mirror: reduce noise on interrupted clones
  clone: support --inbox-config option
  lei_mirror: retrieve v2 description properly
  lei_mirror: reduce scope of v2 lock
  lei_mirror: allow --epoch on mixed v1/v2 clones
  lei_mirror: fix infinite loop in dependency resolution
  lei_mirror: defend against infinite loops
  lei_mirror: do not fetch descriptions if using manifest
  lei_mirror: require PublicInbox::Lock at use
  lei_mirror: fix glob semantics to match end-of-path
  lei_mirror: differentiate -entv vs -ent
  lei_mirror: support manifest {references} for v2 epochs
  lei_mirror: simplify v2 code paths
  clone: support --inbox-version
  lei_mirror: require Perl v5.12+
  lei_mirror: ensure curl exits 22 on HTTP 404 responses
  lei_mirror: cleanup File::Temp OO usage
  lei_mirror: add `index' target to generated Makefile
  lei_mirror: do not write Makefile for --inbox-config=never
  lei_mirror: hoist out dump_manifest sub
  lei_mirror: avoid convoluted lazy_cb usage
  lei_mirror: simplify clone_v2_prep
  lei_mirror: support --objstore and forkgroups
  lei_mirror: cleanup process reaping logic
  lei_mirror: ensure git <1.8.5 fallback can use torsocks
  clone: flesh out --objstore behavior and document
  lei_mirror: always pack refs for coderepos
  lei_mirror: set description for non-inboxes, too
  lei_mirror: force --no-tags when fetching forkgroups
  lei_mirror: preserve permissions of existing alternates file
  lei_mirror: do not show ref updates w/o --verbose
  lei_mirror: drop git <1.8.5 support
  lei_mirror: make basename more descriptive
  lei_mirror: fix --dry-run for forkgroups
  lei_mirror: forkgroups use `git fetch --multiple'
  clone: move --dry-run handling to lei_mirror
  clone: drop unnecessary requires
  clone: use v5.12
  clone: require `--objstore=' for default location
  lei_mirror: shorten remote names
  fetch: use v5.12
  fetch: eliminate File::Temp->filename var
  lei_mirror: properly pack-refs in non-forkgroup repos
  lei_mirror: show child error error code
  on_destroy: support ->cancel callback
  lei_mirror: support resuming multi-repo clones
  lei_mirror: check fingerprints before fetching
  clone: support loading manifest.js.gz from destination
  lei_mirror: delay configuring forkgroups
  clone: canonicalize destination path from CLI
  clone|fetch: support passing --prune(-tags) to `git fetch'
  lei_mirror: avoid needless FD passing
  clone: support --keep-going/-k like make(1)
  lei_mirror: don't warn on missing manifest on initial clone
  lei_mirror: respect `./' and `../' prefixes for CLI args
  lei_mirror: --manifest= affects destination, too
  lei_mirror: update fingerprints when writing local manifest.js.gz
  lei_mirror: remove janky mirror.done stamp file
  lei_mirror: simplify most process spawning
  lei_mirror: run v1_done earlier on forkgroup done
  lei_mirror: simplify forkgroup-related subs
  lei_mirror: shorten scope mirror objects
  lei_mirror: set {head} from manifest
  lei_mirror: support {symlinks} from manifest
  lei_mirror: eliminate circular references
  lei_mirror: use curl -z/--timecond if manifest exists
  lei_mirror: avoid redundant curl `-f' use
  lei_mirror: omit trailing slash for git remote.*.url
  lei_mirror: set info/web/last-modified from manifest
  lei_mirror: don't clobber inbox.config.example if it exists
  lei_mirror: break out of fgrp fetch iteration early
  clone: support --project-list= for cgit
  lei_mirror: handle forkgroup changes

 Documentation/lei-add-external.pod   |    4 +-
 Documentation/public-inbox-clone.pod |   76 ++
 Documentation/public-inbox-fetch.pod |    6 +
 lib/PublicInbox/DSKQXS.pm            |    5 +-
 lib/PublicInbox/DirIdle.pm           |    4 +-
 lib/PublicInbox/FakeInotify.pm       |   13 +-
 lib/PublicInbox/Fetch.pm             |   50 +-
 lib/PublicInbox/In2Tie.pm            |    4 +-
 lib/PublicInbox/InboxIdle.pm         |    2 +-
 lib/PublicInbox/KQNotify.pm          |   12 +-
 lib/PublicInbox/LEI.pm               |    5 +-
 lib/PublicInbox/LeiMirror.pm         | 1104 +++++++++++++++++++++-----
 lib/PublicInbox/ManifestJsGz.pm      |    8 +-
 lib/PublicInbox/OnDestroy.pm         |    5 +-
 lib/PublicInbox/TestCommon.pm        |    1 +
 script/public-inbox-clone            |   23 +-
 script/public-inbox-fetch            |    4 +-
 t/on_destroy.t                       |    8 +-
 t/www_listing.t                      |   71 +-
 19 files changed, 1148 insertions(+), 257 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-11-28  5:30  7% [PATCH 00/95] clone: multi-inbox/repo support Eric Wong
2022-11-28  5:32  4% ` [PATCH 87/95] lei_mirror: eliminate circular references 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).