本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.ProtoToTabletType函数的典型用法代码示例。如果您正苦于以下问题:Golang ProtoToTabletType函数的具体用法?Golang ProtoToTabletType怎么用?Golang ProtoToTabletType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ProtoToTabletType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExecuteEntityIds
func (conn *vtgateConn) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*pbg.ExecuteEntityIdsRequest_EntityId, bindVars map[string]interface{}, tabletType pb.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
var s *proto.Session
if session != nil {
s = session.(*proto.Session)
}
request := proto.EntityIdsQuery{
CallerID: getEffectiveCallerID(ctx),
Sql: query,
BindVariables: bindVars,
Keyspace: keyspace,
EntityColumnName: entityColumnName,
EntityKeyspaceIDs: proto.ProtoToEntityIds(entityKeyspaceIDs),
TabletType: topo.ProtoToTabletType(tabletType),
Session: s,
NotInTransaction: notInTransaction,
}
var result proto.QueryResult
if err := conn.rpcConn.Call(ctx, "VTGate.ExecuteEntityIds", request, &result); err != nil {
return nil, session, err
}
if err := vterrors.FromRPCError(result.Err); err != nil {
return nil, result.Session, err
}
return result.Result, result.Session, nil
}
示例2: getKeyspaceShards
func getKeyspaceShards(ctx context.Context, topoServ SrvTopoServer, cell, keyspace string, tabletType pb.TabletType) (string, *topo.SrvKeyspace, []topo.ShardReference, error) {
srvKeyspace, err := topoServ.GetSrvKeyspace(ctx, cell, keyspace)
if err != nil {
return "", nil, nil, vterrors.NewVitessError(
vtrpc.ErrorCode_INTERNAL_ERROR, err,
"keyspace %v fetch error: %v", keyspace, err,
)
}
// check if the keyspace has been redirected for this tabletType.
tt := topo.ProtoToTabletType(tabletType)
if servedFrom, ok := srvKeyspace.ServedFrom[tt]; ok {
keyspace = servedFrom
srvKeyspace, err = topoServ.GetSrvKeyspace(ctx, cell, keyspace)
if err != nil {
return "", nil, nil, vterrors.NewVitessError(
vtrpc.ErrorCode_INTERNAL_ERROR, err,
"keyspace %v fetch error: %v", keyspace, err,
)
}
}
partition, ok := srvKeyspace.Partitions[tt]
if !ok {
return "", nil, nil, vterrors.NewVitessError(
vtrpc.ErrorCode_INTERNAL_ERROR, err,
"No partition found for tabletType %v in keyspace %v", strings.ToLower(tabletType.String()), keyspace,
)
}
return keyspace, srvKeyspace, partition.ShardReferences, nil
}
示例3: StreamExecute
// StreamExecute is part of the VTGateService interface
func (f *fakeVTGateService) StreamExecute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType pb.TabletType, sendReply func(*proto.QueryResult) error) error {
execCase, ok := execMap[sql]
if !ok {
return fmt.Errorf("no match for: %s", sql)
}
query := &proto.Query{
Sql: sql,
BindVariables: bindVariables,
TabletType: topo.ProtoToTabletType(tabletType),
}
if !reflect.DeepEqual(query, execCase.execQuery) {
return fmt.Errorf("request mismatch: got %+v, want %+v", query, execCase.execQuery)
}
if execCase.reply.Result != nil {
result := proto.QueryResult{Result: &mproto.QueryResult{}}
result.Result.Fields = execCase.reply.Result.Fields
if err := sendReply(&result); err != nil {
return err
}
for _, row := range execCase.reply.Result.Rows {
result := proto.QueryResult{Result: &mproto.QueryResult{}}
result.Result.Rows = [][]sqltypes.Value{row}
if err := sendReply(&result); err != nil {
return err
}
}
}
if execCase.reply.Error != "" {
return errors.New(execCase.reply.Error)
}
return nil
}
示例4: ChangeType
func (s *server) ChangeType(ctx context.Context, request *pb.ChangeTypeRequest) (*pb.ChangeTypeResponse, error) {
ctx = callinfo.GRPCCallInfo(ctx)
response := &pb.ChangeTypeResponse{}
return response, s.agent.RPCWrapLockAction(ctx, actionnode.TabletActionChangeType, request, response, true, func() error {
return s.agent.ChangeType(ctx, topo.ProtoToTabletType(request.TabletType))
})
}
示例5: ExecuteBatchKeyspaceIds
// ExecuteBatchKeyspaceIds is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteBatchKeyspaceIds(ctx context.Context, request *pb.ExecuteBatchKeyspaceIdsRequest) (response *pb.ExecuteBatchKeyspaceIdsResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
query := &proto.KeyspaceIdBatchQuery{
Session: proto.ProtoToSession(request.Session),
Queries: proto.ProtoToBoundKeyspaceIdQueries(request.Queries),
TabletType: topo.ProtoToTabletType(request.TabletType),
AsTransaction: request.AsTransaction,
}
reply := new(proto.QueryResultList)
executeErr := vtg.server.ExecuteBatchKeyspaceIds(ctx, query, reply)
response = &pb.ExecuteBatchKeyspaceIdsResponse{
Error: vtgate.VtGateErrorToVtRPCError(executeErr, reply.Error),
}
if executeErr == nil {
response.Results = tproto.QueryResultListToProto3(reply.List)
response.Session = proto.SessionToProto(reply.Session)
return response, nil
}
if *vtgate.RPCErrorOnlyInReply {
return response, nil
}
return nil, executeErr
}
示例6: ExecuteKeyspaceIds
// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest) (response *pb.ExecuteKeyspaceIdsResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
query := &proto.KeyspaceIdQuery{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
Keyspace: request.Keyspace,
KeyspaceIds: key.ProtoToKeyspaceIds(request.KeyspaceIds),
TabletType: topo.ProtoToTabletType(request.TabletType),
Session: proto.ProtoToSession(request.Session),
NotInTransaction: request.NotInTransaction,
}
reply := new(proto.QueryResult)
executeErr := vtg.server.ExecuteKeyspaceIds(ctx, query, reply)
response = &pb.ExecuteKeyspaceIdsResponse{
Error: vtgate.VtGateErrorToVtRPCError(executeErr, reply.Error),
}
if executeErr == nil {
response.Result = mproto.QueryResultToProto3(reply.Result)
response.Session = proto.SessionToProto(reply.Session)
return response, nil
}
if *vtgate.RPCErrorOnlyInReply {
return response, nil
}
return nil, executeErr
}
示例7: ExecuteShards
// ExecuteShards is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteShards(ctx context.Context, request *pb.ExecuteShardsRequest) (response *pb.ExecuteShardsResponse, err error) {
defer vtg.server.HandlePanic(&err)
query := &proto.QueryShard{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
Keyspace: request.Keyspace,
Shards: request.Shards,
TabletType: topo.ProtoToTabletType(request.TabletType),
Session: proto.ProtoToSession(request.Session),
NotInTransaction: request.NotInTransaction,
}
reply := new(proto.QueryResult)
executeErr := vtg.server.ExecuteShard(ctx, query, reply)
response = &pb.ExecuteShardsResponse{
Error: vtgate.VtGateErrorToVtRPCError(executeErr, reply.Error),
}
if executeErr == nil {
response.Result = mproto.QueryResultToProto3(reply.Result)
response.Session = proto.SessionToProto(reply.Session)
return response, nil
}
if *vtgate.RPCErrorOnlyInReply {
return response, nil
}
return nil, executeErr
}
示例8: Execute
// Execute please see vtgateconn.Impl.Execute
func (conn *FakeVTGateConn) Execute(ctx context.Context, sql string, bindVars map[string]interface{}, tabletType pb.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
var s *proto.Session
if session != nil {
s = session.(*proto.Session)
}
query := &proto.Query{
Sql: sql,
BindVariables: bindVars,
TabletType: topo.ProtoToTabletType(tabletType),
Session: s,
NotInTransaction: notInTransaction,
}
response, ok := conn.execMap[query.Sql]
if !ok {
return nil, nil, fmt.Errorf("no match for: %s", query.Sql)
}
if !reflect.DeepEqual(query, response.execQuery) {
return nil, nil, fmt.Errorf(
"Execute: %+v, want %+v", query, response.execQuery)
}
var reply mproto.QueryResult
reply = *response.reply
if s != nil {
s = newSession(true, "test_keyspace", []string{}, pb.TabletType_MASTER)
}
return &reply, s, nil
}
示例9: ExecuteShards
func (conn *vtgateConn) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType pb.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
var s *proto.Session
if session != nil {
s = session.(*proto.Session)
}
request := proto.QueryShard{
CallerID: getEffectiveCallerID(ctx),
Sql: query,
BindVariables: bindVars,
Keyspace: keyspace,
Shards: shards,
TabletType: topo.ProtoToTabletType(tabletType),
Session: s,
NotInTransaction: notInTransaction,
}
var result proto.QueryResult
if err := conn.rpcConn.Call(ctx, "VTGate.ExecuteShard", request, &result); err != nil {
return nil, session, err
}
if result.Error != "" {
return nil, result.Session, errors.New(result.Error)
}
if err := vterrors.FromRPCError(result.Err); err != nil {
return nil, result.Session, err
}
return result.Result, result.Session, nil
}
示例10: RunHealthCheck
func (s *server) RunHealthCheck(ctx context.Context, request *pb.RunHealthCheckRequest) (*pb.RunHealthCheckResponse, error) {
ctx = callinfo.GRPCCallInfo(ctx)
response := &pb.RunHealthCheckResponse{}
return response, s.agent.RPCWrap(ctx, actionnode.TabletActionRunHealthCheck, request, response, func() error {
s.agent.RunHealthCheck(ctx, topo.ProtoToTabletType(request.TabletType))
return nil
})
}
示例11: StreamExecute2
func (conn *vtgateConn) StreamExecute2(ctx context.Context, query string, bindVars map[string]interface{}, tabletType pb.TabletType) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) {
req := &proto.Query{
CallerID: getEffectiveCallerID(ctx),
Sql: query,
BindVariables: bindVars,
TabletType: topo.ProtoToTabletType(tabletType),
Session: nil,
}
sr := make(chan *proto.QueryResult, 10)
c := conn.rpcConn.StreamGo("VTGate.StreamExecute2", req, sr)
return sendStreamResults(c, sr)
}
示例12: Find
// Find returns the transactionId, if any, for a session
func (session *SafeSession) Find(keyspace, shard string, tabletType pb.TabletType) int64 {
if session == nil {
return 0
}
tt := topo.ProtoToTabletType(tabletType)
session.mu.Lock()
defer session.mu.Unlock()
for _, shardSession := range session.ShardSessions {
if keyspace == shardSession.Keyspace && tt == shardSession.TabletType && shard == shardSession.Shard {
return shardSession.TransactionId
}
}
return 0
}
示例13: StreamExecute
// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Vitess_StreamExecuteServer) (err error) {
defer vtg.server.HandlePanic(&err)
query := &proto.Query{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
TabletType: topo.ProtoToTabletType(request.TabletType),
}
return vtg.server.StreamExecute(stream.Context(), query, func(value *proto.QueryResult) error {
return stream.Send(&pb.StreamExecuteResponse{
Result: mproto.QueryResultToProto3(value.Result),
})
})
}
示例14: StreamExecute
// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Vitess_StreamExecuteServer) (err error) {
defer vtg.server.HandlePanic(&err)
ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
query := &proto.Query{
Sql: string(request.Query.Sql),
BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
TabletType: topo.ProtoToTabletType(request.TabletType),
}
return vtg.server.StreamExecute(ctx, query, func(value *proto.QueryResult) error {
return stream.Send(&pb.StreamExecuteResponse{
Result: mproto.QueryResultToProto3(value.Result),
})
})
}
示例15: Execute
// Execute is part of the VTGateService interface
func (f *fakeVTGateService) Execute(ctx context.Context, sql string, bindVariables map[string]interface{}, tabletType pb.TabletType, session *proto.Session, notInTransaction bool, reply *proto.QueryResult) error {
execCase, ok := execMap[sql]
if !ok {
return fmt.Errorf("no match for: %s", sql)
}
query := &proto.Query{
Sql: sql,
BindVariables: bindVariables,
TabletType: topo.ProtoToTabletType(tabletType),
Session: session,
NotInTransaction: notInTransaction,
}
if !reflect.DeepEqual(query, execCase.execQuery) {
return fmt.Errorf("request mismatch: got %+v, want %+v", query, execCase.execQuery)
}
*reply = *execCase.reply
return nil
}