From: Jani Nikula Date: Thu, 14 Nov 2013 14:08:55 +0000 (+0100) Subject: Re: [PATCH v2 3/5] compact: preserve backup database until compacted database is... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e1243e5c2f718c42116f1bf2d869e21f70db0d38;p=notmuch-archives.git Re: [PATCH v2 3/5] compact: preserve backup database until compacted database is in place --- diff --git a/9b/1c60c51ce66d8a4ad18adf5f62ddc147031e6f b/9b/1c60c51ce66d8a4ad18adf5f62ddc147031e6f new file mode 100644 index 000000000..66f3e638e --- /dev/null +++ b/9b/1c60c51ce66d8a4ad18adf5f62ddc147031e6f @@ -0,0 +1,173 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 175CA431FC4 + for ; Thu, 14 Nov 2013 06:38:00 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 4mvrzmNt+C1u for ; + Thu, 14 Nov 2013 06:37:52 -0800 (PST) +Received: from mail-we0-f171.google.com (mail-we0-f171.google.com + [74.125.82.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D331A431FB6 + for ; Thu, 14 Nov 2013 06:37:51 -0800 (PST) +Received: by mail-we0-f171.google.com with SMTP id t61so2069322wes.30 + for ; Thu, 14 Nov 2013 06:37:50 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:in-reply-to:references + :user-agent:date:message-id:mime-version:content-type; + bh=F3IuyrOG7YiYZmu+/JjuBX7uIKx/i8LT5IMR2uTJDpk=; + b=LB1OhFHWV6qeAl6sV5BC6CkvA4VbRH9dvf7wnjL8Bv3wiXGZ8qln7hGzx331bo9NLd + bT/K0vGN08i/QQulLwshhrp/qZJ7fhe4/lvT3cTr2SASA9pfimaWIS8vvGFjuETpUL1M + JkDYYOQfZZeBxL0aGGFQS3PfVg0NFiF6bT0tVhS4YX4sZ5VTXMRQr7J27NagTplGF0Xt + zHGo/8W0w1+8CqCDSVuR41jXiZdbUDY6j9/4LjfhIJxXoocOilpFOBUo5SovoFQV0lF3 + a6yseB3eLQVPxFlXsSWVb4UjZ/LMgDQ31sBsyrAecjvz2szndoqvkKzYcSuy6y1AG0x4 + o5Ag== +X-Gm-Message-State: + ALoCoQl6up+nUhzxy5v3oxhQUZuyhU5DjwhnPd2gcp/wKIDKsKEV+kYZFpU53jffbC7gHtXRaps6 +X-Received: by 10.180.89.98 with SMTP id bn2mr2824161wib.63.1384438151571; + Thu, 14 Nov 2013 06:09:11 -0800 (PST) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id x19sm5550103wia.5.2013.11.14.06.09.10 + for + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Thu, 14 Nov 2013 06:09:10 -0800 (PST) +From: Jani Nikula +To: Tomi Ollila , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 3/5] compact: preserve backup database until compacted + database is in place +In-Reply-To: <1384362167-12740-4-git-send-email-tomi.ollila@iki.fi> +References: <1384362167-12740-1-git-send-email-tomi.ollila@iki.fi> + <1384362167-12740-4-git-send-email-tomi.ollila@iki.fi> +User-Agent: Notmuch/0.16+115~gd647c65 (http://notmuchmail.org) Emacs/23.2.1 + (x86_64-pc-linux-gnu) +Date: Thu, 14 Nov 2013 15:08:55 +0100 +Message-ID: <874n7fnki0.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Cc: tomi.ollila@iki.fi +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 14 Nov 2013 14:38:00 -0000 + +On Wed, 13 Nov 2013, Tomi Ollila wrote: +> It is less error prone and window of failure opportunity is smaller +> if the old (backup) database is always renamed (instead of sometimes +> rmtree'd) before new (compacted) database is put into its place. +> Finally rmtree() old database in case old database backup is not kept. +> --- +> lib/database.cc | 42 +++++++++++++++++++++++++----------------- +> 1 file changed, 25 insertions(+), 17 deletions(-) +> +> diff --git a/lib/database.cc b/lib/database.cc +> index 3530cb6..ee09c5e 100644 +> --- a/lib/database.cc +> +++ b/lib/database.cc +> @@ -873,6 +873,7 @@ notmuch_database_compact (const char *path, +> notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; +> notmuch_database_t *notmuch = NULL; +> struct stat statbuf; +> + notmuch_bool_t keep_backup; +> +> local = talloc_new (NULL); +> if (! local) +> @@ -898,17 +899,25 @@ notmuch_database_compact (const char *path, +> goto DONE; +> } +> +> - if (backup_path != NULL) { +> - if (stat (backup_path, &statbuf) != -1) { +> - fprintf (stderr, "Backup path already exists: %s\n", backup_path); +> - ret = NOTMUCH_STATUS_FILE_ERROR; +> - goto DONE; +> - } +> - if (errno != ENOENT) { +> - fprintf (stderr, "Unknown error while stat()ing backup path: %s\n", +> - strerror (errno)); +> + if (backup_path == NULL) { +> + if (! (backup_path = talloc_asprintf (local, "%s.old", xapian_path))) { +> + ret = NOTMUCH_STATUS_OUT_OF_MEMORY; +> goto DONE; +> } +> + keep_backup = FALSE; +> + } +> + else +> + keep_backup = TRUE; + +*cough* I thought you were the style police around here *cough* + +> + +> + if (stat (backup_path, &statbuf) != -1) { +> + fprintf (stderr, "Backup path already exists: %s\n", backup_path); + +The user will be confused if he specifically didn't add --backup and +happens to get this. But maybe it's a corner case. *shrug*. + +> + ret = NOTMUCH_STATUS_FILE_ERROR; +> + goto DONE; +> + } +> + if (errno != ENOENT) { +> + fprintf (stderr, "Unknown error while stat()ing backup path: %s\n", +> + strerror (errno)); + +ret = ? + +> + goto DONE; +> } +> +> try { +> @@ -924,14 +933,10 @@ notmuch_database_compact (const char *path, +> goto DONE; +> } +> +> - if (backup_path) { +> - if (rename (xapian_path, backup_path)) { +> - fprintf (stderr, "Error moving old database out of the way\n"); +> - ret = NOTMUCH_STATUS_FILE_ERROR; +> - goto DONE; +> - } +> - } else { +> - rmtree (xapian_path); +> + if (rename (xapian_path, backup_path)) { +> + fprintf (stderr, "Error moving old database out of the way\n"); +> + ret = NOTMUCH_STATUS_FILE_ERROR; +> + goto DONE; +> } +> +> if (rename (compact_xapian_path, xapian_path)) { +> @@ -940,6 +945,9 @@ notmuch_database_compact (const char *path, +> goto DONE; +> } +> +> + if (! keep_backup) +> + rmtree (backup_path); +> + +> DONE: +> if (notmuch) +> notmuch_database_destroy (notmuch); +> -- +> 1.8.3.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch