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

database/sql: Support retrying on ErrBadConn in driver.Rows #21059

Closed
F21 opened this issue Jul 18, 2017 · 2 comments
Closed

database/sql: Support retrying on ErrBadConn in driver.Rows #21059

F21 opened this issue Jul 18, 2017 · 2 comments

Comments

@F21
Copy link

F21 commented Jul 18, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.9-beta2

What operating system and processor architecture are you using (go env)?

Windows 10 64-bit

I'd like to be able to return a ErrBadConn from my driver implementation of driver.Rows.Next().

The reason is that I want to add HA support for the Apache Phoenix/Avatica sql driver. With Avatica, you open a connection to the query server by generating a connection id, sending it to the server and then referencing all further operations with this id.

In HA mode, you'd have multiple Avatica servers using stick sessions or some other form of client routing sitting behind a load balancer. If we initially opened a connection against server 1 and it failed, we are able to open new connections to another server by returning driver.ErrBadConn in Open(), Exec(), Query(), Prepare(), Close(), Begin() and Ping(). However, in the case of the methods on driver.Rows that returns an error, it appears the database/sql package does not attempt to create or use another connection to try again.

With Avatica, it is able to signal in the response if the server we're connecting to requires us to recreate the state (for example, missing SQL statements, because the server we were previously talking to failed) to support HA. For example, it is able to signal this to use if we attempt to execute a prepared statement in driver.Stmt.Exec() or driver.Stmt.Query(). or fetch more rows in driver.Rows.Next().

In this case, if the server we're talking to previously fails, we need a new connection. However, there does not appear to be a way to signal this in driver.Rows.

It would be great if driver.Rows.Next() is able to ask database/sql to get or create a new connection if ErrBadConn is returned from those methods.

@F21 F21 changed the title database/sql: Support retrying on ErrBadConn in driver.Rows and driver.Stmt database/sql: Support retrying on ErrBadConn in driver.Rows Jul 18, 2017
@odeke-em
Copy link
Member

/cc @kardianos and @bradfitz
This is a proposal/feature request not a regression so I'll mark it for Go1.10.

@odeke-em odeke-em added this to the Go1.10 milestone Jul 21, 2017
@kardianos
Copy link
Contributor

@F21 I think it would be better for you to do this reconnecting behind the scenes and if you encounter a fundamental issue (dial fail to failover) set Rows.Err.

@golang golang locked and limited conversation to collaborators Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants