|
|
@@ -2,6 +2,7 @@ package gocql
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"net"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -38,10 +39,18 @@ func (c *cassVersion) Set(v string) error {
|
|
|
}
|
|
|
|
|
|
func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error {
|
|
|
+ return c.unmarshal(data)
|
|
|
+}
|
|
|
+
|
|
|
+func (c *cassVersion) unmarshal(data []byte) error {
|
|
|
version := strings.TrimSuffix(string(data), "-SNAPSHOT")
|
|
|
version = strings.TrimPrefix(version, "v")
|
|
|
v := strings.Split(version, ".")
|
|
|
|
|
|
+ if len(v) < 2 {
|
|
|
+ return fmt.Errorf("invalid version string: %s", data)
|
|
|
+ }
|
|
|
+
|
|
|
var err error
|
|
|
c.Major, err = strconv.Atoi(v[0])
|
|
|
if err != nil {
|
|
|
@@ -319,8 +328,16 @@ func (r *ringDescriber) GetHosts() (hosts []*HostInfo, partitioner string, err e
|
|
|
return r.prevHosts, r.prevPartitioner, nil
|
|
|
}
|
|
|
|
|
|
- host := &HostInfo{port: r.session.cfg.Port}
|
|
|
- for iter.Scan(&host.peer, &host.dataCenter, &host.rack, &host.hostId, &host.tokens, &host.version) {
|
|
|
+ var (
|
|
|
+ host = &HostInfo{port: r.session.cfg.Port}
|
|
|
+ versionBytes []byte
|
|
|
+ )
|
|
|
+ for iter.Scan(&host.peer, &host.dataCenter, &host.rack, &host.hostId, &host.tokens, &versionBytes) {
|
|
|
+ if err = host.version.unmarshal(versionBytes); err != nil {
|
|
|
+ log.Printf("invalid peer entry: peer=%s host_id=%s tokens=%v version=%s\n", host.peer, host.hostId, host.tokens, versionBytes)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
if r.matchFilter(host) {
|
|
|
hosts = append(hosts, host)
|
|
|
}
|