FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-45040: Simplify `sqlite3` transaction control functions by erlend-aasland · Pull Request #28019 · python/cpython · GitHub

Repository navigation

bpo-45040: Simplify sqlite3 transaction control functions - #28019

Merged
pablogsal merged 1 commit into
python:mainfrom
erlend-aasland:sqlite-optimise-tx-fns
Sep 19, 2021
Merged

pablogsal merged 1 commit into
python:mainfrom
erlend-aasland:sqlite-optimise-tx-fns

Conversation

erlend-aasland commented Aug 28, 2021 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor
  • only save/restore thread state once pr. function
  • optimise SQLite C API usage
  • simplify error paths

https://bugs.python.org/issue45040

}

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_finalize(statement);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Seems that sqlite3_finalize was protected with the GIL previously and the check for PyErr_Occurred makes me thing that some callback or similar could end calling Python code. Could you confirm if this is indeed safe?

erlend-aasland Aug 30, 2021 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hm, sqlite3_finalize was called outside of the GIL previously, and it still is. Previously, we would release/acquire GIL before/after every SQLite API call; now we release, do all SQLite API calls, then acquire.

Previously

  1. allow threads (unlock GIL), prepare statement, disallow threads (lock GIL)
  2. raise exception and bail on error
  3. unlock GIL, execute SQL statement (sqlite3_step), lock GIL
  4. raise exception and "fall through" on error
  5. unlock GIL, finalise statement (release resources, etc.), lock GIL
  6. raise exception, unless sqlite3_step already did, on error => this is the extra PyErr_Occurred

Since sqlite3_finalize will pass on the error set by sqlite3_step, there is no need to check for errors after stepping. We only need to do it after finalising the statement.

Now

  1. unlock GIL, create, execute, and finalise SQL statement, lock GIL
  2. raise exception and bail on error

pablogsal Aug 30, 2021 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can sqlite3_finalize raise Python errors on its own (via cleanups, callbacks or otherwise)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not the way we currently use the SQLite API. If we'd added SQLite profile support, sqlite3_finalize (and other API's) would invoke our _trace_callback() C callback with argument type set to SQLITE_TRACE_PROFILE. We could add an assert(type != SQLITE_TRACE_PROFILE) and a comment about this to _trace_callback().

erlend-aasland added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 1, 2021

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @erlend-aasland for commit 0ec285a 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 1, 2021

erlend-aasland commented Sep 9, 2021 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

The AMD64 Arch Linux Asan Debug PR is unrelated to this PR.

Manually rerunning failed buildbots. See python/buildmaster-config#275

Copy link
Copy Markdown
Member

Thanks for the PR @erlend-aasland ! 🎉

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL