Exemple #1
0
func newTestCluster(cluster_name string) (*cluster.Cluster, error) {
	if _, err := newTestServer(); err != nil {
		testCluster, testClusterError = nil, err
	}

	f := func() {
		testCluster, testClusterError = cluster.New(cluster_name)
	}

	testClusterOnce.Do(f)
	return testCluster, testClusterError
}
Exemple #2
0
func (session *Session) useDB(db string) error {

	if session.cluster != nil {
		if session.cluster.DBName != db {
			return mysql.NewDefaultError(mysql.ER_BAD_DB_ERROR, db)
		}

		return nil
	}

	if _, err := session.config.GetClusterByDBName(db); err != nil {
		return mysql.NewDefaultError(mysql.ER_BAD_DB_ERROR, db)
	} else if session.cluster, err = cluster.New(session.user.ClusterName); err != nil {
		return err
	}

	if session.bc == nil {
		master, err := session.cluster.Master()
		if err != nil {
			return mysql.NewDefaultError(mysql.ER_BAD_DB_ERROR, db)
		}
		slave, err := session.cluster.Slave()
		if err != nil {
			slave = master
		}
		session.bc = &SqlConn{
			master:  master,
			slave:   slave,
			stmts:   make(map[uint32]*mysql.Stmt),
			tx:      nil,
			session: session,
		}
	}

	return nil
}