my ($self) = @_;
$self->{mm_alt} ||= eval {
require PublicInbox::Msgmap;
- PublicInbox::Msgmap->new_file(@$self{qw(filename writable)});
+ # TODO: expose a way to disable fsync + enable WAL
+ my $opt = $self->{writable} ? { fsync => 1 } : undef;
+ PublicInbox::Msgmap->new_file($self->{filename}, $opt);
};
}
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, 1, $opt);
+ my $mm = PublicInbox::Msgmap->new_file($self, $opt);
if (defined $skip_artnum) {
$mm->{dbh}->begin_work;
$mm->skip_artnum($skip_artnum);
use Scalar::Util qw(blessed);
sub new_file {
- my ($class, $ibx, $rw, $opt) = @_;
+ my ($class, $ibx, $opt) = @_;
my $f;
+ my $rw = !!$opt;
if (blessed($ibx)) {
$f = $ibx->mm_file;
$rw = 2 if $rw && $ibx->{-no_fsync};
require PublicInbox::Syscall;
PublicInbox::Syscall::nodatacow_fh($fh);
$self->{dbh}->sqlite_backup_to_file($fn);
- $tmp = ref($self)->new_file($fn, 2);
+ $tmp = ref($self)->new_file($fn, {});
$tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
$tmp->{pid} = $$;
$tmp;
} else {
die "unsupported inbox version=$version\n";
}
- $self->{creat} = !!$creat_opt;
+ $self->{creat} = !!$creat_opt; # TODO: eliminate
+ $self->{-opt} = $creat_opt;
$self;
}
die "BUG: v1_mm_init is only for v1\n" if $self->{ibx}->version != 1;
$self->{mm} //= do {
require PublicInbox::Msgmap;
- PublicInbox::Msgmap->new_file($self->{ibx}, 1, $self->{-opt});
+ PublicInbox::Msgmap->new_file($self->{ibx}, $self->{-opt});
};
}
# Now that all subprocesses are up, we can open the FDs
# for SQLite:
- my $mm = $self->{mm} = PublicInbox::Msgmap->new_file($ibx, 1, $opt);
+ my $mm = $self->{mm} = PublicInbox::Msgmap->new_file($ibx, $opt);
$mm->{dbh}->begin_work;
}
#!/usr/bin/perl -w
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Useful for mapping article IDs from existing NNTP servers to MIDs
use strict;
if ($msgmap) {
require PublicInbox::Msgmap;
require PublicInbox::MID; # mid_clean
- $mm = PublicInbox::Msgmap->new_file($msgmap, 1);
+ $mm = PublicInbox::Msgmap->new_file($msgmap, {});
}
my $group = shift or die $usage;
my $ibx;
{
- my $mm = PublicInbox::Msgmap->new_file($alt_file, 2);
+ my $mm = PublicInbox::Msgmap->new_file($alt_file, { wal => 1 });
is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
};
{
- my $mm = PublicInbox::Msgmap->new_file($alt_file, 2);
+ my $mm = PublicInbox::Msgmap->new_file($alt_file, { wal => 1 });
my ($min, $max) = $mm->minmax;
my $num = $mm->mid_insert('b@example.com');
ok($num > $max, 'auto-increment goes beyond mid_set');
my $ibx = create_inbox 'v2', version => 2, indexlevel => 'medium',
altid => $altid, sub {
my ($im, $ibx) = @_;
- my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 2);
+ my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another",
+ { wal => 1 });
is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set') or xbail 'once';
is($mm->mid_set(1234, 'a@example.com')+0, 0, 'mid_set not idempotent');
is($mm->mid_set(1, 'a@example.com')+0, 0, 'mid_set fails with dup MID');
hello world gmane:666
EOF
};
-my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 2);
+my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another",
+ { wal => 1 });
is($mm->mid_set(1234, 'a@example.com') + 0, 0, 'mid_set not idempotent');
is($mm->mid_set(1, 'a@example.com') + 0, 0, 'mid_set fails with dup MID');
my $mset = $ibx->search->mset('gmane:1234');
altid => $altid, sub {
my ($im, $ibx) = @_;
my $mm = PublicInbox::Msgmap->new_file(
- "$ibx->{inboxdir}/$another", 2);
+ "$ibx->{inboxdir}/$another",
+ { wal => 1 });
$mm->mid_set(1234, 'a@example.com') == 1 or xbail 'mid_set';
$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
From: a@example.com
use_ok 'PublicInbox::Msgmap';
my ($tmpdir, $for_destroy) = tmpdir();
my $f = "$tmpdir/msgmap.sqlite3";
-my $d = PublicInbox::Msgmap->new_file($f, 1);
+my $d = PublicInbox::Msgmap->new_file($f, { wal => 1 });
+is $d->{dbh}->selectrow_array('PRAGMA journal_mode'), 'wal',
+ 'wal in options hashref respected';
my %mid2num;
my %num2mid;
is(undef, $d->num_for('a@b'), 'num_for fails on deleted msg');
$d = undef;
-ok($d = PublicInbox::Msgmap->new_file($f, 1), 'idempotent DB creation');
+ok($d = PublicInbox::Msgmap->new_file($f, {}), 'idempotent DB creation');
my ($min, $max) = $d->minmax;
ok($min > 0, "article min OK");
ok($max > 0 && $max < 10, "article max OK");