From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DE9121F4D0 for ; Tue, 17 Dec 2024 21:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1734470857; bh=fk8T551YFT7SjP7PmtcWiUtJYGUL634W/A0rl61k9SE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U9lOSKZq4eiGicogR085qKkpgnCKtKPj9e6d2DfxCJAldQywT38mgZEIwDFKmqIg9 OeRB2I0jz7dmBfth9t9kMaKr5IDFAbze2ufKOvd6GrS2MTgSCrVzAo2wPisuF9WMRv MlaPrnIeJOIKYa2CfBUIclhgacm3koBzTonzFe4A= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] v2writable: simplify epoch directory generation Date: Tue, 17 Dec 2024 21:27:36 +0000 Message-ID: <20241217212737.1255809-2-e@80x24.org> In-Reply-To: <20241217212737.1255809-1-e@80x24.org> References: <20241217212737.1255809-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: As noted in a now-removed comment, InboxWritable->git_dir_latest seems redundant and an unnecessary function. Instead, we can use MultiGit->epoch_dir for these v2-only (non-extindex) codepaths. --- lib/PublicInbox/InboxWritable.pm | 7 ------- lib/PublicInbox/V2Writable.pm | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index 8e95cb28..b995a8ad 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -172,13 +172,6 @@ sub cleanup ($) { delete @{$_[0]}{qw(over mm git search)}; } -# v2+ only, XXX: maybe we can just rely on ->max_git_epoch and remove -sub git_dir_latest { - my ($self, $max) = @_; - defined($$max = $self->max_git_epoch) ? - "$self->{inboxdir}/git/$$max.git" : undef; -} - # for unconfigured inboxes sub detect_indexlevel ($) { my ($ibx) = @_; diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 15945b35..194524b7 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -630,22 +630,20 @@ sub importer { return $self->import_init($git, 0); } } - my $epoch = 0; - my $max; - my $latest = $self->{ibx}->git_dir_latest(\$max); - if (defined $latest) { - my $git = PublicInbox::Git->new($latest); + my $epoch = $self->{ibx}->max_git_epoch; + if (defined $epoch) { # use existing if not too big + my $git = PublicInbox::Git->new( + $self->{mg}->epoch_dir."/$epoch.git"); my $packed_bytes = $git->packed_bytes; my $unpacked_bytes = $packed_bytes / $PACKING_FACTOR; - if ($unpacked_bytes >= $self->{rotate_bytes}) { - $epoch = $max + 1; - } else { - $self->{epoch_max} = $max; + if ($unpacked_bytes < $self->{rotate_bytes}) { # ok, space left + $self->{epoch_max} = $epoch; return $self->import_init($git, $packed_bytes); } + ++$epoch; # too big, start a new epoch on fall through } - $self->{epoch_max} = $epoch; + $self->{epoch_max} = $epoch //= 0; my $dir = $self->{mg}->add_epoch($epoch); $self->import_init(PublicInbox::Git->new($dir), 0); } @@ -1211,8 +1209,8 @@ sub index_sync { local $self->{need_checkpoint} = 0; return xapian_only($self, $opt) if $opt->{xapian_only}; - my $epoch_max; - my $latest = $self->{ibx}->git_dir_latest(\$epoch_max) // return; + my $epoch_max = $self->{ibx}->max_git_epoch // return; + my $latest = $self->{mg}->epoch_dir."/$epoch_max.git"; if ($opt->{'fast-noop'}) { # nanosecond (st_ctim) comparison use Time::HiRes qw(stat); if (my @mm = stat("$self->{ibx}->{inboxdir}/msgmap.sqlite3")) {