]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
import: fix space calculation when reusing epochs
authorEric Wong <e@80x24.org>
Tue, 17 Dec 2024 21:27:37 +0000 (21:27 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Dec 2024 21:42:27 +0000 (21:42 +0000)
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
lib/PublicInbox/V2Writable.pm

index 28eb57107be55608f4346e81536d6ca0061699ef..5b2c5587839793a7d9f61088248ca5148768df3d 100644 (file)
@@ -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;
index 194524b7196f71d4d2d9d421b80c13a2dd78e022..61c41b6053a477d6b00b1592359d45eeaa9ef52c 100644 (file)
@@ -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;