]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: keep DB handles if git processes are live
authorEric Wong <e@80x24.org>
Fri, 1 Oct 2021 09:54:43 +0000 (09:54 +0000)
committerEric Wong <e@80x24.org>
Fri, 1 Oct 2021 12:06:33 +0000 (12:06 +0000)
Having git processes outlive DB handles is likely to hurt
from a fragmentation perspective if the DB handle needs to
be recreated immediately due to a git->cat_async callback.
So only unref DB handles when we're sure there's no live
git users left, otherwise check the inodes.

We'll also avoid needless localization checks in git->cleanup
and make the return value more obvious since the pid fields are
unconditionally deleted nowadays.

lib/PublicInbox/Git.pm
lib/PublicInbox/Inbox.pm

index 97c39aad7468a09db5c0a1a5f68d852745f61a2d..77783000573f20692be001042d256ed20597cfce 100644 (file)
@@ -399,16 +399,16 @@ sub async_wait_all ($) {
 # returns true if there are pending "git cat-file" processes
 sub cleanup {
        my ($self, $lazy) = @_;
-       local $in_cleanup = 1;
        return 1 if $lazy && (scalar(@{$self->{inflight_c} // []}) ||
                                scalar(@{$self->{inflight} // []}));
+       local $in_cleanup = 1;
        delete $self->{async_cat};
        async_wait_all($self);
        delete $self->{inflight};
        delete $self->{inflight_c};
        _destroy($self, qw(cat_rbuf in out pid));
        _destroy($self, qw(chk_rbuf in_c out_c pid_c err_c));
-       defined($self->{pid}) || defined($self->{pid_c});
+       undef;
 }
 
 # assuming a well-maintained repo, this should be a somewhat
index 7c1c3afedf2dc281acf4e5fef9b18497b32db5cd..724df50a7134725601cd1c2ce83d9a9f41805c77 100644 (file)
@@ -13,6 +13,10 @@ use Carp qw(croak);
 # returns true if further checking is required
 sub cleanup_shards { $_[0]->{search} ? $_[0]->{search}->cleanup_shards : undef }
 
+sub check_inodes ($) {
+       for (qw(over mm)) { $_[0]->{$_}->check_inodes if $_[0]->{$_} }
+}
+
 sub do_cleanup {
        my ($ibx) = @_;
        my $live;
@@ -21,11 +25,16 @@ sub do_cleanup {
                                        : $ibx->{git}->cleanup_if_unlinked;
                delete($ibx->{git}) unless $live;
        }
+       if ($live) {
+               check_inodes($ibx);
+       } else {
+               delete(@$ibx{qw(over mm description cloneurl
+                               -imap_url -nntp_url)});
+       }
        $ibx->cleanup_shards and $live = 1;
        for my $git (@{$ibx->{-repo_objs} // []}) {
                $live = 1 if $git->cleanup(1);
        }
-       delete(@$ibx{qw(over mm description cloneurl -imap_url -nntp_url)});
        PublicInbox::DS::add_uniq_timer($ibx+0, 5, \&do_cleanup, $ibx) if $live;
 }
 
@@ -362,13 +371,6 @@ sub unsubscribe_unlock {
        delete $self->{unlock_subs}->{$ident};
 }
 
-sub check_inodes ($) {
-       my ($self) = @_;
-       for (qw(over mm)) {
-               $self->{$_}->check_inodes if $self->{$_};
-       }
-}
-
 # called by inotify
 sub on_unlock {
        my ($self) = @_;