summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6d6c6d2)
For sharded v2 repositories with few-enough messages, it is
possible for shard[0] to go unused and never trigger the
->commit_txn_lazy to set the indexlevel field in Xapian
metadata.
So set it immediately at initialization and avoid this case.
While we're at it, avoid triggering needless pwrite syscalls
from ->set_metadata by checking with ->get_metadata, first.
ibx_ver => $version,
indexlevel => $indexlevel,
}, $class;
ibx_ver => $version,
indexlevel => $indexlevel,
}, $class;
+ $self->{-set_indexlevel_once} = 1 if $indexlevel eq 'medium';
$ibx->umask_prepare;
if ($version == 1) {
$self->{lock_path} = "$inboxdir/ssoma.lock";
$ibx->umask_prepare;
if ($version == 1) {
$self->{lock_path} = "$inboxdir/ssoma.lock";
+# store 'indexlevel=medium' in v2 shard=0 and v1 (only one shard)
+# This metadata is read by Admin::detect_indexlevel:
+sub set_indexlevel {
+ my ($self) = @_;
+
+ if (!$self->{shard} && # undef or 0, not >0
+ delete($self->{-set_indexlevel_once})) {
+ my $xdb = $self->{xdb};
+ my $level = $xdb->get_metadata('indexlevel');
+ if (!$level || $level ne 'medium') {
+ $xdb->set_metadata('indexlevel', 'medium');
+ }
+ }
+}
+
sub commit_txn_lazy {
my ($self) = @_;
delete $self->{txn} or return;
$self->{-inbox}->with_umask(sub {
if (my $xdb = $self->{xdb}) {
sub commit_txn_lazy {
my ($self) = @_;
delete $self->{txn} or return;
$self->{-inbox}->with_umask(sub {
if (my $xdb = $self->{xdb}) {
-
- # store 'indexlevel=medium' in v2 shard=0 and
- # v1 (only one shard)
- # This metadata is read by Admin::detect_indexlevel:
- if (!$self->{shard} # undef or 0, not >0
- && $self->{indexlevel} eq 'medium') {
- $xdb->set_metadata('indexlevel', 'medium');
- }
-
$xdb->commit_transaction;
}
$self->{over}->commit_lazy if $self->{over};
$xdb->commit_transaction;
}
$self->{over}->commit_lazy if $self->{over};
sub new {
my ($class, $v2writable, $shard) = @_;
sub new {
my ($class, $v2writable, $shard) = @_;
- my $self = $class->SUPER::new($v2writable->{-inbox}, 1, $shard);
+ my $ibx = $v2writable->{-inbox};
+ my $self = $class->SUPER::new($ibx, 1, $shard);
# create the DB before forking:
$self->_xdb_acquire;
# create the DB before forking:
$self->_xdb_acquire;
$self->_xdb_release;
$self->spawn_worker($v2writable, $shard) if $v2writable->{parallel};
$self;
$self->_xdb_release;
$self->spawn_worker($v2writable, $shard) if $v2writable->{parallel};
$self;
use Test::More;
use PublicInbox::Config;
use PublicInbox::TestCommon;
use Test::More;
use PublicInbox::Config;
use PublicInbox::TestCommon;
use File::Basename;
my ($tmpdir, $for_destroy) = tmpdir();
sub quiet_fail {
use File::Basename;
my ($tmpdir, $for_destroy) = tmpdir();
sub quiet_fail {
quiet_fail($cmd, 'initializing V2 as V1 fails');
foreach my $lvl (qw(medium basic)) {
quiet_fail($cmd, 'initializing V2 as V1 fails');
foreach my $lvl (qw(medium basic)) {
+ my $dir = "$tmpdir/v2$lvl";
$cmd = [ '-init', "v2$lvl", '-V2', '-L', $lvl,
$cmd = [ '-init', "v2$lvl", '-V2', '-L', $lvl,
- "$tmpdir/v2$lvl", "http://example.com/v2$lvl",
+ $dir, "http://example.com/v2$lvl",
"v2$lvl\@example.com" ];
ok(run_script($cmd), "-init -L $lvl");
is(read_indexlevel("v2$lvl"), $lvl, "indexlevel set to '$lvl'");
"v2$lvl\@example.com" ];
ok(run_script($cmd), "-init -L $lvl");
is(read_indexlevel("v2$lvl"), $lvl, "indexlevel set to '$lvl'");
+ my $ibx = PublicInbox::Inbox->new({ inboxdir => $dir });
+ is(PublicInbox::Admin::detect_indexlevel($ibx), $lvl,
+ 'detected expected level w/o config');