Example #1
0
File: cass.go Project: araddon/cass
// opens a cassandra connection
func (conn *CassandraConnection) Open(keyspace string) error {

	Log(DEBUG, "creating new cassandra connection ", conn.pool)
	tcpConn, err := net.Dial("tcp", conn.Server)
	if err != nil {
		return err
	}

	ts, err := thrift.NewTSocketConn(tcpConn)
	if err != nil || ts == nil {
		return fmt.Errorf("Failed opening thrift socket: %s %s", err, ts)
	}

	if ts == nil {
		return errors.New("No TSocket connection?")
	}

	// the TSocket implements interface TTransport
	trans := thrift.NewTFramedTransport(ts)

	// A previous version of this code called trans.Open() at this point, but it's already open

	protocolfac := thrift.NewTBinaryProtocolFactoryDefault()

	conn.Client = cassandra.NewCassandraClientFactory(trans, protocolfac)

	Log(DEBUG, " in conn.Open, how is client? ", conn.Client)

	ire, t3e := conn.Client.SetCqlVersion("3.0.0")
	if ire != nil || t3e != nil {
		Log(ERROR, ire, t3e)
		return fmt.Errorf("Failed in SetCqlVersion: %s %s", ire.Why, t3e)
	}
	return nil
}
Example #2
0
// opens a cassandra connection
func (conn *CassandraConnection) Open(keyspace string) error {

	Log(DEBUG, "creating new cassandra connection ", conn.pool)
	tcpConn, er := net.Dial("tcp", conn.Server)
	if er != nil {
		return er
	}
	ts, err := thrift.NewTSocketConn(tcpConn)
	if err != nil {
		return err
	}

	if ts == nil {
		return errors.New("No TSocket connection?")
	}

	// the TSocket implements interface TTransport
	trans := thrift.NewTFramedTransport(ts)
	trans.Open()

	protocolfac := thrift.NewTBinaryProtocolFactoryDefault()

	conn.Client = cassandra.NewCassandraClientFactory(trans, protocolfac)

	Log(DEBUG, " in conn.Open, how is client? ", conn.Client)

	ire, er := conn.Client.SetKeyspace(keyspace)
	if ire != nil || er != nil {
		// most likely this is because it hasn't been created yet, so we will
		// ignore for now, as SetKeyspace() is purely optional
		Log(ERROR, ire, er)
	}
	e, t3e := conn.Client.SetCqlVersion("3.0.0")
	if e != nil || t3e != nil {
		Log(ERROR, e, t3e)
	}
	return nil
}