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;
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";
}
# 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
# 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);
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 {
# 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
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;
}