浏览代码

Merge pull request #761 from mark-i-m/master

Use correct CQL version even if `DisableInitialHostLookup` is true
Chris Bannister 9 年之前
父节点
当前提交
7b3e849109
共有 3 个文件被更改,包括 27 次插入1 次删除
  1. 1 0
      AUTHORS
  2. 16 0
      host_source.go
  3. 10 1
      session.go

+ 1 - 0
AUTHORS

@@ -74,5 +74,6 @@ Sarah Brown <esbie.is@gmail.com>
 Caleb Doxsey <caleb@datadoghq.com>
 Frederic Hemery <frederic.hemery@datadoghq.com>
 Pekka Enberg <penberg@scylladb.com>
+Mark M <m.mim95@gmail.com>
 Bartosz Burclaf <burclaf@gmail.com>
 Marcus King <marcusking01@gmail.com>

+ 16 - 0
host_source.go

@@ -272,6 +272,22 @@ func checkSystemLocal(control *controlConn) (bool, error) {
 	return true, nil
 }
 
+// Returns true if we are using system_schema.keyspaces instead of system.schema_keyspaces
+func checkSystemSchema(control *controlConn) (bool, error) {
+	iter := control.query("SELECT * FROM system_schema.keyspaces")
+	if err := iter.err; err != nil {
+		if errf, ok := err.(*errorFrame); ok {
+			if errf.code == errReadFailure {
+				return false, nil
+			}
+		}
+
+		return false, err
+	}
+
+	return true, nil
+}
+
 func (r *ringDescriber) GetHosts() (hosts []*HostInfo, partitioner string, err error) {
 	r.mu.Lock()
 	defer r.mu.Unlock()

+ 10 - 1
session.go

@@ -195,7 +195,16 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 		return nil, ErrNoConnectionsStarted
 	}
 
-	s.useSystemSchema = hosts[0].Version().Major >= 3
+	// If we disable the initial host lookup, we need to still check if the
+	// cluster is using the newer system schema or not... however, if control
+	// connection is disable, we really have no choice, so we just make our
+	// best guess...
+	if !cfg.disableControlConn && cfg.DisableInitialHostLookup {
+		newer, _ := checkSystemSchema(s.control)
+		s.useSystemSchema = newer
+	} else {
+		s.useSystemSchema = hosts[0].Version().Major >= 3
+	}
 
 	return s, nil
 }