From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A068A1F5AE; Wed, 29 Jul 2020 11:20:00 +0000 (UTC) Date: Wed, 29 Jul 2020 11:20:00 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/1] xapcmd: -xcpdb and -compact disable CoW, too Message-ID: <20200729112000.GA25039@dcvr> References: <20200728222158.17457-1-e@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200728222158.17457-1-e@yhbt.net> List-Id: 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 | 11 ++++++++--- lib/PublicInbox/Xapcmd.pm | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index aa8d8ce3..080aca7c 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -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; diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 3b7a581b..f1c80831 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -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; }