$l !~ $PublicInbox::SearchIdx::INDEXLEVELS and
die "invalid indexlevel=$l\n";
$self->{indexlevel} = $l;
- my $oidx = PublicInbox::OverIdx->new($over_file);
- $oidx->{journal_mode} = 'wal' if $opt->{wal};
- $self->{-no_fsync} = $oidx->{-no_fsync} = 1 if !$opt->{fsync};
+ $self->{oidx} = PublicInbox::OverIdx->new($over_file, $opt);
+ $self->{-no_fsync} = 1 if !$opt->{fsync};
$self->{-dangerous} = 1 if $opt->{dangerous};
- $self->{oidx} = $oidx;
$self
}
require PublicInbox::SearchIdx;
require PublicInbox::Msgmap;
my $sidx = PublicInbox::SearchIdx->new($self, $opt);
- $sidx->{oidx}->{journal_mode} = 'wal' if $opt->{wal};
$sidx->begin_txn_lazy;
my $mm = PublicInbox::Msgmap->new_file($self, $opt);
if (defined $skip_artnum) {
$self->{oidx} // do {
my $creat = !-f $self->{-ovf};
my $lk = $self->lock_for_scope; # git-config doesn't wait
- my $oidx = PublicInbox::OverIdx->new($self->{-ovf});
- $oidx->{-no_fsync} = 1;
- $oidx->{journal_mode} = 'WAL';
+ my $oidx = PublicInbox::OverIdx->new($self->{-ovf},
+ { wal => 1 });
$oidx->dbh;
$oidx->eidx_prep if $creat; # for xref3
$self->{oidx} = $oidx
sub new {
my (undef, $dir, $opt) = @_;
+ $opt->{wal} = 1;
my $eidx = PublicInbox::ExtSearchIdx->new($dir, $opt);
my $self = bless { priv_eidx => $eidx }, __PACKAGE__;
eidx_init($self)->done if $opt->{creat};
return if !$rw && !-r $f;
my $self = bless { filename => $f }, $class;
- $self->{journal_mode} = 'wal' if $opt->{wal};
+ $self->{-opt} = $opt if $opt; # for WAL
my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, $rw);
if ($rw) {
$dbh->begin_work;
sub dbh_new {
my ($self, $rw) = @_;
my $f = delete $self->{filename};
+ my $opt = $self->{-opt};
if (!-s $f) {
if ($rw) {
PublicInbox::SQLiteUtil::create_db $f;
# If an admin is willing to give read-only daemons R/W
# permissions; they can enable WAL manually and we will
# respect that by not clobbering it.
- my $jm = $self->{journal_mode}; # set by lei
- if (defined $jm) {
- $dbh->do('PRAGMA journal_mode = '.$jm);
+ if ($opt->{wal}) {
+ $dbh->do('PRAGMA journal_mode = wal');
} else {
- $jm = $dbh->selectrow_array('PRAGMA journal_mode');
+ my $jm = $dbh->selectrow_array('PRAGMA journal_mode');
$jm eq 'wal' or
$dbh->do('PRAGMA journal_mode = TRUNCATE');
}
-
- $dbh->do('PRAGMA synchronous = OFF') if $rw > 1;
+ $opt->{fsync} or $dbh->do('PRAGMA synchronous = OFF')
}
$dbh;
}
sub dbh_new {
my ($self) = @_;
- my $dbh = $self->SUPER::dbh_new($self->{-no_fsync} ? 2 : 1);
+ my $dbh = $self->SUPER::dbh_new(1);
# 80000 pages (80MiB on SQLite <3.12.0, 320MiB on 3.12.0+)
# was found to be good in 2018 during the large LKML import
}
sub new {
- my ($class, $f) = @_;
+ my ($class, $f, $opt) = @_;
my $self = $class->SUPER::new($f);
+ $self->{-opt} = $opt;
$self->{min_tid} = 0;
$self;
}
my ($dir) = ($fn =~ m!(.*?/)[^/]+\z!);
File::Path::mkpath($dir);
}
- $self->{journal_mode} = 'wal' if $opt->{wal};
# create the DB:
PublicInbox::Over::dbh($self);
$self->dbh_close;
}
if ($version == 1) {
$self->{lock_path} = "$inboxdir/ssoma.lock";
- my $dir = $self->xdir;
- $self->{oidx} = PublicInbox::OverIdx->new("$dir/over.sqlite3");
- $self->{oidx}->{-no_fsync} = 1 if $ibx->{-no_fsync};
+ $self->{oidx} = PublicInbox::OverIdx->new(
+ $self->xdir.'/over.sqlite3', $creat_opt);
} elsif ($version == 2) {
defined $shard or die "shard is required for v2\n";
# shard is a number
local $SIG{QUIT} = $quit;
local $SIG{INT} = $quit;
local $SIG{TERM} = $quit;
- $self->{oidx}->{journal_mode} = 'wal' if $opt->{wal};
my $xdb = $self->begin_txn_lazy;
$self->{oidx}->rethread_prepare($opt);
my $mm = v1_mm_init $self;
total_bytes => 0,
current_info => '',
xpfx => $xpfx,
- oidx => PublicInbox::OverIdx->new("$xpfx/over.sqlite3"),
+ oidx => PublicInbox::OverIdx->new("$xpfx/over.sqlite3",
+ $creat_opt),
lock_path => "$dir/inbox.lock",
# limit each git repo (epoch) to 1GB or so
rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
my $mods = {};
my @eidx_unconfigured;
foreach my $ibx (@ibxs) {
- $ibx = PublicInbox::InboxWritable->new($ibx);
+ $ibx = PublicInbox::InboxWritable->new($ibx, $opt);
# detect_indexlevel may also set $ibx->{-skip_docdata}
my $detected = $ibx->detect_indexlevel;
# XXX: users can shoot themselves in the foot, with opt->{indexlevel}
$over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
ok($over->dbh->{ReadOnly}, 'Over is ReadOnly');
+my $jm = $over->dbh->selectrow_array('PRAGMA journal_mode');
+isnt $jm, 'wal', 'journal_mode is not WAL by default';
-$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
+$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3", { wal => 1 });
$over->dbh;
+$jm = $over->dbh->selectrow_array('PRAGMA journal_mode');
+is $jm, 'wal', "`wal' option respected";
is($over->sid('hello-world'), $x, 'idempotent across reopen');
$over->each_by_mid('never', sub { fail('should not be called') });