Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client support for non-leader connections #333

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cole-miller
Copy link
Contributor

@cole-miller cole-miller commented Oct 2, 2024

This is the go-dqlite counterpart of canonical/dqlite#709, tests are expected to fail since that hasn't merged. We expose the new functionality with a query parameter in the filename passed to OpenConnector. The usage is

connector := dqlitedriver.OpenConnector("file:my_db_name?dqlite_direct=TARGET")
conn, err := connector.Connect(ctx)
// conn is a database/sql/driver.Conn, needs some type-asserting to use

This gives you a usable connection to the node with address TARGET, which need not be the leader. You can prepare statements and run queries.

Signed-off-by: Cole Miller [email protected]

Signed-off-by: Cole Miller <[email protected]>
Signed-off-by: Cole Miller <[email protected]>
Signed-off-by: Cole Miller <[email protected]>
@sabaini
Copy link

sabaini commented Oct 8, 2024

Would this API make it possible to force leader reads for specific queries?

@cole-miller
Copy link
Contributor Author

@sabaini With the current state of the PR you'd have to store two DB connections, a "normal" one that talks to the currrent leader and a special one created using the new API that talks to a specific (possibly non-leader) node. I've implemented it this way because go-dqlite is built on a model where one DB connection = one network connection to a dqlite server; moving away from that would introduce a lot more complexity, especially with the database/sql connection pool in the mix.

@cole-miller cole-miller marked this pull request as ready for review October 16, 2024 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants