samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can't use go-thrift to access hbase

skoowoo opened this issue · comments

thrift idl: http://wiki.apache.org/hadoop/Hbase/ThriftApi

server is writen by java. client use go-thrift to call a remote method will be blocked. the method can't return.

I found it in Go standard library:
// Call invokes the named function, waits for it to complete, and returns its error status.
func (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error {
call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).Done
return call.Error
}

client is blocked here. the length of the "Done" channel is 0, so will block here. But I don't know why the "Done" is empty.

Hope resolve it...
thx~

follow codes, I found the really block point is "ReadResponseHeader", the funtion can't return. Is the protocol wrong???

It's most likely that the server is expecting the framed transport, and the client is probably not setup to use it. Or, the other way around. Generally these sorts of issues are related to a mismatch in the transport.

You can try flipping the "framed" argument when creating the connection, or if you're creating the connection yourself then you can wrap it using thrift.NewFramedReadWriteCloser(rw)

conn, err := net.Dial("tcp", "xxxxxxxxxxxxx")
if err != nil {
    panic(err)
}

client := thrift.NewClient(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false))
cli := hbase.HbaseClient{client}

value := &hbase.Mutation{Column: []byte("cf:"), Value: []byte("aaaaaaaaaaaaaaaaaaaaaaaaaa")}

var vs []*hbase.Mutation
vs = append(vs, value)

println("start...")
err = cli.MutateRow([]byte("table"), []byte("abc"), vs, nil)
if err != nil {
    println(err)
}
println("end...")

it's my code.... I think that I have used the framed transport. Is it ok???

thx~

Oh.....the server is not using the framed transport, but client use it, so RPC blocked.

the API of go-thrift is wonderful, I like it.
thx~