unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: David Bremner <david@tethera.net>,
	notmuch@notmuchmail.org, eg@gaute.vetsj.com
Subject: Re: [PATCH 2/4] lib: add notmuch_database_reopen
Date: Sat, 25 Feb 2017 20:33:46 +0200	[thread overview]
Message-ID: <87shn26rxx.fsf@nikula.org> (raw)
In-Reply-To: <20170225034513.19427-3-david@tethera.net>

On Fri, 24 Feb 2017, David Bremner <david@tethera.net> wrote:
> The main expected use is to recover from a Xapian::DatabaseChanged
> exception.

I guess the main question here is if this should be exposed from the
library or not. If the intention is to recover *within* the library, why
add new API?

> ---
>  lib/database-private.h |  4 ++++
>  lib/database.cc        | 23 +++++++++++++++++++++++
>  lib/notmuch.h          | 12 ++++++++++++
>  3 files changed, 39 insertions(+)
>
> diff --git a/lib/database-private.h b/lib/database-private.h
> index 2fb60f5e..06882439 100644
> --- a/lib/database-private.h
> +++ b/lib/database-private.h
> @@ -207,6 +207,10 @@ struct _notmuch_database {
>      unsigned long revision;
>      const char *uuid;
>  
> +    /* Keep track of the number of times the database has been re-opened
> +     * (or other global invalidations of notmuch's caching)
> +     */
> +    unsigned long view;
>      Xapian::QueryParser *query_parser;
>      Xapian::TermGenerator *term_gen;
>      Xapian::ValueRangeProcessor *value_range_processor;
> diff --git a/lib/database.cc b/lib/database.cc
> index 386dcd17..1e958b65 100644
> --- a/lib/database.cc
> +++ b/lib/database.cc
> @@ -951,6 +951,7 @@ notmuch_database_open_verbose (const char *path,
>  
>      notmuch->mode = mode;
>      notmuch->atomic_nesting = 0;
> +    notmuch->view = 1;
>      try {
>  	string last_thread_id;
>  	string last_mod;
> @@ -1133,6 +1134,28 @@ notmuch_database_close (notmuch_database_t *notmuch)
>      return status;
>  }
>  
> +notmuch_status_t
> +notmuch_database_reopen (notmuch_database_t *notmuch)
> +{
> +    if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_ONLY)
> +	return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
> +
> +    try {
> +	notmuch->xapian_db->reopen ();
> +    } catch (const Xapian::Error &error) {
> +	if (! notmuch->exception_reported) {
> +	    _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",
> +				   error.get_msg ().c_str ());
> +	    notmuch->exception_reported = TRUE;
> +	    return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
> +	}

Move the above return out of the if block?

> +    }
> +
> +    notmuch->view++;
> +
> +    return NOTMUCH_STATUS_SUCCESS;
> +}
> +
>  static int
>  unlink_cb (const char *path,
>  	   unused (const struct stat *sb),
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index 16da8be9..e9ed01dd 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -363,6 +363,18 @@ notmuch_status_t
>  notmuch_database_close (notmuch_database_t *database);
>  
>  /**
> + * Reopen a (read-only) database, synching the database view with that
> + * on disk.
> + *
> + * @returns
> + * - NOTMUCH_STATUS_UNSUPPORTED_OPERATION: database is not read only
> + * - NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured trying to
> + *   re-open the database.
> + */
> +notmuch_status_t
> +notmuch_database_reopen (notmuch_database_t *database);
> +
> +/**
>   * A callback invoked by notmuch_database_compact to notify the user
>   * of the progress of the compaction process.
>   */
> -- 
> 2.11.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

  reply	other threads:[~2017-02-25 18:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-25  3:45 v1 _notmuch_message_ensure_metadata exception handling David Bremner
2017-02-25  3:45 ` [PATCH 1/4] test: add known broken test for uncaught DatabaseModifiedError David Bremner
2017-02-25 18:49   ` Jani Nikula
2017-02-25 20:08     ` David Bremner
2017-02-25  3:45 ` [PATCH 2/4] lib: add notmuch_database_reopen David Bremner
2017-02-25 18:33   ` Jani Nikula [this message]
2017-02-25 20:11     ` David Bremner
2017-02-25  3:45 ` [PATCH 3/4] lib: handle DatabaseModifiedError in _n_message_ensure_metadata David Bremner
2017-02-25 18:42   ` Jani Nikula
2017-02-25 20:21     ` David Bremner
2017-02-25 20:39       ` Jani Nikula
2017-02-25  3:45 ` [PATCH 4/4] lib/message.cc: use view number to invalidate cached metadata David Bremner
2017-02-25 18:44   ` Jani Nikula

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://notmuchmail.org/

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

  git send-email \
    --in-reply-to=87shn26rxx.fsf@nikula.org \
    --to=jani@nikula.org \
    --cc=david@tethera.net \
    --cc=eg@gaute.vetsj.com \
    --cc=notmuch@notmuchmail.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://yhetil.org/notmuch.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).