From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 1pe9EVFB5l6jGwAA0tVLHw (envelope-from ) for ; Sun, 14 Jun 2020 15:25:05 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cEcnDVFB5l7AJgAAB5/wlQ (envelope-from ) for ; Sun, 14 Jun 2020 15:25:05 +0000 Received: from arlo.cworth.org (arlo.cworth.org [50.126.95.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BC7529408E9 for ; Sun, 14 Jun 2020 15:25:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 27AB06DE13CC; Sun, 14 Jun 2020 08:25:03 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QshFk-IiapRB; Sun, 14 Jun 2020 08:25:02 -0700 (PDT) Received: from arlo.cworth.org (localhost [IPv6:::1]) by arlo.cworth.org (Postfix) with ESMTP id E06116DE13BA; Sun, 14 Jun 2020 08:25:01 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id B6CBA6DE13BA for ; Sun, 14 Jun 2020 08:25:00 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nwaZYwT8FsV7 for ; Sun, 14 Jun 2020 08:25:00 -0700 (PDT) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by arlo.cworth.org (Postfix) with ESMTPS id 26D9B6DE13AE for ; Sun, 14 Jun 2020 08:25:00 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id r15so12374472wmh.5 for ; Sun, 14 Jun 2020 08:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YTLs+loOIDkRF4SQ2nJlHlqWtTPOa7AH310XDiqF/b4=; b=PuQFAAshYIVTbJjp9rD8KWn3N44saEVlQtxpsjSHlj+BAxBrSsYwU2xAkMjqj9uRRa qFiZmqHlGrfuACMwEj1M0HxtY86DMZNQCzvnWPdgKnRNUaQqqSOyLBBMxYz8oa5au2Uk jy5eSX7x68CenDc98AkVeD3WBWz7WqGsjs4PkPSiM9vrE0oZgCNaVVeuxrcWxq2JhwUi 36wF4G9WlvzKw3X3kHeEUtrOLZkKGiZ/JWDrm0p+tFb0suSrxR1HzoQL274vZZvrieLH BlpZBSzv2Zr7454J6TFjlkdEOm5QovU/uv1kErtaaaL+A2m4pmFmToE4dKvI3OX11AJL bzXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YTLs+loOIDkRF4SQ2nJlHlqWtTPOa7AH310XDiqF/b4=; b=ZQluwDkG1edvsR6qAZr9NffCqvLb1BND2fys3OqrxU4dR2jqJ/uOGdjATtDKn4kNcc AlvLvvyHlzYPZoQ591IXD3r8kel1BWnQpc0fptiGjRVgz2eQzB/v0x5iwZ35/F77rgGJ ROp7PPYjLm9s7gehfvSM7FKGvjg7kmTE/86l8V4tWZviqUg9EhtGkiK9kt5dyzIuijqG wq+DXYZLqAfxBIR8X9aoC19+Q3LhRPyqilOWzJze9tn0dDFANmviTuwVt0hR011WunDC 8UPIqBV0IpYgPOu+7/bk2y4r4p/6VWDEJN67xVpvc6K0D9psGiZC27sNiHBxGNMt6JUt zPRw== X-Gm-Message-State: AOAM532N0aUIloUq9kl1C0Eju54j6h9Qded5F92s+R2eqPawCGJn6A+x 9O0hB//RTblQsRhnhg9YyXNdKza/ X-Google-Smtp-Source: ABdhPJwq30xAj5HqbHGPIW0K1nJfoJ06uduF7FKN7SCvz9wq0pYJd1CiyGAs37fIrh8gc2YB/HEjxg== X-Received: by 2002:a7b:c212:: with SMTP id x18mr8643636wmi.119.1592148298446; Sun, 14 Jun 2020 08:24:58 -0700 (PDT) Received: from powell.devork.be (2a02-8388-8480-1180-4c18-fc69-8d8c-22b5.cable.dynamic.v6.surfer.at. [2a02:8388:8480:1180:4c18:fc69:8d8c:22b5]) by smtp.gmail.com with ESMTPSA id s72sm18327915wme.35.2020.06.14.08.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 08:24:57 -0700 (PDT) Received: (nullmailer pid 57336 invoked by uid 1000); Sun, 14 Jun 2020 15:24:57 -0000 From: Floris Bruynooghe To: notmuch@notmuchmail.org Subject: [PATCH] Support aborting the atomic context Date: Sun, 14 Jun 2020 17:23:19 +0200 Message-Id: <20200614152319.57064-2-flub@devork.be> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614152319.57064-1-flub@devork.be> References: <20200614152319.57064-1-flub@devork.be> MIME-Version: 1.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: notmuch-bounces@notmuchmail.org Sender: "notmuch" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=PuQFAAsh; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 50.126.95.6 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 2.49 X-TUID: 8SCKMIB52aYc Since it is possible to use an atomic context to abort a number of changes support this usage. Because the only way to actually abort the transaction is to close the database this must also do so. --- bindings/python-cffi/notmuch2/_database.py | 16 +++++++++++++++- bindings/python-cffi/tests/test_database.py | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py index 95f59ca0..c851f0a5 100644 --- a/bindings/python-cffi/notmuch2/_database.py +++ b/bindings/python-cffi/notmuch2/_database.py @@ -641,6 +641,7 @@ class AtomicContext: def __init__(self, db, ptr_name): self._db = db self._ptr = lambda: getattr(db, ptr_name) + self._exit_fn = lambda: None def __del__(self): self._destroy() @@ -656,13 +657,17 @@ class AtomicContext: ret = capi.lib.notmuch_database_begin_atomic(self._ptr()) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + self._exit_fn = self._end_atomic return self - def __exit__(self, exc_type, exc_value, traceback): + def _end_atomic(self): ret = capi.lib.notmuch_database_end_atomic(self._ptr()) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + def __exit__(self, exc_type, exc_value, traceback): + self._exit_fn() + def force_end(self): """Force ending the atomic section. @@ -681,6 +686,15 @@ class AtomicContext: if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + def abort(self): + """Abort the transaction. + + Aborting a transaction will not commit any of the changes, but + will also implicitly close the database. + """ + self._exit_fn = lambda: None + self._db.close() + @functools.total_ordering class DbRevision: diff --git a/bindings/python-cffi/tests/test_database.py b/bindings/python-cffi/tests/test_database.py index e3a8344d..aa2cbdc7 100644 --- a/bindings/python-cffi/tests/test_database.py +++ b/bindings/python-cffi/tests/test_database.py @@ -127,6 +127,11 @@ class TestAtomic: with pytest.raises(errors.UnbalancedAtomicError): ctx.force_end() + def test_abort(self, db): + with db.atomic() as txn: + txn.abort() + assert db.closed + class TestRevision: -- 2.27.0