// from nested map create mutation map thrift struct func makeMutationMap(cf string, mutate map[string]map[string]string, timestamp int64) (mutationMap thrift.TMap) { mutationMap = thrift.NewTMap(thrift.STRING, thrift.MAP, len(mutate)) // len = # of keys(rows) for rowkey, cols := range mutate { colm := thrift.NewTMap(thrift.STRING, thrift.LIST, 1) // # of column families l := thrift.NewTList(thrift.STRUCT, 0) // auto-expands, starting length should be 0 columns := makeColumns(cols, timestamp) for i := 0; i < len(cols); i++ { cosc := cassandra.NewColumnOrSuperColumn() cosc.Column = &columns[i] mut := cassandra.NewMutation() mut.ColumnOrSupercolumn = cosc l.Push(mut) } // seems backwards, but.. row key on the outer map, cfname on inner colm.Set(cf, l) mutationMap.Set(rowkey, colm) } return }
func newWriter(cp *connectionPool, cl int) *writer { return &writer{ pool: cp, consistencyLevel: cl, writers: thrift.NewTMap(thrift.BINARY, thrift.MAP, 1), } }
func (r *LoginReq) GetCassAuthRequest() *cassandra.AuthenticationRequest { creds := thrift.NewTMap(thrift.STRING, thrift.STRING, 2) // key, value, size creds.Set("username", r.Username()) creds.Set("password", r.Password()) req := cassandra.NewAuthenticationRequest() req.Credentials = creds return req }
func (w *writer) addWriter(cf string, key []byte) *cassandra.Mutation { tm := cassandra.NewMutation() var cfMuts thrift.TMap im, exists := w.writers.Get(key) if !exists { cfMuts = thrift.NewTMap(thrift.STRING, thrift.LIST, 1) w.writers.Set(key, cfMuts) } else { cfMuts = im.(thrift.TMap) } var mutList thrift.TList im, exists = cfMuts.Get(cf) if !exists { mutList = thrift.NewTList(thrift.STRUCT, 1) cfMuts.Set(cf, mutList) } else { mutList = im.(thrift.TList) } mutList.Push(tm) return tm }
func newConnection(node, keyspace string, timeout int, authentication map[string]string) (*connection, error) { addr, err := net.ResolveTCPAddr("tcp", node) if err != nil { return nil, err } c := &connection{node: node} c.socket, err = thrift.NewTNonblockingSocketAddr(addr) if err != nil { return nil, err } // socket not open yet, so no error expected. it expects nanos, we have milis, so it's 1e6 c.socket.SetTimeout(int64(timeout) * 1e6) c.transport = thrift.NewTFramedTransport(c.socket) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() c.client = cassandra.NewCassandraClientFactory(c.transport, protocolFactory) // simulate timeout support for the underlying Dial() in .Open(). needless to say this sucks // restore sanity to this for Go v1 with the new DialTimeout() func ch := make(chan bool, 1) go func() { err = c.transport.Open() ch <- true }() timedOut := false select { case <-time.After(time.Duration(timeout) * time.Millisecond): timedOut = true case <-ch: } if timedOut { return nil, ErrorConnectionTimeout } if err != nil { return nil, err } version, err := c.client.DescribeVersion() if err != nil { c.close() return nil, err } versionComponents := strings.Split(version, ".") if len(versionComponents) < 1 { return nil, ErrorInvalidThriftVersion } majorVersion, err := strconv.Atoi(versionComponents[0]) if err != nil { return nil, ErrorInvalidThriftVersion } if majorVersion < LOWEST_COMPATIBLE_VERSION { return nil, ErrorWrongThriftVersion } if len(authentication) > 0 { ar := cassandra.NewAuthenticationRequest() ar.Credentials = thrift.NewTMap(thrift.STRING, thrift.STRING, 1) for k, v := range authentication { ar.Credentials.Set(k, v) } autE, auzE, err := c.client.Login(ar) if autE != nil { return nil, ErrorAuthenticationFailed } if auzE != nil { return nil, ErrorAuthorizationFailed } if err != nil { return nil, err } } ire, err := c.client.SetKeyspace(keyspace) if err != nil { c.close() return nil, err } if ire != nil { c.close() return nil, ErrorSetKeyspace } c.keyspace = keyspace return c, nil }