]> Sergey Matveev's repositories - public-inbox.git/commitdiff
xapcmd: -xcpdb and -compact disable CoW, too
authorEric Wong <e@yhbt.net>
Wed, 29 Jul 2020 11:20:00 +0000 (11:20 +0000)
committerEric Wong <e@yhbt.net>
Wed, 29 Jul 2020 11:35:43 +0000 (11:35 +0000)
This gives an opportunity for users already suffering from CoW
fragmentation to at least get the Xapian DBs off CoW.  Aside
from over.sqlite3 in v1, the SQLite DBs remain untouched; though
VACUUM support may come in the future.

lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/Xapcmd.pm

index aa8d8ce325cf203d1ea77abc9e89d7bb5b73091b..080aca7cb7b79cb05509ef2a1916d0f65430ff5b 100644 (file)
@@ -21,7 +21,7 @@ use PublicInbox::OverIdx;
 use PublicInbox::Spawn qw(spawn);
 use PublicInbox::Git qw(git_unquote);
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
-our @EXPORT_OK = qw(crlf_adjust log2stack is_ancestor check_size);
+our @EXPORT_OK = qw(crlf_adjust log2stack is_ancestor check_size nodatacow_dir);
 my $X = \%PublicInbox::Search::X;
 my ($DB_CREATE_OR_OPEN, $DB_OPEN);
 our $DB_NO_SYNC = 0;
@@ -110,6 +110,12 @@ sub load_xapian_writable () {
        1;
 }
 
+sub nodatacow_dir ($) {
+       my ($dir) = @_;
+       opendir my $dh, $dir or die "opendir($dir): $!\n";
+       PublicInbox::Spawn::set_nodatacow(fileno($dh));
+}
+
 sub idx_acquire {
        my ($self) = @_;
        my $flag;
@@ -128,8 +134,7 @@ sub idx_acquire {
                if (!-d $dir && (!$is_shard ||
                                ($is_shard && need_xapian($self)))) {
                        File::Path::mkpath($dir);
-                       opendir my $dh, $dir or die "opendir($dir): $!\n";
-                       PublicInbox::Spawn::set_nodatacow(fileno($dh));
+                       nodatacow_dir($dir);
                }
        }
        return unless defined $flag;
index 3b7a581bd5c872463447c86dd81113ddd5f5db04..f1c80831d91803021ad275157f1220d66c26d248 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use PublicInbox::Spawn qw(which popen_rd);
 use PublicInbox::Over;
-use PublicInbox::SearchIdx;
+use PublicInbox::SearchIdx qw(nodatacow_dir);
 use File::Temp 0.19 (); # ->newdir
 use File::Path qw(remove_tree);
 use File::Basename qw(dirname);
@@ -187,6 +187,7 @@ sub prepare_run {
                my $v = PublicInbox::Search::SCHEMA_VERSION();
                my $wip = File::Temp->newdir("xapian$v-XXXXXXXX", DIR => $dir);
                $tmp->{$old} = $wip;
+               nodatacow_dir($wip->dirname);
                push @queue, [ $old, $wip ];
        } else {
                opendir my $dh, $old or die "Failed to opendir $old: $!\n";
@@ -217,6 +218,7 @@ sub prepare_run {
                        same_fs_or_die($old, $wip->dirname);
                        my $cur = "$old/$dn";
                        push @queue, [ $src // $cur , $wip ];
+                       nodatacow_dir($wip->dirname);
                        $tmp->{$cur} = $wip;
                }
                # mark old shards to be unlinked
@@ -406,6 +408,7 @@ sub cpdb ($$) {
                $ft = File::Temp->newdir("$new.compact-XXXXXX", DIR => $dir);
                setup_signals();
                $tmp = $ft->dirname;
+               nodatacow_dir($tmp);
        } else {
                $tmp = $new;
        }