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 1E5EE1F4D3 for ; Tue, 17 Dec 2024 21:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1734470858; bh=jjrnUAW1B7Q6pIWjY/tqCn9IxvoU3gxhE6e9cKDkN6g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=atq9K7M04Skl1zCTFojCXLg5A2/4ZEyOV3ANY6Gv8UxwzR0nHrL+9PRdpPQE9Lksf BhIouRi03Sj6gkmLUM+LTNWcMVRhVZGllHxNoXKROe/FAUexo5+4zl+zaDXv+foWEF T/gVKMfamBcyZBRImenU+fMBz+CC8khIgnSj49S8= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/2] import: fix space calculation when reusing epochs Date: Tue, 17 Dec 2024 21:27:37 +0000 Message-ID: <20241217212737.1255809-3-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: Dividing the result of $git->packed_bytes by $PACKING_FACTOR _twice_ was completely wrong for v2. Just calculate $unpacked_bytes once and use it for the Import->{bytes_added} field. The calculation for lei/store was actually correct, just redundant since repeated division is unnecessary. --- lib/PublicInbox/LeiStore.pm | 5 ++--- lib/PublicInbox/V2Writable.pm | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 28eb5710..5b2c5587 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -94,15 +94,14 @@ sub importer { $self->done; # unlock # re-acquire lock, update alternates for new epoch (undef, $tl) = eidx_init($self); - my $packed_bytes = $git->packed_bytes; - my $unpacked_bytes = $packed_bytes / $self->packing_factor; + my $unpacked_bytes = int($git->packed_bytes / $self->packing_factor); if ($unpacked_bytes >= $self->rotate_bytes) { $max++; next; } my ($n, $e) = git_ident($git); $self->{im} = $im = PublicInbox::Import->new($git, $n, $e); - $im->{bytes_added} = int($packed_bytes / $self->packing_factor); + $im->{bytes_added} = $unpacked_bytes; $im->{lock_path} = undef; $im->{path_type} = 'v2'; return $im; diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 194524b7..61c41b60 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -634,12 +634,11 @@ sub importer { 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; + my $unpacked_bytes = int($git->packed_bytes / $PACKING_FACTOR); if ($unpacked_bytes < $self->{rotate_bytes}) { # ok, space left $self->{epoch_max} = $epoch; - return $self->import_init($git, $packed_bytes); + return $self->import_init($git, $unpacked_bytes); } ++$epoch; # too big, start a new epoch on fall through } @@ -649,9 +648,9 @@ sub importer { } sub import_init { - my ($self, $git, $packed_bytes, $tmp) = @_; + my ($self, $git, $unpacked_bytes, $tmp) = @_; my $im = PublicInbox::Import->new($git, undef, undef, $self->{ibx}); - $im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR); + $im->{bytes_added} = $unpacked_bytes; $im->{lock_path} = undef; $im->{path_type} = 'v2'; $self->{im} = $im unless $tmp;