本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.TabletTypeToProto函数的典型用法代码示例。如果您正苦于以下问题:Golang TabletTypeToProto函数的具体用法?Golang TabletTypeToProto怎么用?Golang TabletTypeToProto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TabletTypeToProto函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:khanchan,项目名称:vitess,代码行数:28,代码来源:scatter_conn.go
示例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
}
开发者ID:richarwu,项目名称:vitess,代码行数:32,代码来源:server.go
示例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)
}
开发者ID:haoqoo,项目名称:vitess,代码行数:32,代码来源:after_action.go
示例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
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:35,代码来源:conn.go
示例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
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:12,代码来源:client.go
示例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
}
开发者ID:cgvarela,项目名称:vitess,代码行数:12,代码来源:scatter_conn.go
示例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
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:12,代码来源:client.go
示例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
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:13,代码来源:toporeader.go
示例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)
})
}
开发者ID:richarwu,项目名称:vitess,代码行数:14,代码来源:server.go
示例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
}
开发者ID:khanchan,项目名称:vitess,代码行数:18,代码来源:server.go
示例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
}
开发者ID:richarwu,项目名称:vitess,代码行数:21,代码来源:server.go
示例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
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:20,代码来源:conn.go
示例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
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:20,代码来源:conn.go
示例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)
}
开发者ID:khanchan,项目名称:vitess,代码行数:21,代码来源:server.go
示例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
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:21,代码来源:proto3.go
示例16: ExecuteEntityIds
// ExecuteEntityIds is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteEntityIds(ctx context.Context, request *proto.EntityIdsQuery, 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.ExecuteEntityIds(ctx,
request.Sql,
request.BindVariables,
request.Keyspace,
request.EntityColumnName,
proto.EntityIdsToProto(request.EntityKeyspaceIDs),
topo.TabletTypeToProto(request.TabletType),
request.Session,
request.NotInTransaction,
reply)
vtgate.AddVtGateError(vtgErr, &reply.Err)
return nil
}
开发者ID:khanchan,项目名称:vitess,代码行数:21,代码来源:server.go
示例17: InitializeConnections
// InitializeConnections pre-initializes connections for all shards.
// It also populates topology cache by accessing it.
// It is not necessary to call this function before serving queries,
// but it would reduce connection overhead when serving.
func (stc *ScatterConn) InitializeConnections(ctx context.Context) error {
ksNames, err := stc.toposerv.GetSrvKeyspaceNames(ctx, stc.cell)
if err != nil {
return err
}
var wg sync.WaitGroup
var errRecorder concurrency.AllErrorRecorder
for _, ksName := range ksNames {
wg.Add(1)
go func(keyspace string) {
defer wg.Done()
// get SrvKeyspace for cell/keyspace
ks, err := stc.toposerv.GetSrvKeyspace(ctx, stc.cell, keyspace)
if err != nil {
errRecorder.RecordError(err)
return
}
// work on all shards of all serving tablet types
for tabletType, ksPartition := range ks.Partitions {
tt := topo.TabletTypeToProto(tabletType)
for _, shard := range ksPartition.ShardReferences {
wg.Add(1)
go func(shardName string, tabletType pb.TabletType) {
defer wg.Done()
err = stc.gateway.Dial(ctx, keyspace, shardName, tabletType)
if err != nil {
errRecorder.RecordError(err)
return
}
}(shard.Name, tt)
}
}
}(ksName)
}
wg.Wait()
if errRecorder.HasErrors() {
return errRecorder.Error()
}
return nil
}
开发者ID:yinyousong,项目名称:vitess,代码行数:44,代码来源:scatter_conn.go
示例18: ExecuteKeyspaceIds
func (conn *vtgateConn) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds []key.KeyspaceId, 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.ExecuteKeyspaceIdsRequest{
CallerId: callerid.EffectiveCallerIDFromContext(ctx),
Session: s,
Query: tproto.BoundQueryToProto3(query, bindVars),
Keyspace: keyspace,
KeyspaceIds: key.KeyspaceIdsToProto(keyspaceIds),
TabletType: topo.TabletTypeToProto(tabletType),
NotInTransaction: notInTransaction,
}
response, err := conn.c.ExecuteKeyspaceIds(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
}
开发者ID:haoqoo,项目名称:vitess,代码行数:23,代码来源:conn.go
示例19: NewShardConn
// NewShardConn creates a new ShardConn. It creates a Balancer using
// serv, cell, keyspace, tabletType and retryDelay. retryCount is the max
// number of retries before a ShardConn returns an error on an operation.
func NewShardConn(ctx context.Context, serv SrvTopoServer, cell, keyspace, shard string, tabletType topo.TabletType, retryDelay time.Duration, retryCount int, connTimeoutTotal, connTimeoutPerConn, connLife time.Duration, tabletConnectTimings *stats.MultiTimings) *ShardConn {
getAddresses := func() (*pb.EndPoints, error) {
endpoints, _, err := serv.GetEndPoints(ctx, cell, keyspace, shard, topo.TabletTypeToProto(tabletType))
if err != nil {
return nil, fmt.Errorf("endpoints fetch error: %v", err)
}
return endpoints, nil
}
blc := NewBalancer(getAddresses, retryDelay)
var ticker *timer.RandTicker
if tabletType != topo.TYPE_MASTER {
ticker = timer.NewRandTicker(connLife, connLife/2)
}
sdc := &ShardConn{
keyspace: keyspace,
shard: shard,
tabletType: tabletType,
retryDelay: retryDelay,
retryCount: retryCount,
connTimeoutTotal: connTimeoutTotal,
connTimeoutPerConn: connTimeoutPerConn,
connLife: connLife,
balancer: blc,
ticker: ticker,
consolidator: sync2.NewConsolidator(),
connectTimings: tabletConnectTimings,
}
if ticker != nil {
go func() {
for range ticker.C {
sdc.closeCurrent()
}
}()
}
return sdc
}
开发者ID:anusornc,项目名称:vitess,代码行数:39,代码来源:shard_conn.go
示例20: DbServingGraph
// DbServingGraph returns the ServingGraph for the given cell.
func DbServingGraph(ctx context.Context, ts topo.Server, cell string) (servingGraph *ServingGraph) {
servingGraph = &ServingGraph{
Cell: cell,
Keyspaces: make(map[string]*KeyspaceNodes),
}
rec := concurrency.AllErrorRecorder{}
keyspaces, err := ts.GetSrvKeyspaceNames(ctx, cell)
if err != nil {
servingGraph.Errors = append(servingGraph.Errors, fmt.Sprintf("GetSrvKeyspaceNames failed: %v", err))
return
}
wg := sync.WaitGroup{}
servingTypes := []topo.TabletType{topo.TYPE_MASTER, topo.TYPE_REPLICA, topo.TYPE_RDONLY}
for _, keyspace := range keyspaces {
kn := newKeyspaceNodes()
servingGraph.Keyspaces[keyspace] = kn
wg.Add(1)
go func(keyspace string, kn *KeyspaceNodes) {
defer wg.Done()
ks, err := ts.GetSrvKeyspace(ctx, cell, keyspace)
if err != nil {
rec.RecordError(fmt.Errorf("GetSrvKeyspace(%v, %v) failed: %v", cell, keyspace, err))
return
}
if len(ks.ServedFrom) > 0 {
kn.ServedFrom = make(map[topo.TabletType]string)
for _, sf := range ks.ServedFrom {
kn.ServedFrom[topo.ProtoToTabletType(sf.TabletType)] = sf.Keyspace
}
}
displayedShards := make(map[string]bool)
for _, partitionTabletType := range servingTypes {
kp := topoproto.SrvKeyspaceGetPartition(ks, topo.TabletTypeToProto(partitionTabletType))
if kp == nil {
continue
}
for _, srvShard := range kp.ShardReferences {
shard := srvShard.Name
if displayedShards[shard] {
continue
}
displayedShards[shard] = true
sn := &ShardNodes{
Name: shard,
}
kn.ShardNodes = append(kn.ShardNodes, sn)
wg.Add(1)
go func(shard string, sn *ShardNodes) {
defer wg.Done()
tabletTypes, err := ts.GetSrvTabletTypesPerShard(ctx, cell, keyspace, shard)
if err != nil {
rec.RecordError(fmt.Errorf("GetSrvTabletTypesPerShard(%v, %v, %v) failed: %v", cell, keyspace, shard, err))
return
}
for _, tabletType := range tabletTypes {
endPoints, _, err := ts.GetEndPoints(ctx, cell, keyspace, shard, tabletType)
if err != nil {
rec.RecordError(fmt.Errorf("GetEndPoints(%v, %v, %v, %v) failed: %v", cell, keyspace, shard, tabletType, err))
continue
}
for _, endPoint := range endPoints.Entries {
var tabletNode *TabletNodesByType
for _, t := range sn.TabletNodes {
if t.TabletType == tabletType {
tabletNode = t
break
}
}
if tabletNode == nil {
tabletNode = &TabletNodesByType{
TabletType: tabletType,
}
sn.TabletNodes = append(sn.TabletNodes, tabletNode)
}
tabletNode.Nodes = append(tabletNode.Nodes, newTabletNodeFromEndPoint(endPoint, cell))
}
}
}(shard, sn)
}
}
}(keyspace, kn)
}
wg.Wait()
servingGraph.Errors = rec.ErrorStrings()
return
}
开发者ID:xgwubin,项目名称:vitess,代码行数:91,代码来源:topology.go
注:本文中的github.com/youtube/vitess/go/vt/topo.TabletTypeToProto函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论