예제 #1
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) GetSrvKeyspace(ctx context.Context, keyspace string) (*topopb.SrvKeyspace, error) {
	request := &pb.GetSrvKeyspaceRequest{
		Keyspace: keyspace,
	}
	response := &pb.GetSrvKeyspaceResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.GetSrvKeyspace", request, response); err != nil {
		return nil, vterrors.FromJSONError(err)
	}
	return response.SrvKeyspace, nil
}
예제 #2
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) Rollback2(ctx context.Context, session interface{}) error {
	s := session.(*pb.Session)
	request := &pb.RollbackRequest{
		CallerId: callerid.EffectiveCallerIDFromContext(ctx),
		Session:  s,
	}
	response := &pb.RollbackResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.Rollback", request, response); err != nil {
		return vterrors.FromJSONError(err)
	}
	return nil
}
예제 #3
0
파일: conn.go 프로젝트: xgwubin/vitess
func sendStreamResults(c *rpcplus.Call, sr chan *qpb.QueryResult) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) {
	srout := make(chan *mproto.QueryResult, 1)
	go func() {
		defer close(srout)
		for r := range sr {
			srout <- mproto.Proto3ToQueryResult(r)
		}
	}()
	errFunc := func() error {
		return vterrors.FromJSONError(c.Error)
	}
	return srout, errFunc, nil
}
예제 #4
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) SplitQuery(ctx context.Context, keyspace string, query string, bindVars map[string]interface{}, splitColumn string, splitCount int) ([]proto.SplitQueryPart, error) {
	request := &pb.SplitQueryRequest{
		CallerId:    callerid.EffectiveCallerIDFromContext(ctx),
		Keyspace:    keyspace,
		Query:       tproto.BoundQueryToProto3(query, bindVars),
		SplitColumn: splitColumn,
		SplitCount:  int64(splitCount),
	}
	response := &pb.SplitQueryResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.SplitQuery", request, response); err != nil {
		return nil, vterrors.FromJSONError(err)
	}
	return proto.ProtoToSplitQueryParts(response), nil
}
예제 #5
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) Begin2(ctx context.Context) (interface{}, error) {
	request := &pb.BeginRequest{
		CallerId: callerid.EffectiveCallerIDFromContext(ctx),
	}
	response := &pb.BeginResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.Begin", request, response); err != nil {
		return nil, vterrors.FromJSONError(err)
	}
	// Return a non-nil pointer
	session := &pb.Session{}
	if response.Session != nil {
		session = response.Session
	}
	return session, nil
}
예제 #6
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topopb.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
	var s *pb.Session
	if session != nil {
		s = session.(*pb.Session)
	}
	request := &pb.ExecuteRequest{
		CallerId:         callerid.EffectiveCallerIDFromContext(ctx),
		Session:          s,
		Query:            tproto.BoundQueryToProto3(query, bindVars),
		TabletType:       tabletType,
		NotInTransaction: notInTransaction,
	}
	response := &pb.ExecuteResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.Execute", request, response); err != nil {
		return nil, session, vterrors.FromJSONError(err)
	}
	if response.Error != nil {
		return nil, response.Session, vterrors.FromVtRPCError(response.Error)
	}
	return mproto.Proto3ToQueryResult(response.Result), response.Session, nil
}
예제 #7
0
파일: conn.go 프로젝트: xgwubin/vitess
func (conn *vtgateConn) ExecuteBatchKeyspaceIds(ctx context.Context, queries []proto.BoundKeyspaceIdQuery, tabletType topopb.TabletType, asTransaction bool, session interface{}) ([]mproto.QueryResult, interface{}, error) {
	var s *pb.Session
	if session != nil {
		s = session.(*pb.Session)
	}
	request := &pb.ExecuteBatchKeyspaceIdsRequest{
		CallerId:      callerid.EffectiveCallerIDFromContext(ctx),
		Session:       s,
		Queries:       proto.BoundKeyspaceIdQueriesToProto(queries),
		TabletType:    tabletType,
		AsTransaction: asTransaction,
	}
	response := &pb.ExecuteBatchKeyspaceIdsResponse{}
	if err := conn.rpcConn.Call(ctx, "VTGateP3.ExecuteBatchKeyspaceIds", request, response); err != nil {
		return nil, session, vterrors.FromJSONError(err)
	}
	if response.Error != nil {
		return nil, response.Session, vterrors.FromVtRPCError(response.Error)
	}
	return mproto.Proto3ToQueryResults(response.Results), response.Session, nil
}