user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: Re: [PATCH] inboxidle: new class to detect inbox changes
Date: Thu, 21 May 2020 09:37:16 +0000	[thread overview]
Message-ID: <20200521093716.GA21137@dcvr> (raw)
In-Reply-To: <20200521071532.1970-1-e@yhbt.net>

Eric Wong <e@yhbt.net> 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

      reply	other threads:[~2020-05-21  9:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21  7:15 [PATCH] inboxidle: new class to detect inbox changes Eric Wong
2020-05-21  9:37 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200521093716.GA21137@dcvr \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).