1 # Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 # based on notmuch, but with no concept of folders, files or flags
5 # Indexes mail with Xapian and our (SQLite-based) ::Msgmap for use
6 # with the web and NNTP interfaces. This index maintains thread
7 # relationships for use by PublicInbox::SearchThread.
8 # This writes to the search index.
9 package PublicInbox::SearchIdx;
12 use base qw(PublicInbox::Search PublicInbox::Lock);
13 use PublicInbox::MIME;
14 use PublicInbox::InboxWritable;
15 use PublicInbox::MID qw/mid_clean id_compress mid_mime mids/;
16 use PublicInbox::MsgIter;
18 use POSIX qw(strftime);
19 use PublicInbox::OverIdx;
20 use PublicInbox::Spawn qw(spawn);
21 use PublicInbox::Git qw(git_unquote);
24 BATCH_BYTES => defined($ENV{XAPIAN_FLUSH_THRESHOLD}) ?
25 0x7fffffff : 1_000_000,
26 DEBUG => !!$ENV{DEBUG},
29 my $xapianlevels = qr/\A(?:full|medium)\z/;
32 my ($class, $ibx, $creat, $part) = @_;
33 my $levels = qr/\A(?:full|medium|basic)\z/;
34 my $mainrepo = $ibx; # for "public-inbox-index" w/o entry in config
35 my $git_dir = $mainrepo;
38 my $indexlevel = 'full';
40 $mainrepo = $ibx->{mainrepo};
41 $altid = $ibx->{altid};
42 $version = $ibx->{version} || 1;
44 require PublicInbox::AltId;
46 PublicInbox::AltId->new($ibx, $_);
49 if ($ibx->{indexlevel}) {
50 if ($ibx->{indexlevel} =~ $levels) {
51 $indexlevel = $ibx->{indexlevel};
53 die("Invalid indexlevel $ibx->{indexlevel}\n");
56 } else { # FIXME: old tests: old tests
57 $ibx = { mainrepo => $git_dir, version => 1 };
59 $ibx = PublicInbox::InboxWritable->new($ibx);
61 mainrepo => $mainrepo,
66 indexlevel => $indexlevel,
70 $self->{lock_path} = "$mainrepo/ssoma.lock";
71 my $dir = $self->xdir;
72 $self->{over} = PublicInbox::OverIdx->new("$dir/over.sqlite3");
73 } elsif ($version == 2) {
74 defined $part or die "partition is required for v2\n";
75 # partition is a number
76 $self->{partition} = $part;
77 $self->{lock_path} = undef;
79 die "unsupported inbox version=$version\n";
81 $self->{creat} = ($creat || 0) == 1;
85 sub need_xapian ($) { $_[0]->{indexlevel} =~ $xapianlevels }
89 if (need_xapian($self)) {
90 my $xdb = delete $self->{xdb} or croak 'not acquired';
93 $self->lock_release if $self->{creat};
100 my $dir = $self->xdir;
101 if (need_xapian($self)) {
102 croak 'already acquired' if $self->{xdb};
103 PublicInbox::Search::load_xapian();
104 require Search::Xapian::WritableDatabase;
105 $flag = $self->{creat} ?
106 Search::Xapian::DB_CREATE_OR_OPEN() :
107 Search::Xapian::DB_OPEN();
109 if ($self->{creat}) {
113 # don't create empty Xapian directories if we don't need Xapian
114 my $is_part = defined($self->{partition});
115 if (!$is_part || ($is_part && need_xapian($self))) {
116 File::Path::mkpath($dir);
119 return unless defined $flag;
120 my $xdb = eval { Search::Xapian::WritableDatabase->new($dir, $flag) };
122 die "Failed opening $dir: ", $@;
128 my ($doc, $col, $num) = @_;
129 $num = Search::Xapian::sortable_serialise($num);
130 $doc->add_value($col, $num);
133 sub index_text ($$$$)
135 my ($self, $field, $n, $text) = @_;
136 my $tg = $self->term_generator;
138 if ($self->{indexlevel} eq 'full') {
139 $tg->index_text($field, $n, $text);
140 $tg->increase_termpos;
142 $tg->index_text_without_positions($field, $n, $text);
146 sub index_users ($$) {
147 my ($self, $smsg) = @_;
149 my $from = $smsg->from;
153 $self->index_text($from, 1, 'A'); # A - author
154 $self->index_text($to, 1, 'XTO') if $to ne '';
155 $self->index_text($cc, 1, 'XCC') if $cc ne '';
158 sub index_diff_inc ($$$$) {
159 my ($self, $text, $pfx, $xnq) = @_;
161 $self->index_text(join("\n", @$xnq), 1, 'XNQ');
164 $self->index_text($text, 1, $pfx);
167 sub index_old_diff_fn {
168 my ($self, $seen, $fa, $fb, $xnq) = @_;
170 # no renames or space support for traditional diffs,
171 # find the number of leading common paths to strip:
172 my @fa = split('/', $fa);
173 my @fb = split('/', $fb);
174 while (scalar(@fa) && scalar(@fb)) {
175 $fa = join('/', @fa);
176 $fb = join('/', @fb);
178 unless ($seen->{$fa}++) {
179 $self->index_diff_inc($fa, 'XDFN', $xnq);
189 sub index_diff ($$$) {
190 my ($self, $lines, $doc) = @_;
196 if ($in_diff && s/^ //) { # diff context
197 $self->index_diff_inc($_, 'XDFCTX', $xnq);
198 } elsif (/^-- $/) { # email signature begins
200 } elsif (m!^diff --git ("?a/.+) ("?b/.+)\z!) {
201 my ($fa, $fb) = ($1, $2);
202 my $fn = (split('/', git_unquote($fa), 2))[1];
203 $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
204 $fn = (split('/', git_unquote($fb), 2))[1];
205 $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
208 } elsif (m/^diff -(.+) (\S+) (\S+)$/) {
209 my ($opt, $fa, $fb) = ($1, $2, $3);
211 # only support unified:
212 next unless $opt =~ /[uU]/;
213 $in_diff = $self->index_old_diff_fn(\%seen, $fa, $fb,
215 } elsif (m!^--- ("?a/.+)!) {
216 my $fn = (split('/', git_unquote($1), 2))[1];
217 $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
219 } elsif (m!^\+\+\+ ("?b/.+)!) {
220 my $fn = (split('/', git_unquote($1), 2))[1];
221 $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
223 } elsif (/^--- (\S+)/) {
226 } elsif (defined $in_diff && /^\+\+\+ (\S+)/) {
227 $in_diff = $self->index_old_diff_fn(\%seen, $in_diff, $1,
229 } elsif ($in_diff && s/^\+//) { # diff added
230 $self->index_diff_inc($_, 'XDFB', $xnq);
231 } elsif ($in_diff && s/^-//) { # diff removed
232 $self->index_diff_inc($_, 'XDFA', $xnq);
233 } elsif (m!^index ([a-f0-9]+)\.\.([a-f0-9]+)!) {
234 my ($ba, $bb) = ($1, $2);
235 index_git_blob_id($doc, 'XDFPRE', $ba);
236 index_git_blob_id($doc, 'XDFPOST', $bb);
238 } elsif (/^@@ (?:\S+) (?:\S+) @@\s*$/) {
239 # traditional diff w/o -p
240 } elsif (/^@@ (?:\S+) (?:\S+) @@\s*(\S+.*)$/) {
241 # hunk header context
242 $self->index_diff_inc($1, 'XDFHH', $xnq);
243 # ignore the following lines:
244 } elsif (/^(?:dis)similarity index/ ||
245 /^(?:old|new) mode/ ||
246 /^(?:deleted|new) file mode/ ||
247 /^(?:copy|rename) (?:from|to) / ||
248 /^(?:dis)?similarity index / ||
249 /^\\ No newline at end of file/ ||
250 /^Binary files .* differ/) {
256 warn "non-diff line: $_\n" if DEBUG && $_ ne '';
261 $self->index_text(join("\n", @xnq), 1, 'XNQ');
264 sub index_body ($$$) {
265 my ($self, $lines, $doc) = @_;
266 my $txt = join("\n", @$lines);
268 # does it look like a diff?
269 if ($txt =~ /^(?:diff|---|\+\+\+) /ms) {
271 $self->index_diff($lines, $doc);
273 $self->index_text($txt, 1, 'XNQ');
276 $self->index_text($txt, 0, 'XQUOT');
281 sub add_xapian ($$$$$) {
282 my ($self, $mime, $num, $oid, $mids, $mid0) = @_;
283 my $smsg = PublicInbox::SearchMsg->new($mime);
284 my $doc = Search::Xapian::Document->new;
285 my $subj = $smsg->subject;
286 add_val($doc, PublicInbox::Search::TS(), $smsg->ts);
287 my @ds = gmtime($smsg->ds);
288 my $yyyymmdd = strftime('%Y%m%d', @ds);
289 add_val($doc, PublicInbox::Search::YYYYMMDD(), $yyyymmdd);
290 my $dt = strftime('%Y%m%d%H%M%S', @ds);
291 add_val($doc, PublicInbox::Search::DT(), $dt);
293 my $tg = $self->term_generator;
295 $tg->set_document($doc);
296 $self->index_text($subj, 1, 'S') if $subj;
297 $self->index_users($smsg);
299 msg_iter($mime, sub {
300 my ($part, $depth, @idx) = @{$_[0]};
301 my $ct = $part->content_type || 'text/plain';
302 my $fn = $part->filename;
303 if (defined $fn && $fn ne '') {
304 $self->index_text($fn, 1, 'XFN');
307 my ($s, undef) = msg_part_text($part, $ct);
308 defined $s or return;
311 my @lines = split(/\n/, $s);
312 while (defined(my $l = shift @lines)) {
314 $self->index_body(\@orig, $doc) if @orig;
317 $self->index_body(\@quot, 0) if @quot;
321 $self->index_body(\@quot, 0) if @quot;
322 $self->index_body(\@orig, $doc) if @orig;
325 foreach my $mid (@$mids) {
326 $self->index_text($mid, 1, 'XM');
328 # because too many Message-IDs are prefixed with
330 if ($mid =~ /\w{12,}/) {
331 my @long = ($mid =~ /(\w{3,}+)/g);
332 $self->index_text(join(' ', @long), 1, 'XM');
335 $smsg->{to} = $smsg->{cc} = '';
336 PublicInbox::OverIdx::parse_references($smsg, $mid0, $mids);
337 my $data = $smsg->to_doc_data($oid, $mid0);
338 $doc->set_data($data);
339 if (my $altid = $self->{-altid}) {
340 foreach my $alt (@$altid) {
341 my $pfx = $alt->{xprefix};
342 foreach my $mid (@$mids) {
343 my $id = $alt->mid2alt($mid);
344 next unless defined $id;
345 $doc->add_boolean_term($pfx . $id);
349 $doc->add_boolean_term('Q' . $_) foreach @$mids;
350 $self->{xdb}->replace_document($num, $doc);
354 # mime = Email::MIME object
355 my ($self, $mime, $bytes, $num, $oid, $mid0) = @_;
356 my $mids = mids($mime->header_obj);
357 $mid0 = $mids->[0] unless defined $mid0; # v1 compatibility
358 unless (defined $num) { # v1
360 $num = index_mm($self, $mime);
363 if (need_xapian($self)) {
364 $self->add_xapian($mime, $num, $oid, $mids, $mid0)
366 if (my $over = $self->{over}) {
367 $over->add_overview($mime, $bytes, $num, $oid, $mid0);
372 warn "failed to index message <".join('> <',@$mids).">: $@\n";
378 # returns begin and end PostingIterator
380 my ($self, $termval) = @_;
381 my $db = $self->{xdb};
383 ($db->postlist_begin($termval), $db->postlist_end($termval));
388 my ($self, $termval, $cb) = @_;
389 my $batch_size = 1000; # don't let @ids grow too large to avoid OOM
391 my ($head, $tail) = $self->find_doc_ids($termval);
392 return if $head == $tail;
394 for (; $head != $tail && @ids < $batch_size; $head->inc) {
395 push @ids, $head->get_docid;
401 # v1 only, where $mid is unique
403 my ($self, $mid) = @_;
404 $mid = mid_clean($mid);
406 if (my $over = $self->{over}) {
407 my $nr = eval { $over->remove_oid(undef, $mid) };
409 warn "failed to remove <$mid> from overview: $@\n";
411 warn "<$mid> missing for removal from overview\n";
414 return unless need_xapian($self);
415 my $db = $self->{xdb};
418 batch_do($self, 'Q' . $mid, sub {
420 $db->delete_document($_) for @$ids;
425 warn "failed to remove <$mid> from Xapian: $@\n";
427 warn "<$mid> missing for removal from Xapian\n";
431 # MID is a hint in V2
433 my ($self, $oid, $mid) = @_;
435 $self->{over}->remove_oid($oid, $mid) if $self->{over};
437 return unless need_xapian($self);
438 my $db = $self->{xdb};
440 # XXX careful, we cannot use batch_do here since we conditionally
441 # delete documents based on other factors, so we cannot call
442 # find_doc_ids twice.
443 my ($head, $tail) = $self->find_doc_ids('Q' . $mid);
444 return if $head == $tail;
446 # there is only ONE element in @delete unless we
447 # have bugs in our v2writable deduplication check
449 for (; $head != $tail; $head->inc) {
450 my $docid = $head->get_docid;
451 my $doc = $db->get_document($docid);
452 my $smsg = PublicInbox::SearchMsg->wrap($mid);
453 $smsg->load_expand($doc);
454 if ($smsg->{blob} eq $oid) {
455 push(@delete, $docid);
458 $db->delete_document($_) foreach @delete;
462 sub term_generator { # write-only
465 my $tg = $self->{term_generator};
468 $tg = Search::Xapian::TermGenerator->new;
469 $tg->set_stemmer($self->stemmer);
471 $self->{term_generator} = $tg;
474 sub index_git_blob_id {
475 my ($doc, $pfx, $objid) = @_;
477 my $len = length($objid);
478 for (my $len = length($objid); $len >= 7; ) {
479 $doc->add_term($pfx.$objid);
480 $objid = substr($objid, 0, --$len);
485 my ($self, $mime) = @_;
486 my $mid = eval { mid_clean(mid_mime($mime)) };
487 $self->remove_message($mid) if defined $mid;
491 my ($self, $mime) = @_;
492 my $mid = mid_clean(mid_mime($mime));
493 my $mm = $self->{mm};
496 if (defined $self->{regen_down}) {
497 $num = $mm->num_for($mid) and return $num;
499 while (($num = $self->{regen_down}--) > 0) {
500 if ($mm->mid_set($num, $mid) != 0) {
504 } elsif (defined $self->{regen_up}) {
505 $num = $mm->num_for($mid) and return $num;
507 # this is to fixup old bugs due to add-remove-add
508 while (($num = ++$self->{regen_up})) {
509 if ($mm->mid_set($num, $mid) != 0) {
515 $num = $mm->mid_insert($mid) and return $num;
517 # fallback to num_for since filters like RubyLang set the number
522 my ($self, $mime) = @_;
523 $self->{mm}->mid_delete(mid_clean(mid_mime($mime)));
527 my ($self, $mime, $bytes, $blob) = @_;
528 my $num = index_mm($self, $mime);
529 add_message($self, $mime, $bytes, $num, $blob);
533 my ($self, $mime) = @_;
534 unindex_blob($self, $mime);
535 unindex_mm($self, $mime);
539 my ($git, $blob, $sizeref) = @_;
541 my $str = $git->cat_file($blob, $sizeref);
542 # fixup bugs from import:
543 $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
544 PublicInbox::MIME->new($str);
549 # called by public-inbox-index
551 my ($self, $opts) = @_;
552 delete $self->{lock_path} if $opts->{-skip_lock};
553 $self->{-inbox}->with_umask(sub { $self->_index_sync($opts) })
556 sub batch_adjust ($$$$$) {
557 my ($max, $bytes, $batch_cb, $latest, $nr) = @_;
561 $batch_cb->($nr, $latest);
567 my ($self, $log, $add_cb, $del_cb, $batch_cb) = @_;
568 my $hex = '[a-f0-9]';
569 my $h40 = $hex .'{40}';
570 my $addmsg = qr!^:000000 100644 \S+ ($h40) A\t${hex}{2}/${hex}{38}$!;
571 my $delmsg = qr!^:100644 000000 ($h40) \S+ D\t${hex}{2}/${hex}{38}$!;
572 my $git = $self->{git};
575 my $max = BATCH_BYTES;
581 while (defined($line = <$log>)) {
582 if ($line =~ /$addmsg/o) {
584 if (delete $D{$blob}) {
585 if (defined $self->{regen_down}) {
586 my $num = $self->{regen_down}--;
587 $self->{mm}->num_highwater($num);
591 my $mime = do_cat_mail($git, $blob, \$bytes) or next;
592 batch_adjust(\$max, $bytes, $batch_cb, $latest, ++$nr);
593 $add_cb->($self, $mime, $bytes, $blob);
594 } elsif ($line =~ /$delmsg/o) {
597 } elsif ($line =~ /^commit ($h40)/o) {
603 foreach my $blob (keys %D) {
604 my $mime = do_cat_mail($git, $blob, \$bytes) or next;
605 $del_cb->($self, $mime);
607 $batch_cb->($nr, $latest, $newest);
612 die "BUG: _msgmap_init is only for v1\n" if $self->{version} != 1;
613 $self->{mm} ||= eval {
614 require PublicInbox::Msgmap;
615 PublicInbox::Msgmap->new($self->{mainrepo}, 1);
620 my ($self, $opts, $range) = @_;
621 my $git = $self->{git};
623 if (index($range, '..') < 0) {
624 # don't show annoying git errrors to users who run -index
626 $git->qx(qw(rev-parse -q --verify), "$range^0");
628 open my $fh, '<', '/dev/null' or
629 die "failed to open /dev/null: $!\n";
634 # Count the new files so they can be added newest to oldest
635 # and still have numbers increasing from oldest to newest
637 my $pr = $opts->{-progress};
638 $pr->("counting changes\n\t$range ... ") if $pr;
639 # can't use 'rev-list --count' if we use --diff-filter
640 my $fh = $git->popen(qw(log --pretty=tformat:%h
641 --no-notes --no-color --no-renames
642 --diff-filter=AM), $range);
643 ++$fcount while <$fh>;
645 my $high = $self->{mm}->num_highwater;
646 $pr->("$fcount\n") if $pr; # continue previous line
647 $self->{ntodo} = $fcount;
649 if (index($range, '..') < 0) {
650 if ($high && $high == $fcount) {
651 # fix up old bugs in full indexes which caused messages to
652 # not appear in Msgmap
653 $self->{regen_up} = $high;
655 # normal regen is for for fresh data
656 $self->{regen_down} = $fcount;
659 # Give oldest messages the smallest numbers
660 $self->{regen_down} = $high + $fcount;
663 $git->popen(qw/log --no-notes --no-color --no-renames
664 --raw -r --no-abbrev/, $range);
667 # --is-ancestor requires git 1.8.0+
668 sub is_ancestor ($$$) {
669 my ($git, $cur, $tip) = @_;
670 return 0 unless $git->check($cur);
671 my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
672 qw(merge-base --is-ancestor), $cur, $tip ];
673 my $pid = spawn($cmd);
674 defined $pid or die "spawning ".join(' ', @$cmd)." failed: $!";
675 waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
679 sub need_update ($$$) {
680 my ($self, $cur, $new) = @_;
681 my $git = $self->{git};
682 return 1 if $cur && !is_ancestor($git, $cur, $new);
683 my $range = $cur eq '' ? $new : "$cur..$new";
684 chomp(my $n = $git->qx(qw(rev-list --count), $range));
685 ($n eq '' || $n > 0);
688 # The last git commit we indexed with Xapian or SQLite (msgmap)
689 # This needs to account for cases where Xapian or SQLite is
690 # out-of-date with respect to the other.
692 my ($self, $mm) = @_;
693 my $lm = $mm->last_commit || '';
695 if (need_xapian($self)) {
696 $lx = $self->{xdb}->get_metadata('last_commit') || '';
700 # Use last_commit from msgmap if it is older or unset
701 if (!$lm || ($lx && $lm && is_ancestor($self->{git}, $lm, $lx))) {
707 sub reindex_from ($$) {
708 my ($reindex, $last_commit) = @_;
709 return $last_commit unless $reindex;
710 ref($reindex) eq 'HASH' ? $reindex->{from} : '';
713 # indexes all unindexed messages (v1 only)
715 my ($self, $opts) = @_;
716 my $tip = $opts->{ref} || 'HEAD';
717 my ($last_commit, $lx, $xlog);
718 my $git = $self->{git};
720 my $pr = $opts->{-progress};
722 my $xdb = $self->begin_txn_lazy;
723 my $mm = _msgmap_init($self);
726 $last_commit = _last_x_commit($self, $mm);
727 $lx = reindex_from($opts->{reindex}, $last_commit);
729 $self->{over}->rollback_lazy;
730 $self->{over}->disconnect;
733 $xdb->cancel_transaction if $xdb;
734 $xdb = _xdb_release($self);
736 # ensure we leak no FDs to "git log" with Xapian <= 1.2
737 my $range = $lx eq '' ? $tip : "$lx..$tip";
738 $xlog = _git_log($self, $opts, $range);
740 $xdb = $self->begin_txn_lazy;
741 } while (_last_x_commit($self, $mm) ne $last_commit);
743 my $dbh = $mm->{dbh} if $mm;
745 my ($nr, $commit, $newest) = @_;
748 my $cur = $mm->last_commit || '';
749 if (need_update($self, $cur, $newest)) {
750 $mm->last_commit($newest);
755 if ($newest && need_xapian($self)) {
756 my $cur = $xdb->get_metadata('last_commit');
757 if (need_update($self, $cur, $newest)) {
758 $xdb->set_metadata('last_commit', $newest);
761 $self->commit_txn_lazy;
763 $xdb = _xdb_release($self);
764 # let another process do some work... <
765 $pr->("indexed $nr/$self->{ntodo}\n") if $pr && $nr;
767 $xdb = $self->begin_txn_lazy;
768 $dbh->begin_work if $dbh;
773 read_log($self, $xlog, *index_both, *unindex_both, $cb);
777 # order matters for unlocking
778 $_[0]->{xdb} = undef;
779 $_[0]->{lockfh} = undef;
782 # remote_* subs are only used by SearchIdxPart
785 if (my $w = $self->{w}) {
786 print $w "commit\n" or die "failed to write commit: $!";
788 $self->commit_txn_lazy;
794 if (my $w = delete $self->{w}) {
795 my $pid = delete $self->{pid} or die "no process to wait on\n";
796 print $w "close\n" or die "failed to write to pid:$pid: $!\n";
797 close $w or die "failed to close pipe for pid:$pid: $!\n";
798 waitpid($pid, 0) == $pid or die "remote process did not finish";
799 $? == 0 or die ref($self)." pid:$pid exited with: $?";
801 die "transaction in progress $self\n" if $self->{txn};
802 $self->_xdb_release if $self->{xdb};
807 my ($self, $oid, $mid) = @_;
808 if (my $w = $self->{w}) {
809 # triggers remove_by_oid in a partition
810 print $w "D $oid $mid\n" or die "failed to write remove $!";
812 $self->begin_txn_lazy;
813 $self->remove_by_oid($oid, $mid);
819 return if $self->{txn};
821 $self->{-inbox}->with_umask(sub {
822 my $xdb = $self->{xdb} || $self->_xdb_acquire;
823 $self->{over}->begin_lazy if $self->{over};
824 $xdb->begin_transaction if $xdb;
830 sub commit_txn_lazy {
832 delete $self->{txn} or return;
833 $self->{-inbox}->with_umask(sub {
834 if (my $xdb = $self->{xdb}) {
836 # store 'indexlevel=medium' in v2 part=0 and v1 (only part)
837 # This metadata is read by Admin::detect_indexlevel:
838 if (!$self->{partition} # undef or 0, not >0
839 && $self->{indexlevel} eq 'medium') {
840 $xdb->set_metadata('indexlevel', 'medium');
843 $xdb->commit_transaction;
845 $self->{over}->commit_lazy if $self->{over};
851 if (need_xapian($self)) {
852 die "$$ $0 xdb not released\n" if $self->{xdb};
854 die "$$ $0 still in transaction\n" if $self->{txn};