We need to detect the number of partitions the repository was
created with to ensure Xapian DBs can work across different
machines (or even CPU affinity changes) without leaving messages
unaffected by search.
my $PACKING_FACTOR = 0.4;
# assume 2 cores if GNU nproc(1) is not available
my $PACKING_FACTOR = 0.4;
# assume 2 cores if GNU nproc(1) is not available
-my $NPROC = int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
+sub nproc () {
+ int($ENV{NPROC} || `nproc 2>/dev/null` || 2);
+}
sub new {
my ($class, $v2ibx, $creat) = @_;
sub new {
my ($class, $v2ibx, $creat) = @_;
die "$dir does not exist\n";
}
}
die "$dir does not exist\n";
}
}
+
+ my $nparts = 0;
+ my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
+
+ # always load existing partitions in case core count changes:
+ if (-d $xpfx) {
+ foreach my $part (<$xpfx/*>) {
+ -d $part && $part =~ m!/\d+\z! or next;
+ eval {
+ Search::Xapian::Database->new($part)->close;
+ $nparts++;
+ };
+ }
+ }
+ $nparts = nproc() if ($nparts == 0);
+
my $self = {
-inbox => $v2ibx,
im => undef, # PublicInbox::Import
xap_rw => undef, # PublicInbox::V2SearchIdx
xap_ro => undef,
my $self = {
-inbox => $v2ibx,
im => undef, # PublicInbox::Import
xap_rw => undef, # PublicInbox::V2SearchIdx
xap_ro => undef,
transact_bytes => 0,
# limit each repo to 1GB or so
rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
transact_bytes => 0,
# limit each repo to 1GB or so
rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
body => "hello world\n",
);
body => "hello world\n",
);
-my $im = PublicInbox::V2Writable->new($ibx, 1);
+my $im = eval {
+ local $ENV{NPROC} = '1';
+ PublicInbox::V2Writable->new($ibx, 1);
+};
+is($im->{partitions}, 1, 'one partition when forced');
ok($im->add($mime), 'ordinary message added');
if ('ensure git configs are correct') {
ok($im->add($mime), 'ordinary message added');
if ('ensure git configs are correct') {
}
is_deeply([sort keys %nn], [sort keys %uniq]);
};
}
is_deeply([sort keys %nn], [sort keys %uniq]);
};
+{
+ local $ENV{NPROC} = 2;
+ $im = PublicInbox::V2Writable->new($ibx, 1);
+ is($im->{partitions}, 1, 'detected single partition from previous');
+}