]> Sergey Matveev's repositories - public-inbox.git/commitdiff
over: use only supported and safe SQLite APIs
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Thu, 5 Apr 2018 21:45:27 +0000 (21:45 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Fri, 6 Apr 2018 21:18:37 +0000 (21:18 +0000)
Some of this jankiness was from early performance problems
and they turned out to be unnecessary measures.

lib/PublicInbox/OverIdx.pm
lib/PublicInbox/V2Writable.pm
script/public-inbox-compact

index 0e43aabc044f61d0f16153b70f554cbc11159fc9..5c20f1f0c2170c4dae4a3417a8c77ad73ee95010 100644 (file)
@@ -14,21 +14,12 @@ use DBI qw(:sql_types); # SQL_BLOB
 sub dbh_new {
        my ($self) = @_;
        my $dbh = $self->SUPER::dbh_new;
-       $dbh->do('PRAGMA synchronous = OFF'); # commit_fsync instead
        $dbh->do('PRAGMA journal_mode = TRUNCATE');
        $dbh->do('PRAGMA cache_size = 80000');
        create_tables($dbh);
        $dbh;
 }
 
-sub commit_fsync {
-       my $fn = $_[0]->{filename};
-       if (open my $fh, '+<', $fn) {
-               $fh->sync;
-               close $fh;
-       }
-}
-
 sub get_counter ($$) {
        my ($dbh, $key) = @_;
        my $sth = $dbh->prepare_cached(<<'', undef, 1);
index b858dcc737a2e9a327f96823cfe2cbc6b1dc193e..a8117aaa15a109cd90e2513ca42703120ca30ab3 100644 (file)
@@ -397,7 +397,7 @@ sub checkpoint {
 # issue a write barrier to ensure all data is visible to other processes
 # and read-only ops.  Order of data importance is: git > SQLite > Xapian
 sub barrier {
-       my ($self, $fsync) = @_;
+       my ($self) = @_;
 
        if (my $im = $self->{im}) {
                $im->barrier;
@@ -416,7 +416,6 @@ sub barrier {
                $_->remote_barrier foreach @$parts;
 
                $over->barrier_wait; # wait for each Xapian partition
-               $over->commit_fsync if $fsync;
 
                # last_commit is special, don't commit these until
                # remote partitions are done:
index b8aaa4bd812f7a54ffe7c8ef0af8d3878205b0c4..43e94609a01ee79891cf11c25363e263492d06c5 100755 (executable)
@@ -36,15 +36,12 @@ sub commit_changes ($$$) {
        my ($im, $old, $new) = @_;
        my @st = stat($old) or die "failed to stat($old): $!\n";
 
-       for my $suf (qw(.pipe.lock -journal)) {
-               my $orig = "$old/over.sqlite3$suf";
-               link($orig, "$new/over.sqlite3$suf") and next;
-               next if $!{ENOENT};
-               die "failed to link $orig => $new/over.sqlite3$suf: $!\n";
+       my $over = "$old/over.sqlite3";
+       if (-f $over) {
+               require PublicInbox::Over;
+               $over = PublicInbox::Over->new($over);
+               $over->connect->sqlite_backup_to_file("$new/over.sqlite3");
        }
-       link("$old/over.sqlite3", "$new/over.sqlite3") or die
-               "failed to link {$old => $new}/over.sqlite3: $!\n";
-
        rename($old, "$new/old") or die "rename $old => $new/old: $!\n";
        chmod($st[2] & 07777, $new) or die "chmod $old: $!\n";
        rename($new, $old) or die "rename $new => $old: $!\n";