]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
searchidxpart: s/barrier/remote_barrier/
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index bdde76bbbf54702007d5f27a8c0e05777d67d06c..261f9d91a0c7e7849eb21d22b6d48c6ffaf5b4ed 100644 (file)
@@ -5,7 +5,7 @@
 package PublicInbox::V2Writable;
 use strict;
 use warnings;
-use Fcntl qw(:flock :DEFAULT);
+use base qw(PublicInbox::Lock);
 use PublicInbox::SearchIdxPart;
 use PublicInbox::SearchIdxSkeleton;
 use PublicInbox::MIME;
@@ -26,13 +26,10 @@ sub nproc () {
 sub new {
        my ($class, $v2ibx, $creat) = @_;
        my $dir = $v2ibx->{mainrepo} or die "no mainrepo in inbox\n";
-       my $lock_path = "$dir/inbox.lock";
        unless (-d $dir) {
                if ($creat) {
                        require File::Path;
                        File::Path::mkpath($dir);
-                       open my $fh, '>>', $lock_path or
-                               die "failed to open $lock_path: $!\n";
                } else {
                        die "$dir does not exist\n";
                }
@@ -64,7 +61,7 @@ sub new {
                # limit each repo to 1GB or so
                rotate_bytes => int((1024 * 1024 * 1024) / $PACKING_FACTOR),
        };
-       bless $self, $class
+       bless $self, $class;
 }
 
 # returns undef on duplicate or spam
@@ -188,6 +185,8 @@ sub idx_init {
        # frequently activated.
        delete $ibx->{$_} foreach (qw(git mm search));
 
+       $self->lock_acquire;
+
        # first time initialization, first we create the skeleton pipe:
        my $skel = $self->{skel} = PublicInbox::SearchIdxSkeleton->new($self);
 
@@ -250,9 +249,11 @@ sub remove {
 
 sub done {
        my ($self) = @_;
+       my $locked = defined $self->{idx_parts};
        my $im = delete $self->{im};
        $im->done if $im; # PublicInbox::Import::done
        $self->searchidx_checkpoint(0);
+       $self->lock_release if $locked;
 }
 
 sub checkpoint {
@@ -279,7 +280,7 @@ sub barrier {
                # Now deal with Xapian
                $skel->barrier_init(scalar(@$parts));
                # each partition needs to issue a barrier command to skel:
-               $_->barrier foreach @$parts;
+               $_->remote_barrier foreach @$parts;
 
                $skel->barrier_wait; # wait for each Xapian partition
 
@@ -399,7 +400,7 @@ sub import_init {
        my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
        $im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
        $im->{want_object_info} = 1;
-       $im->{lock_path} = $self->{lock_path};
+       $im->{lock_path} = undef;
        $im->{path_type} = 'v2';
        $self->{im} = $im;
 }