|
@@ -9,8 +9,8 @@ import (
|
|
|
"encoding/binary"
|
|
"encoding/binary"
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "golang.org/x/net/context"
|
|
|
|
|
"io"
|
|
"io"
|
|
|
|
|
+ "log"
|
|
|
"net"
|
|
"net"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
"strings"
|
|
"strings"
|
|
@@ -19,6 +19,8 @@ import (
|
|
|
"time"
|
|
"time"
|
|
|
"unicode"
|
|
"unicode"
|
|
|
|
|
|
|
|
|
|
+ "golang.org/x/net/context"
|
|
|
|
|
+
|
|
|
"github.com/gocql/gocql/internal/lru"
|
|
"github.com/gocql/gocql/internal/lru"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -175,6 +177,10 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if cfg.ReconnectInterval > 0 {
|
|
|
|
|
+ go s.reconnectDownedHosts(cfg.ReconnectInterval)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// TODO(zariel): we probably dont need this any more as we verify that we
|
|
// TODO(zariel): we probably dont need this any more as we verify that we
|
|
|
// can connect to one of the endpoints supplied by using the control conn.
|
|
// can connect to one of the endpoints supplied by using the control conn.
|
|
|
// See if there are any connections in the pool
|
|
// See if there are any connections in the pool
|
|
@@ -188,6 +194,30 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
|
|
|
return s, nil
|
|
return s, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (s *Session) reconnectDownedHosts(intv time.Duration) {
|
|
|
|
|
+ for !s.Closed() {
|
|
|
|
|
+ time.Sleep(intv)
|
|
|
|
|
+
|
|
|
|
|
+ hosts := s.ring.allHosts()
|
|
|
|
|
+
|
|
|
|
|
+ // Print session.ring for debug.
|
|
|
|
|
+ if gocqlDebug {
|
|
|
|
|
+ buf := bytes.NewBufferString("Session.ring:")
|
|
|
|
|
+ for _, h := range hosts {
|
|
|
|
|
+ buf.WriteString("[" + h.Peer() + ":" + h.State().String() + "]")
|
|
|
|
|
+ }
|
|
|
|
|
+ log.Println(buf.String())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, h := range hosts {
|
|
|
|
|
+ if h.IsUp() {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ s.handleNodeUp(net.ParseIP(h.Peer()), h.Port(), true)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// SetConsistency sets the default consistency level for this session. This
|
|
// SetConsistency sets the default consistency level for this session. This
|
|
|
// setting can also be changed on a per-query basis and the default value
|
|
// setting can also be changed on a per-query basis and the default value
|
|
|
// is Quorum.
|
|
// is Quorum.
|