Conversation
cursor() is another connection to the same database, made from a connection rather than from a path, which is how a pool is written. duplicate() is the same call under the name that says what it does; cursor() is what every other embedded database calls it and a caller who learned the word elsewhere should not have to learn another one here. It forks off the database the connection already holds rather than opening the file again, so it costs a schema load and no path lookup, and it works on a database in memory, where there is no path to open a second time. Each of the two has its own prepared statements, its own caches and its own transaction, and closing one does not close the other. What they share is the write side. On an event loop it is awaited and the new connection gets a thread of its own, which is the point: one connection runs one statement at a time, so two results in flight means two connections. In zudb.dbapi the name is duplicate() alone, because cursor() there is the thing PEP 249 means by it.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Milestone tamnd/zu#169, item 6:
cursor()in both clients, which is how a pool is written. The engine half is tamnd/zu#409, and this pins it.conn.cursor()gives back anotherzudb.Connectionon the same database.conn.duplicate()is the same call under the name that says what it does. Two names becausecursor()is what every other embedded database calls this and a caller who learned the word elsewhere should not have to learn another one, while a reader of this code who has not should not have to guess.It forks off the database the connection already holds rather than opening the file again, so it costs a schema load and no path lookup, and it works on a database in memory, where there is no path to open a second time. That was the gap worth closing: a pool that seeds itself and lets the first connection go had no way to a second one at all.
The two are connections in every sense rather than two names for one. Each has its own prepared statements, its own caches and its own transaction, so a thread taking one from a pool is not in whatever transaction the last borrower left open, and closing one does not close the other. What they share is the write side, so they queue behind each other to write and each sees what the other has committed.
On an event loop
conn.cursor()is awaited, because forking reaches the engine, and the new connection gets a thread of its own, which is the point: one connection runs one statement at a time, so two results in flight means two connections. There is a test that gathers two statements on the two of them.In
zudb.dbapithe name isduplicate()alone.cursor()there is the thing PEP 249 means by it, which shares its connection and its transaction rather than making new ones, and the two are worth keeping apart in a docstring as well as in the code. A duplicate carriesautocommitacross and starts outside a transaction.Twelve tests: the pool case both ways, the properties carried across, a duplicate outliving the connection it was made from, a transaction of its own, a closed connection refusing, the async pair running at once, the DB-API pair, and the README program.
ruff check,ruff format --check,cargo clippy --all-targets -- -D warnings,cargo fmt --checkandpytestall green locally.