本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.TabletTypeToProto函数的典型用法代码示例。如果您正苦于以下问题:Golang TabletTypeToProto函数的具体用法?Golang TabletTypeToProto怎么用?Golang TabletTypeToProto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TabletTypeToProto函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Commit
// Commit commits the current transaction. There are no retries on this operation.
func (stc *ScatterConn) Commit(ctx context.Context, session *SafeSession) (err error) {
if session == nil {
return vterrors.FromError(
vtrpc.ErrorCode_BAD_INPUT,
fmt.Errorf("cannot commit: empty session"),
)
}
if !session.InTransaction() {
return vterrors.FromError(
vtrpc.ErrorCode_NOT_IN_TX,
fmt.Errorf("cannot commit: not in transaction"),
)
}
committing := true
for _, shardSession := range session.ShardSessions {
tabletType := topo.TabletTypeToProto(shardSession.TabletType)
if !committing {
stc.gateway.Rollback(ctx, shardSession.Keyspace, shardSession.Shard, tabletType, shardSession.TransactionId)
continue
}
if err = stc.gateway.Commit(ctx, shardSession.Keyspace, shardSession.Shard, tabletType, shardSession.TransactionId); err != nil {
committing = false
}
}
session.Reset()
return err
}
示例2: StreamExecuteKeyRanges2
// StreamExecuteKeyRanges2 is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecuteKeyRanges2(ctx context.Context, request *proto.KeyRangeQuery, sendReply func(interface{}) error) (err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(ctx,
callerid.GoRPCEffectiveCallerID(request.CallerID),
callerid.NewImmediateCallerID("gorpc client"))
vtgErr := vtg.server.StreamExecuteKeyRanges(ctx,
request.Sql,
request.BindVariables,
request.Keyspace,
key.KeyRangesToProto(request.KeyRanges),
topo.TabletTypeToProto(request.TabletType),
func(value *proto.QueryResult) error {
return sendReply(value)
})
if vtgErr == nil {
return nil
}
if *vtgate.RPCErrorOnlyInReply {
// If there was an app error, send a QueryResult back with it.
qr := new(proto.QueryResult)
vtgate.AddVtGateErrorToQueryResult(vtgErr, qr)
// Sending back errors this way is not backwards compatible. If a (new) server sends an additional
// QueryResult with an error, and the (old) client doesn't know how to read it, it will cause
// problems where the client will get out of sync with the number of QueryResults sent.
// That's why this the error is only sent this way when the --rpc_errors_only_in_reply flag is set
// (signalling that all clients are able to handle new-style errors).
return sendReply(qr)
}
return vtgErr
}
示例3: allowQueries
func (agent *ActionAgent) allowQueries(tablet *topo.Tablet, blacklistedTables []string) error {
// if the query service is already running, we're not starting it again
if agent.QueryServiceControl.IsServing() {
return nil
}
// only for real instances
if agent.DBConfigs != nil {
// Update our DB config to match the info we have in the tablet
if agent.DBConfigs.App.DbName == "" {
agent.DBConfigs.App.DbName = tablet.DbName()
}
agent.DBConfigs.App.Keyspace = tablet.Keyspace
agent.DBConfigs.App.Shard = tablet.Shard
if tablet.Type != topo.TYPE_MASTER {
agent.DBConfigs.App.EnableInvalidator = true
} else {
agent.DBConfigs.App.EnableInvalidator = false
}
}
err := agent.loadKeyspaceAndBlacklistRules(tablet, blacklistedTables)
if err != nil {
return err
}
return agent.QueryServiceControl.AllowQueries(&pb.Target{
Keyspace: tablet.Keyspace,
Shard: tablet.Shard,
TabletType: topo.TabletTypeToProto(tablet.Type),
}, agent.DBConfigs, agent.SchemaOverrides, agent.MysqlDaemon)
}
示例4: StreamExecuteKeyspaceIds
func (conn *vtgateConn) StreamExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds []key.KeyspaceId, bindVars map[string]interface{}, tabletType topo.TabletType) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) {
req := &pb.StreamExecuteKeyspaceIdsRequest{
Query: tproto.BoundQueryToProto3(query, bindVars),
Keyspace: keyspace,
KeyspaceIds: key.KeyspaceIdsToProto(keyspaceIds),
TabletType: topo.TabletTypeToProto(tabletType),
}
stream, err := conn.c.StreamExecuteKeyspaceIds(ctx, req)
if err != nil {
return nil, nil, err
}
sr := make(chan *mproto.QueryResult, 10)
var finalError error
go func() {
for {
ser, err := stream.Recv()
if err != nil {
if err != io.EOF {
finalError = err
}
close(sr)
return
}
if ser.Error != nil {
finalError = vterrors.FromVtRPCError(ser.Error)
close(sr)
return
}
sr <- mproto.Proto3ToQueryResult(ser.Result)
}
}()
return sr, func() error {
return finalError
}, nil
}
示例5: ChangeType
// ChangeType is part of the tmclient.TabletManagerClient interface
func (client *Client) ChangeType(ctx context.Context, tablet *topo.TabletInfo, dbType topo.TabletType) error {
cc, c, err := client.dial(ctx, tablet)
if err != nil {
return err
}
defer cc.Close()
_, err = c.ChangeType(ctx, &pb.ChangeTypeRequest{
TabletType: topo.TabletTypeToProto(dbType),
})
return err
}
示例6: Rollback
// Rollback rolls back the current transaction. There are no retries on this operation.
func (stc *ScatterConn) Rollback(ctx context.Context, session *SafeSession) (err error) {
if session == nil {
return nil
}
for _, shardSession := range session.ShardSessions {
tabletType := topo.TabletTypeToProto(shardSession.TabletType)
stc.gateway.Rollback(ctx, shardSession.Keyspace, shardSession.Shard, tabletType, shardSession.TransactionId)
}
session.Reset()
return nil
}
示例7: RunHealthCheck
// RunHealthCheck is part of the tmclient.TabletManagerClient interface
func (client *Client) RunHealthCheck(ctx context.Context, tablet *topo.TabletInfo, targetTabletType topo.TabletType) error {
cc, c, err := client.dial(ctx, tablet)
if err != nil {
return err
}
defer cc.Close()
_, err = c.RunHealthCheck(ctx, &pb.RunHealthCheckRequest{
TabletType: topo.TabletTypeToProto(targetTabletType),
})
return err
}
示例8: GetEndPoints
// GetEndPoints returns addresses for a tablet type in a shard
// in a keyspace.
func (tr *TopoReader) GetEndPoints(ctx context.Context, req *topo.GetEndPointsArgs, reply *pb.EndPoints) (err error) {
tr.queryCount.Add(req.Cell, 1)
addrs, _, err := tr.ts.GetEndPoints(ctx, req.Cell, req.Keyspace, req.Shard, topo.TabletTypeToProto(req.TabletType))
if err != nil {
log.Warningf("GetEndPoints(%v,%v,%v,%v) failed: %v", req.Cell, req.Keyspace, req.Shard, req.TabletType, err)
tr.errorCount.Add(req.Cell, 1)
return err
}
*reply = *addrs
return nil
}
示例9: StreamExecute
// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(ctx context.Context, request *proto.Query, sendReply func(interface{}) error) (err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(ctx,
callerid.GoRPCEffectiveCallerID(request.CallerID),
callerid.NewImmediateCallerID("gorpc client"))
return vtg.server.StreamExecute(ctx,
request.Sql,
request.BindVariables,
topo.TabletTypeToProto(request.TabletType),
func(value *proto.QueryResult) error {
return sendReply(value)
})
}
示例10: ExecuteBatchKeyspaceIds
// ExecuteBatchKeyspaceIds is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteBatchKeyspaceIds(ctx context.Context, request *proto.KeyspaceIdBatchQuery, reply *proto.QueryResultList) (err error) {
defer vtg.server.HandlePanic(&err)
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout))
defer cancel()
ctx = callerid.NewContext(ctx,
callerid.GoRPCEffectiveCallerID(request.CallerID),
callerid.NewImmediateCallerID("gorpc client"))
vtgErr := vtg.server.ExecuteBatchKeyspaceIds(ctx,
request.Queries,
topo.TabletTypeToProto(request.TabletType),
request.AsTransaction,
request.Session,
reply)
vtgate.AddVtGateError(vtgErr, &reply.Err)
return nil
}
示例11: Execute
// Execute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) Execute(ctx context.Context, request *proto.Query, reply *proto.QueryResult) (err error) {
defer vtg.server.HandlePanic(&err)
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout))
defer cancel()
ctx = callerid.NewContext(ctx,
callerid.GoRPCEffectiveCallerID(request.CallerID),
callerid.NewImmediateCallerID("gorpc client"))
vtgErr := vtg.server.Execute(ctx,
request.Sql,
request.BindVariables,
topo.TabletTypeToProto(request.TabletType),
request.Session,
request.NotInTransaction,
reply)
vtgate.AddVtGateErrorToQueryResult(vtgErr, reply)
if *vtgate.RPCErrorOnlyInReply {
return nil
}
return vtgErr
}
示例12: Execute
func (conn *vtgateConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topo.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) {
var s *pb.Session
if session != nil {
s = session.(*pb.Session)
}
request := &pb.ExecuteRequest{
Session: s,
Query: tproto.BoundQueryToProto3(query, bindVars),
TabletType: topo.TabletTypeToProto(tabletType),
NotInTransaction: notInTransaction,
}
response, err := conn.c.Execute(ctx, request)
if err != nil {
return nil, session, err
}
if response.Error != nil {
return nil, response.Session, vterrors.FromVtRPCError(response.Error)
}
return mproto.Proto3ToQueryResult(response.Result), response.Session, nil
}
示例13: ExecuteBatchKeyspaceIds
func (conn *vtgateConn) ExecuteBatchKeyspaceIds(ctx context.Context, queries []proto.BoundKeyspaceIdQuery, tabletType topo.TabletType, asTransaction bool, session interface{}) ([]mproto.QueryResult, interface{}, error) {
var s *pb.Session
if session != nil {
s = session.(*pb.Session)
}
request := &pb.ExecuteBatchKeyspaceIdsRequest{
Session: s,
Queries: proto.BoundKeyspaceIdQueriesToProto(queries),
TabletType: topo.TabletTypeToProto(tabletType),
AsTransaction: asTransaction,
}
response, err := conn.c.ExecuteBatchKeyspaceIds(ctx, request)
if err != nil {
return nil, session, err
}
if response.Error != nil {
return nil, response.Session, vterrors.FromVtRPCError(response.Error)
}
return mproto.Proto3ToQueryResults(response.Results), response.Session, nil
}
示例14: StreamExecute2
// StreamExecute2 is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute2(ctx context.Context, request *proto.Query, sendReply func(interface{}) error) (err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(ctx,
callerid.GoRPCEffectiveCallerID(request.CallerID),
callerid.NewImmediateCallerID("gorpc client"))
vtgErr := vtg.server.StreamExecute(ctx,
request.Sql,
request.BindVariables,
topo.TabletTypeToProto(request.TabletType),
func(value *proto.QueryResult) error {
return sendReply(value)
})
if vtgErr == nil {
return nil
}
// If there was an app error, send a QueryResult back with it.
qr := new(proto.QueryResult)
vtgate.AddVtGateError(vtgErr, &qr.Err)
return sendReply(qr)
}
示例15: SessionToProto
// SessionToProto transforms a Session into proto3
func SessionToProto(s *Session) *pb.Session {
if s == nil {
return nil
}
result := &pb.Session{
InTransaction: s.InTransaction,
}
result.ShardSessions = make([]*pb.Session_ShardSession, len(s.ShardSessions))
for i, ss := range s.ShardSessions {
result.ShardSessions[i] = &pb.Session_ShardSession{
Target: &pbq.Target{
Keyspace: ss.Keyspace,
Shard: ss.Shard,
TabletType: topo.TabletTypeToProto(ss.TabletType),
},
TransactionId: ss.TransactionId,
}
}
return result
}