Pārlūkot izejas kodu

Stop retrying to connect on permanent failure

Minor change to the connection pool code that uses the *net.OpError type
to pull of retrying to connect to a host if the error is a permanent
erorr.

Reduces startup time on creating a new sesession when we try to
establish a connection using gocql that does not have visibility to the
host.

Performance improvement easily reproduced when using default cassandra
docker container with gocql.
Michael Highstead 9 gadi atpakaļ
vecāks
revīzija
6e5ecf85b5
2 mainītis faili ar 8 papildinājumiem un 0 dzēšanām
  1. 1 0
      AUTHORS
  2. 7 0
      connectionpool.go

+ 1 - 0
AUTHORS

@@ -69,3 +69,4 @@ Alexander Inozemtsev <alexander.inozemtsev@gmail.com>
 Rob McColl <rob@robmccoll.com>; <rmccoll@ionicsecurity.com>
 Viktor Tönköl <viktor.toenkoel@motionlogic.de>
 Ian Lozinski <ian.lozinski@gmail.com>
+Michael Highstead <highstead@gmail.com>

+ 7 - 0
connectionpool.go

@@ -481,6 +481,13 @@ func (pool *hostConnPool) connect() (err error) {
 		if err == nil {
 			break
 		}
+		if opErr, isOpErr := err.(*net.OpError); isOpErr {
+			// if the error is not a temporary error (ex: network unreachable) don't
+			//  retry
+			if !opErr.Temporary() {
+				break
+			}
+		}
 	}
 
 	if err != nil {