Skip to content

Commit

Permalink
Merge branch 'master' into add-instaclustr-password-authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
jfleming-ic committed Jul 4, 2023
2 parents 998c1d2 + a507dae commit 47b4098
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 14 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

### Fixed

## [1.5.2] - 2023-06-12

Same as 1.5.0. GitHub does not like gpg signed text in the tag message (even with prefixed armor),
so pushing a new tag.

## [1.5.1] - 2023-06-12

Same as 1.5.0. GitHub does not like gpg signed text in the tag message,
so pushing a new tag.

## [1.5.0] - 2023-06-12

### Added

- gocql now advertises the driver name and version in the STARTUP message to the server.
The values are taken from the Go module's path and version
(or from the replacement module, if used). (#1702)
That allows the server to track which fork of the driver is being used.
- Query.Values() to retrieve the values bound to the Query.
This makes writing wrappers around Query easier. (#1700)

### Fixed
- Potential panic on deserialization (#1695)
- Unmarshalling of dates outside of `[1677-09-22, 2262-04-11]` range. (#1692)
Expand Down
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ func (s *startupCoordinator) options(ctx context.Context) error {

func (s *startupCoordinator) startup(ctx context.Context, supported map[string][]string) error {
m := map[string]string{
"CQL_VERSION": s.conn.cfg.CQLVersion,
"CQL_VERSION": s.conn.cfg.CQLVersion,
"DRIVER_NAME": driverName,
"DRIVER_VERSION": driverVersion,
}

if s.conn.compressor != nil {
Expand Down
45 changes: 35 additions & 10 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (c *controlConn) setupConn(conn *Conn) error {
}

if err := c.registerEvents(conn); err != nil {
return err
return fmt.Errorf("register events: %v", err)
}

ch := &connHost{
Expand Down Expand Up @@ -347,6 +347,20 @@ func (c *controlConn) reconnect() {
}
defer atomic.StoreInt32(&c.reconnecting, 0)

conn, err := c.attemptReconnect()

if conn == nil {
c.session.logger.Printf("gocql: unable to reconnect control connection: %v\n", err)
return
}

err = c.session.refreshRing()
if err != nil {
c.session.logger.Printf("gocql: unable to refresh ring: %v\n", err)
}
}

func (c *controlConn) attemptReconnect() (*Conn, error) {
hosts := c.session.ring.allHosts()
hosts = shuffleHosts(hosts)

Expand All @@ -363,6 +377,25 @@ func (c *controlConn) reconnect() {
ch.conn.Close()
}

conn, err := c.attemptReconnectToAnyOfHosts(hosts)

if conn != nil {
return conn, err
}

c.session.logger.Printf("gocql: unable to connect to any ring node: %v\n", err)
c.session.logger.Printf("gocql: control falling back to initial contact points.\n")
// Fallback to initial contact points, as it may be the case that all known initialHosts
// changed their IPs while keeping the same hostname(s).
initialHosts, resolvErr := addrsToHosts(c.session.cfg.Hosts, c.session.cfg.Port, c.session.logger)
if resolvErr != nil {
return nil, fmt.Errorf("resolve contact points' hostnames: %v", resolvErr)
}

return c.attemptReconnectToAnyOfHosts(initialHosts)
}

func (c *controlConn) attemptReconnectToAnyOfHosts(hosts []*HostInfo) (*Conn, error) {
var conn *Conn
var err error
for _, host := range hosts {
Expand All @@ -379,15 +412,7 @@ func (c *controlConn) reconnect() {
conn.Close()
conn = nil
}
if conn == nil {
c.session.logger.Printf("gocql: control unable to register events: %v\n", err)
return
}

err = c.session.refreshRing()
if err != nil {
c.session.logger.Printf("gocql: unable to refresh ring: %v\n", err)
}
return conn, err
}

func (c *controlConn) HandleError(conn *Conn, err error, closed bool) {
Expand Down
3 changes: 3 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
// protocol version explicitly, as it's not defined which version will be used in certain situations (for example
// during upgrade of the cluster when some of the nodes support different set of protocol versions than other nodes).
//
// The driver advertises the module name and version in the STARTUP message, so servers are able to detect the version.
// If you use replace directive in go.mod, the driver will send information about the replacement module instead.
//
// When ready, create a session from the configuration. Don't forget to Close the session once you are done with it:
//
// session, err := cluster.CreateSession()
Expand Down
2 changes: 1 addition & 1 deletion host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ func refreshRing(r *ringDescriber) error {
if !ok {
return fmt.Errorf("get existing host=%s from prevHosts: %w", h, ErrCannotFindHost)
}
if h.nodeToNodeAddress().Equal(existing.nodeToNodeAddress()) {
if h.connectAddress.Equal(existing.connectAddress) && h.nodeToNodeAddress().Equal(existing.nodeToNodeAddress()) {
// no host IP change
host.update(h)
} else {
Expand Down
10 changes: 8 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ var queryPool = &sync.Pool{

func addrsToHosts(addrs []string, defaultPort int, logger StdLogger) ([]*HostInfo, error) {
var hosts []*HostInfo
for _, hostport := range addrs {
resolvedHosts, err := hostInfo(hostport, defaultPort)
for _, hostaddr := range addrs {
resolvedHosts, err := hostInfo(hostaddr, defaultPort)
if err != nil {
// Try other hosts if unable to resolve DNS name
if _, ok := err.(*net.DNSError); ok {
Expand Down Expand Up @@ -935,6 +935,12 @@ func (q Query) Statement() string {
return q.stmt
}

// Values returns the values passed in via Bind.
// This can be used by a wrapper type that needs to access the bound values.
func (q Query) Values() []interface{} {
return q.values
}

// String implements the stringer interface.
func (q Query) String() string {
return fmt.Sprintf("[query statement=%q values=%+v consistency=%s]", q.stmt, q.values, q.cons)
Expand Down
28 changes: 28 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gocql

import "runtime/debug"

const (
mainModule = "github.com/gocql/gocql"
)

var driverName string

var driverVersion string

func init() {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, d := range buildInfo.Deps {
if d.Path == mainModule {
driverName = mainModule
driverVersion = d.Version
if d.Replace != nil {
driverName = d.Replace.Path
driverVersion = d.Replace.Version
}
break
}
}
}
}

0 comments on commit 47b4098

Please sign in to comment.