Skip to content

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

@F21

Description

@F21

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions