use parent qw(PublicInbox::ExtSearch PublicInbox::Lock);
use Carp qw(croak carp);
use PublicInbox::Search;
-use PublicInbox::SearchIdx qw(crlf_adjust);
+use PublicInbox::SearchIdx qw(crlf_adjust prepare_stack);
use PublicInbox::OverIdx;
+use PublicInbox::MID qw(mids);
use PublicInbox::V2Writable;
use PublicInbox::InboxWritable;
+use PublicInbox::ContentHash qw(content_hash);
use PublicInbox::Eml;
use File::Spec;
sub new {
- my (undef, $dir, $opt, $shard) = @_;
+ my (undef, $dir, $opt) = @_;
my $l = $opt->{indexlevel} // 'full';
$l !~ $PublicInbox::SearchIdx::INDEXLEVELS and
die "invalid indexlevel=$l\n";
sub attach_inbox {
my ($self, $ibx) = @_;
+ $ibx = PublicInbox::InboxWritable->new($ibx);
my $key = $ibx->eidx_key;
if (!$ibx->over || !$ibx->mm) {
warn "W: skipping $key (unindexed)\n";
sub do_xpost ($$) {
my ($req, $smsg) = @_;
- my $self = $req->{eidx};
+ my $self = $req->{self};
my $docid = $smsg->{num};
my $idx = $self->idx_shard($docid);
my $oid = $req->{oid};
- my $xibx = $self->{sync}->{ibx};
+ my $xibx = $req->{ibx};
my $eml = $req->{eml};
if (my $new_smsg = $req->{new_smsg}) { # 'm' on cross-posted message
my $xnum = $req->{xnum};
- $idx->shard_add_xref3($docid, $xnum, $oid, $xibx, $eml);
+ $self->{oidx}->add_xref3($docid, $xnum, $oid, $xibx->eidx_key);
+ $idx->shard_add_eidx_info($docid, $oid, $xibx, $eml);
} else { # 'd'
- $idx->shard_remove_xref3($docid, $oid, $xibx, $eml);
+ $idx->shard_remove_eidx_info($docid, $oid, $xibx, $eml);
}
}
+# called by V2Writable::sync_prepare
+sub artnum_max { $_[0]->{oidx}->eidx_max }
+
sub index_unseen ($) {
my ($req) = @_;
my $new_smsg = $req->{new_smsg} or die 'BUG: {new_smsg} unset';
- $new_smsg->populate($req->{eml}, $req);
- my $self = $req->{eidx};
+ my $eml = delete $req->{eml};
+ $new_smsg->populate($eml, $req);
+ my $self = $req->{self};
my $docid = $self->{oidx}->adj_counter('eidx_docid', '+');
$new_smsg->{num} = $docid;
my $idx = $self->idx_shard($docid);
- my $eml = delete $req->{eml};
$self->{oidx}->add_overview($eml, $new_smsg);
- $idx->index_raw(undef, $eml, $new_smsg, delete $new_smsg->{ibx});
+ my $oid = $new_smsg->{blob};
+ my $ibx = delete $req->{ibx} or die 'BUG: {ibx} unset';
+ $self->{oidx}->add_xref3($docid, $req->{xnum}, $oid, $ibx->eidx_key);
+ $idx->index_raw(undef, $eml, $new_smsg, $ibx);
}
sub do_finalize ($) {
sub do_step ($) { # main iterator for adding messages to the index
my ($req) = @_;
- my $self = $req->{eidx};
+ my $self = $req->{self};
while (1) {
if (my $next_arg = $req->{next_arg}) {
if (my $smsg = $self->{oidx}->next_by_mid(@$next_arg)) {
my $smsg = $req->{cur_smsg} or die 'BUG: {cur_smsg} missing';
return if is_bad_blob($oid, $type, $size, $smsg->{blob});
my $cur = PublicInbox::Eml->new($bref);
- if (content_digest($cur) eq $req->{chash}) {
+ if (content_hash($cur) eq $req->{chash}) {
push @{$req->{indexed}}, $smsg; # for do_xpost
} # else { index_unseen later }
do_step($req);
# return the number if so
sub cur_ibx_xnum ($$) {
my ($req, $bref) = @_;
- my $ibx = $req->{sync}->{ibx} or die 'BUG: current {ibx} missing';
+ my $ibx = $req->{ibx} or die 'BUG: current {ibx} missing';
# XXX overkill?
git_blob_digest($bref)->hexdigest eq $req->{oid} or die
undef;
}
-sub m_start { # git->cat_async callback for 'm'
+sub index_oid { # git->cat_async callback for 'm'
my ($bref, $oid, $type, $size, $req) = @_;
return if is_bad_blob($oid, $type, $size, $req->{oid});
my $new_smsg = $req->{new_smsg} = bless {
blob => $oid,
- raw_bytes => $size,
}, 'PublicInbox::Smsg';
- $new_smsg->{bytes} = $new_smsg->{raw_bytes} + crlf_adjust($$bref);
+ $new_smsg->{bytes} = $size + crlf_adjust($$bref);
defined($req->{xnum} = cur_ibx_xnum($req, $bref)) or return;
- $new_smsg->{ibx} = $req->{sync}->{ibx};
do_step($req);
}
-sub d_start { # git->cat_async callback for 'd'
+sub unindex_oid { # git->cat_async callback for 'd'
my ($bref, $oid, $type, $size, $req) = @_;
return if is_bad_blob($oid, $type, $size, $req->{oid});
return if defined(cur_ibx_xnum($req, $bref)); # was re-added
do_step($req);
}
-sub eidx_last_epoch_commit ($$$) {
- my ($self, $sync, $epoch) = @_;
- my $key = $sync->{ibx}->eidx_key;
- my $uidvalidity = $sync->{ibx}->uidvalidity;
- $self->{oidx}->eidx_meta("lc-v2:$key//$uidvalidity;$epoch");
+# overrides V2Writable::last_commits, called by sync_ranges via sync_prepare
+sub last_commits {
+ my ($self, $sync) = @_;
+ my $heads = [];
+ my $ekey = $sync->{ibx}->eidx_key;
+ my $uv = $sync->{ibx}->uidvalidity;
+ for my $i (0..$sync->{epoch_max}) {
+ $heads->[$i] = $self->{oidx}->eidx_meta("lc-v2:$ekey//$uv;$i");
+ }
+ $heads;
}
sub _sync_inbox ($$$) {
my ($self, $opt, $ibx) = @_;
my $sync = {
need_checkpoint => \(my $bool = 0),
- unindex_range => {}, # EPOCH => oid_old..oid_new
reindex => $opt->{reindex},
-opt => $opt,
- eidx => $self,
+ self => $self,
ibx => $ibx,
};
- my $key = $ibx->eidx_key;
- my $u = $ibx->uidvalidity;
- my $oidx = $self->{oidx};
my $v = $ibx->version;
+ my $ekey = $ibx->eidx_key;
if ($v == 2) {
my $epoch_max;
defined($ibx->git_dir_latest(\$epoch_max)) or return;
- my $heads = $sync->{ranges} = [];
- for my $i (0..$epoch_max) {
- $heads->[$i] = $oidx->eidx_meta("lc-v2:$key//$u;$i");
- }
-
-
+ $sync->{epoch_max} = $epoch_max;
+ sync_prepare($self, $sync) or return; # fills $sync->{todo}
} elsif ($v == 1) {
- my $lc = $oidx->eidx_meta("lc-v1:$key//$u");
- prepare_stack($sync, $lc ? "$lc..HEAD" : 'HEAD');
+ my $uv = $ibx->uidvalidity;
+ my $lc = $self->{oidx}->eidx_meta("lc-v1:$ekey//$uv");
+ my $stk = prepare_stack($sync, $lc ? "$lc..HEAD" : 'HEAD');
+ my $unit = { stack => $stk, git => $ibx->git };
+ push @{$sync->{todo}}, $unit;
} else {
- warn "E: $key unsupported inbox version (v$v)\n";
+ warn "E: $ekey unsupported inbox version (v$v)\n";
return;
}
+ index_todo($self, $sync, $_) for @{$sync->{todo}};
}
sub eidx_sync { # main entry point
$self->{oidx}->rethread_prepare($opt);
_sync_inbox($self, $opt, $_) for (@{$self->{ibx_list}});
+
+ $self->{oidx}->rethread_done($opt);
+
+ PublicInbox::V2Writable::done($self);
+}
+
+sub update_last_commit {
+ my ($self, $sync, $unit, $latest_cmt) = @_;
+
+ my $ALL = $self->git;
+ # while (scalar(@{$ALL->{inflight_c}}) || scalar(@{$ALL->{inflight}})) {
+ # $ALL->check_async_wait;
+ # $ALL->cat_async_wait;
+ # }
+ # TODO
}
sub idx_init { # similar to V2Writable
*with_umask = \&PublicInbox::InboxWritable::with_umask;
*parallel_init = \&PublicInbox::V2Writable::parallel_init;
*nproc_shards = \&PublicInbox::V2Writable::nproc_shards;
+*sync_prepare = \&PublicInbox::V2Writable::sync_prepare;
+*index_todo = \&PublicInbox::V2Writable::index_todo;
+*count_shards = \&PublicInbox::V2Writable::count_shards;
+*atfork_child = \&PublicInbox::V2Writable::atfork_child;
+*idx_shard = \&PublicInbox::V2Writable::idx_shard;
1;