瀏覽代碼

Use a query instead of CQL version

mark 9 年之前
父節點
當前提交
f576e6db68
共有 2 個文件被更改,包括 23 次插入5 次删除
  1. 16 0
      host_source.go
  2. 7 5
      session.go

+ 16 - 0
host_source.go

@@ -272,6 +272,22 @@ func checkSystemLocal(control *controlConn) (bool, error) {
 	return true, nil
 	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) {
 func (r *ringDescriber) GetHosts() (hosts []*HostInfo, partitioner string, err error) {
 	r.mu.Lock()
 	r.mu.Lock()
 	defer r.mu.Unlock()
 	defer r.mu.Unlock()

+ 7 - 5
session.go

@@ -195,11 +195,13 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 		return nil, ErrNoConnectionsStarted
 		return nil, ErrNoConnectionsStarted
 	}
 	}
 
 
-	// If initial host lookup is disabled, then we should use the ClusterConfig CQL version
-	if cfg.DisableInitialHostLookup {
-		var v cassVersion
-		v.Set(cfg.CQLVersion)
-		s.useSystemSchema = v.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 {
 	} else {
 		s.useSystemSchema = hosts[0].Version().Major >= 3
 		s.useSystemSchema = hosts[0].Version().Major >= 3
 	}
 	}