From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5C8C31F55B; Thu, 21 May 2020 09:37:16 +0000 (UTC) Date: Thu, 21 May 2020 09:37:16 +0000 From: Eric Wong To: meta@public-inbox.org Subject: Re: [PATCH] inboxidle: new class to detect inbox changes Message-ID: <20200521093716.GA21137@dcvr> References: <20200521071532.1970-1-e@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200521071532.1970-1-e@yhbt.net> List-Id: Eric Wong wrote: > --- a/lib/PublicInbox/Inbox.pm Naming is (still) hard. > +# $obj must respond to >inbox_changed, which takes Inbox ($self) as an arg ^^^^^^^^^^^^^ That should be ->on_inbox_unlock > +sub subscribe_unlock { > + my ($self, $ident, $obj) = @_; > + $self->{over_subs}->{$ident} = $obj; > +} > + > +sub unsubscribe_unlock { > + my ($self, $ident) = @_; > + delete $self->{over_subs}->{$ident}; > +} {over_subs} might be a bad name, here. I originally had this watching over.sqlite3, but started watching the lock, instead. I figure SQLite3 could (now or in the future) write via mmap without waking up inotify. And there may be users who want to serve v1 w/o SQLite... > + > +# called by inotify > +sub on_unlock { > + my ($self) = @_; > + my $subs = $self->{over_subs} or return; > + for (values %$subs) { > + eval { $_->on_inbox_unlock($self) }; > + } Yes, ->on_inbox_unlock is the correct method right now, not ->inbox_changed > diff --git a/lib/PublicInbox/Lock.pm b/lib/PublicInbox/Lock.pm > index 032841ed..5a55c9d3 100644 > --- a/lib/PublicInbox/Lock.pm > +++ b/lib/PublicInbox/Lock.pm > @@ -14,7 +14,7 @@ sub lock_acquire { > my ($self) = @_; > croak 'already locked' if $self->{lockfh}; > my $lock_path = $self->{lock_path} or return; > - sysopen(my $lockfh, $lock_path, O_WRONLY|O_CREAT) or > + sysopen(my $lockfh, $lock_path, O_TRUNC|O_WRONLY|O_CREAT) or I don't think O_TRUNC is necessary, here. O_TRUNC here bothers me, since it causes useless I/O traffic and SSD write amplification on systems, especially where inotify or kqueue are available. > @@ -24,6 +24,11 @@ sub lock_release { > my ($self) = @_; > return unless $self->{lock_path}; > my $lockfh = delete $self->{lockfh} or croak 'not locked'; > + > + # NetBSD 8.1 and OpenBSD 6.5 (and maybe other versions/*BSDs) lack > + # NOTE_CLOSE_WRITE from FreeBSD 11+, so trigger NOTE_WRITE, instead > + syswrite($lockfh, '.') if $^O ne 'linux'; Yeah, relying on NOTE_WRITE there is kinda gross, but NOTE_CLOSE_WRITE isn't available on all *BSDs. > + > +done_testing; > + > +package InboxIdleTestObj; > +use strict; > + > +sub new { bless {}, shift } > + > +sub on_inbox_unlock { > + my ($self, $ibx) = @_; > + push @{$self->{called}}, $ibx; > +} Yup, we use ->on_inbox_unlock, not ->inbox_changed