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;
xap_ro => undef,
partitions => $nparts,
transact_bytes => 0,
+ lock_path => "$dir/inbox.lock",
# 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
my $hdr = $mime->header_obj;
my $dig = content_digest($mime);
- $$mid0 = $dig->clone->hexdigest . '@localhost';
+ $$mid0 = PublicInbox::Import::digest2mid($dig);
my $num = $self->{skel}->{mm}->mid_insert($$mid0);
unless (defined $num) {
# it's hard to spoof the last Received: header
my @recvd = $hdr->header_raw('Received');
$dig->add("Received: $_") foreach (@recvd);
- $$mid0 = $dig->clone->hexdigest . '@localhost';
+ $$mid0 = PublicInbox::Import::digest2mid($dig);
$num = $self->{skel}->{mm}->mid_insert($$mid0);
# fall back to a random Message-ID and give up determinism:
until (defined($num)) {
$dig->add(rand);
- $$mid0 = $dig->clone->hexdigest . '@localhost';
+ $$mid0 = PublicInbox::Import::digest2mid($dig);
warn "using random Message-ID <$$mid0> as fallback\n";
$num = $self->{skel}->{mm}->mid_insert($$mid0);
}
# 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 {
sub barrier {
my ($self) = @_;
- # For safety, we ensure git checkpoint is complete before because
- # the data in git is still more important than what is in Xapian.
- # Performance may be gained by delaying ->progress call but we
- # lose safety
if (my $im = $self->{im}) {
- $im->checkpoint;
- $im->progress('checkpoint');
+ $im->barrier;
}
my $skel = $self->{skel};
my $parts = $self->{idx_parts};
my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
$im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
$im->{want_object_info} = 1;
- $im->{ssoma_lock} = 0;
+ $im->{lock_path} = undef;
$im->{path_type} = 'v2';
$self->{im} = $im;
}