unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] forbid atomic transactions on writable, upgradable databases
@ 2015-10-25 21:30 Steven Allen
  2015-11-23 12:52 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Allen @ 2015-10-25 21:30 UTC (permalink / raw)
  To: notmuch; +Cc: Steven Allen

We can't (but currently do) allow upgrades within transactions because
upgrades need their own transactions. We don't want to re-use the
current transaction because bailing out of an upgrade would mean loosing
all previous changes (because our "atomic" transactions don't commit
before hand). This gives us two options:

1. Fail at the beginning of upgrade (tell the user to end the
   transaction, upgrade, and start over).
2. Don't allow the user to start the transaction.

I went with the latter because:

1. There is no reason to call `begin_atomic` unless you intend to to
   write to the database and anyone intending to write to the database
   should upgrade it first.
2. This means that nothing inside an atomic transaction can ever fail
   with NOTMUCH_STATUS_UPGRADE_REQUIRED.
---
 lib/database.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index 5e86955..3b342f1 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1635,6 +1635,9 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
 	notmuch->atomic_nesting > 0)
 	goto DONE;
 
+	if (notmuch_database_needs_upgrade(notmuch))
+		return NOTMUCH_STATUS_UPGRADE_REQUIRED;
+
     try {
 	(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
     } catch (const Xapian::Error &error) {
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] forbid atomic transactions on writable, upgradable databases
  2015-10-25 21:30 [PATCH] forbid atomic transactions on writable, upgradable databases Steven Allen
@ 2015-11-23 12:52 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2015-11-23 12:52 UTC (permalink / raw)
  To: Steven Allen, notmuch

Steven Allen <steven@stebalien.com> writes:

> 1. There is no reason to call `begin_atomic` unless you intend to to
>    write to the database and anyone intending to write to the database
>    should upgrade it first.
> 2. This means that nothing inside an atomic transaction can ever fail
>    with NOTMUCH_STATUS_UPGRADE_REQUIRED.

Applied to master

d

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-23 12:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-25 21:30 [PATCH] forbid atomic transactions on writable, upgradable databases Steven Allen
2015-11-23 12:52 ` David Bremner

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).