1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # temporary queue for public-inbox-index to support multi-Message-ID
5 # messages on mirrors of v2 inboxes
6 package PublicInbox::MultiMidQueue;
8 use SDBM_File; # part of Perl standard library
9 use Fcntl qw(O_RDWR O_CREAT);
10 use File::Temp 0.19 (); # 0.19 for ->newdir
17 my $O_CLOEXEC = $e{$^O} // 0;
21 my $tmpdir = File::Temp->newdir('multi-mid-q-XXXXXX', TMPDIR => 1);
22 my $base = $tmpdir->dirname . '/q';
24 my $flags = O_RDWR|O_CREAT;
25 if (!tie(%sdbm, 'SDBM_File', $base, $flags|$O_CLOEXEC, 0600)) {
26 if (!tie(%sdbm, 'SDBM_File', $base, $flags, 0600)) {
27 die "could not tie ($base): $!";
42 my ($self, $i, $oid, $v2w) = @_;
43 $self->{max} = $i if $i > $self->{max};
44 $self->{min} = $i if $i < $self->{min};
45 $self->{sdbm}->{$i} = "$oid\t$v2w->{autime}\t$v2w->{cotime}";
49 my ($self, $i, $v2w) = @_;
50 my $rec = $self->{sdbm}->{$i} or return;
51 my ($oid, $autime, $cotime) = split(/\t/, $rec);
52 $v2w->{autime} = $autime;
53 $v2w->{cotime} = $cotime;
58 my ($self, $oid, $v2w) = @_;
59 set_oid($self, $self->{cur}++, $oid, $v2w);