From: Danny Milosavljevic <dannym@scratchpost.org>
To: "Ludovic Courtès" <ludo@gnu.org>,
"Caleb Ristvedt" <caleb.ristvedt@cune.org>
Cc: 41658@debbugs.gnu.org
Subject: [bug#41658] [PATCH] fixes / improvements for (guix store database)
Date: Thu, 4 Jun 2020 19:00:40 +0200 [thread overview]
Message-ID: <20200604190000.3c454a83@scratchpost.org> (raw)
In-Reply-To: <87a71i943g.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]
Hi Ludo,
Hi Caleb,
On Thu, 04 Jun 2020 18:40:35 +0200
Ludovic Courtès <ludo@gnu.org> wrote:
> Nice. It would be great if you could report it upstream (Danny and/or
> myself can then patch it directly in guile-sqlite3 and push out a
> release) and refer to the issue from here.
I agree. It's easy to change sqlite-finalize in guile-sqlite3 to
call sqlite-reset, basically just adapt
(define sqlite-finalize
(let ((f (pointer->procedure
int
(dynamic-func "sqlite3_finalize" libsqlite3)
(list '*))))
(lambda (stmt)
;; Note: When STMT is cached, this is a no-op. This ensures caching
;; actually works while still separating concerns: users can turn
;; caching on and off without having to change the rest of their code.
(when (and (stmt-live? stmt)
(not (stmt-cached? stmt)))
(let ((p (stmt-pointer stmt)))
(sqlite-remove-statement! (stmt->db stmt) stmt)
(set-stmt-live?! stmt #f)
(f p))))))
so that it calls sqlite-reset in the "when"'s new "else" branch there.
(we could also always call sqlite3_reset on sqlite-finalize anyway, it wouldn't
hurt but it wouldn't help either)
I agree that sqlite-finalize should model sqlite's finalization behavior as
much as possible.
Also, the comment about this being a no-op is not true then anymore.
We should definitely also pick up Caleb's comment upstream:
+ ;; Cached statements aren't reset when sqlite-finalize is invoked on
+ ;; them. This can cause problems with automatically-started transactions:
+ ;;
+ ;; "An implicit transaction (a transaction that is started automatically,
+ ;; not a transaction started by BEGIN) is committed automatically when the
+ ;; last active statement finishes. A statement finishes when its last cursor
+ ;; closes, which is guaranteed to happen when the prepared statement is
+ ;; reset or finalized. Some statements might "finish" for the purpose of
+ ;; transaction control prior to being reset or finalized, but there is no
+ ;; guarantee of this."
+ ;;
+ ;; Thus, it's possible for an implicitly-started transaction to hang around
+ ;; until sqlite-reset is called when the cached statement is next
+ ;; used. Because the transaction is committed automatically only when the
+ ;; *last active statement* finishes, the implicitly-started transaction may
+ ;; later be upgraded to a write transaction (!) and this non-reset statement
+ ;; will still be keeping the transaction from committing until it is next
+ ;; used or the database connection is closed. This has the potential to make
+ ;; (exclusive) write access to the database necessary for much longer than
+ ;; it should be.
+ ;;
+ ;; (see https://www.sqlite.org/lang_transaction.html)
@Caleb:
Could you file an issue at https://notabug.org/guile-sqlite3/guile-sqlite3/issues
and pull request so this is auditable?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-06-04 17:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 6:31 [bug#41658] [PATCH] fixes / improvements for (guix store database) Caleb Ristvedt
2020-06-04 16:40 ` Ludovic Courtès
2020-06-04 17:00 ` Danny Milosavljevic [this message]
2020-06-05 16:19 ` Ludovic Courtès
2020-06-08 5:52 ` Caleb Ristvedt
2020-06-09 8:42 ` Ludovic Courtès
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://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200604190000.3c454a83@scratchpost.org \
--to=dannym@scratchpost.org \
--cc=41658@debbugs.gnu.org \
--cc=caleb.ristvedt@cune.org \
--cc=ludo@gnu.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://git.savannah.gnu.org/cgit/guix.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).