use DBD::SQLite;
use File::Temp qw(tempfile);
use PublicInbox::Over;
+use PublicInbox::Spawn;
sub new {
my ($class, $git_dir, $writable) = @_;
my $self = bless { filename => $f }, $class;
my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, $rw);
if ($rw) {
- create_tables($dbh);
-
# TRUNCATE reduces I/O compared to the default (DELETE)
$dbh->do('PRAGMA journal_mode = TRUNCATE');
$dbh->begin_work;
+ create_tables($dbh);
$self->created_at(time) unless $self->created_at;
my $max = $self->max // 0;
# used to keep track of used numeric mappings for v2 reindex
sub tmp_clone {
- my ($self) = @_;
- my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, TMPDIR => 1);
- $self->{dbh}->sqlite_backup_to_file($fn);
- my $tmp = ref($self)->new_file($fn, 1);
- $tmp->{dbh}->do('PRAGMA synchronous = OFF');
- $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+ my ($self, $dir) = @_;
+ my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, DIR => $dir);
+ PublicInbox::Spawn::set_nodatacow(fileno($fh));
+ my $tmp;
+ if ($self->{dbh}->can('sqlite_backup_to_dbh')) {
+ $tmp = ref($self)->new_file($fn, 2);
+ $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+ $self->{dbh}->sqlite_backup_to_dbh($tmp->{dbh});
+ } else { # DBD::SQLite <= 1.61_01
+ $self->{dbh}->sqlite_backup_to_file($fn);
+ $tmp = ref($self)->new_file($fn, 2);
+ $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+ }
$tmp->{pid} = $$;
- close $fh or die "failed to close $fn: $!";
$tmp;
}
sub atfork_parent {
my ($self) = @_;
- $self->{pid} or die "not a temporary clone\n";
- my $dbh = $self->{dbh} and die "tmp_clone dbh not prepared for parent";
- $self->{filename} = $dbh->sqlite_db_filename;
- $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, 1);
- $dbh->do('PRAGMA synchronous = OFF');
+ $self->{pid} or die 'BUG: not a temporary clone';
+ $self->{dbh} and die 'BUG: tmp_clone dbh not prepared for parent';
+ defined($self->{filename}) or die 'BUG: {filename} not defined';
+ $self->{dbh} = PublicInbox::Over::dbh_new($self, 2);
+ $self->{dbh}->do('PRAGMA journal_mode = MEMORY');
}
sub atfork_prepare {
my ($self) = @_;
- $self->{pid} or die "not a temporary clone\n";
- $self->{pid} == $$ or
- die "BUG: atfork_prepare not called from $self->{pid}\n";
- my $dbh = $self->{dbh} or die "temporary clone not open\n";
+ my $pid = $self->{pid} or die 'BUG: not a temporary clone';
+ $pid == $$ or die "BUG: atfork_prepare not called by $pid";
+ my $dbh = $self->{dbh} or die 'BUG: temporary clone not open';
# must clobber prepared statements
- %$self = (filename => $dbh->sqlite_db_filename, pid => $$);
+ %$self = (filename => $dbh->sqlite_db_filename, pid => $pid);
}
sub skip_artnum {