[PATCH 16/17] new: Wrap adding and removing messages in atomic sections.
Austin Clements
amdragon at MIT.EDU
Sat Jun 11 13:04:42 PDT 2011
This addresses atomicity of tag synchronization, the last atomicity
problems in notmuch new. Each message add or remove is wrapped in its
own atomic section, so interrupting notmuch new doesn't lose progress.
---
notmuch-new.c | 16 ++++++++++++++++
test/atomicity | 2 +-
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/notmuch-new.c b/notmuch-new.c
index b24eb51..fb92b03 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -428,6 +428,12 @@ add_files_recursive (notmuch_database_t *notmuch,
fflush (stdout);
}
+ status = notmuch_database_begin_atomic (notmuch);
+ if (status) {
+ ret = status;
+ goto DONE;
+ }
+
status = notmuch_database_add_message (notmuch, next, &message);
switch (status) {
/* success */
@@ -468,6 +474,12 @@ add_files_recursive (notmuch_database_t *notmuch,
goto DONE;
}
+ status = notmuch_database_end_atomic (notmuch);
+ if (status) {
+ ret = status;
+ goto DONE;
+ }
+
if (message) {
notmuch_message_destroy (message);
message = NULL;
@@ -700,6 +712,9 @@ remove_filename (notmuch_database_t *notmuch,
{
notmuch_status_t status;
notmuch_message_t *message;
+ status = notmuch_database_begin_atomic (notmuch);
+ if (status)
+ return status;
message = notmuch_database_find_message_by_filename (notmuch, path);
status = notmuch_database_remove_message (notmuch, path);
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
@@ -709,6 +724,7 @@ remove_filename (notmuch_database_t *notmuch,
} else
add_files_state->removed_messages++;
notmuch_message_destroy (message);
+ notmuch_database_end_atomic (notmuch);
return status;
}
diff --git a/test/atomicity b/test/atomicity
index 817819a..f546c07 100755
--- a/test/atomicity
+++ b/test/atomicity
@@ -96,7 +96,7 @@ for ((i = 0; i < $outcount; i++)); do
i=$(expr $end - 1)
fi
done
-test_expect_equal_failure GDB "$(cat searchall)" "$(cat expectall)"
+test_expect_equal GDB "$(cat searchall)" "$(cat expectall)"
test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10"
--
1.7.5.1
More information about the notmuch
mailing list