From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20241217212737.1255809-3-e@80x24.org> (raw)
In-Reply-To: <20241217212737.1255809-1-e@80x24.org>
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;
prev parent reply other threads:[~2024-12-17 21:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 21:27 [PATCH 0/2] v2: epoch reuse space calculation fix Eric Wong
2024-12-17 21:27 ` [PATCH 1/2] v2writable: simplify epoch directory generation Eric Wong
2024-12-17 21:27 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241217212737.1255809-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).