當前位置: 首頁>>代碼示例>>Golang>>正文


Golang key.ProtoToKeyRanges函數代碼示例

本文整理匯總了Golang中github.com/youtube/vitess/go/vt/key.ProtoToKeyRanges函數的典型用法代碼示例。如果您正苦於以下問題:Golang ProtoToKeyRanges函數的具體用法?Golang ProtoToKeyRanges怎麽用?Golang ProtoToKeyRanges使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ProtoToKeyRanges函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ProtoToSplitQueryParts

// ProtoToSplitQueryParts transforms a proto3 SplitQueryResponse into
// native types
func ProtoToSplitQueryParts(sqr *pb.SplitQueryResponse) []SplitQueryPart {
	if len(sqr.Splits) == 0 {
		return nil
	}
	result := make([]SplitQueryPart, len(sqr.Splits))
	for i, split := range sqr.Splits {
		if split.KeyRangePart != nil {
			result[i].Query = &KeyRangeQuery{
				Sql:           string(split.Query.Sql),
				BindVariables: tproto.Proto3ToBindVariables(split.Query.BindVariables),
				Keyspace:      split.KeyRangePart.Keyspace,
				KeyRanges:     key.ProtoToKeyRanges(split.KeyRangePart.KeyRanges),
			}
		}
		if split.ShardPart != nil {
			result[i].QueryShard = &QueryShard{
				Sql:           string(split.Query.Sql),
				BindVariables: tproto.Proto3ToBindVariables(split.Query.BindVariables),
				Keyspace:      split.ShardPart.Keyspace,
				Shards:        split.ShardPart.Shards,
			}
		}
		result[i].Size = split.Size
	}
	return result
}
開發者ID:ruiaylin,項目名稱:vitess,代碼行數:28,代碼來源:proto3.go

示例2: ExecuteKeyRanges

// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *pb.ExecuteKeyRangesRequest) (response *pb.ExecuteKeyRangesResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.CallerId,
		callerid.NewImmediateCallerID("grpc client"))
	reply := new(proto.QueryResult)
	executeErr := vtg.server.ExecuteKeyRanges(ctx,
		string(request.Query.Sql),
		tproto.Proto3ToBindVariables(request.Query.BindVariables),
		request.Keyspace,
		key.ProtoToKeyRanges(request.KeyRanges),
		request.TabletType,
		proto.ProtoToSession(request.Session),
		request.NotInTransaction,
		reply)
	response = &pb.ExecuteKeyRangesResponse{
		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
}
開發者ID:payintel,項目名稱:vitess,代碼行數:29,代碼來源:server.go

示例3: ExecuteKeyRanges

func (conn *vtgateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*pb.KeyRange, 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.KeyRangeQuery{
		CallerID:         getEffectiveCallerID(ctx),
		Sql:              query,
		BindVariables:    bindVars,
		Keyspace:         keyspace,
		KeyRanges:        key.ProtoToKeyRanges(keyRanges),
		TabletType:       topo.ProtoToTabletType(tabletType),
		Session:          s,
		NotInTransaction: notInTransaction,
	}
	var result proto.QueryResult
	if err := conn.rpcConn.Call(ctx, "VTGate.ExecuteKeyRanges", 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
}
開發者ID:payintel,項目名稱:vitess,代碼行數:27,代碼來源:conn.go

示例4: ExecuteKeyRanges

// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *pb.ExecuteKeyRangesRequest) (response *pb.ExecuteKeyRangesResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	query := &proto.KeyRangeQuery{
		Sql:              string(request.Query.Sql),
		BindVariables:    tproto.Proto3ToBindVariables(request.Query.BindVariables),
		Keyspace:         request.Keyspace,
		KeyRanges:        key.ProtoToKeyRanges(request.KeyRanges),
		TabletType:       topo.ProtoToTabletType(request.TabletType),
		Session:          proto.ProtoToSession(request.Session),
		NotInTransaction: request.NotInTransaction,
	}
	reply := new(proto.QueryResult)
	executeErr := vtg.server.ExecuteKeyRanges(ctx, query, reply)
	response = &pb.ExecuteKeyRangesResponse{
		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
}
開發者ID:afrolovskiy,項目名稱:vitess,代碼行數:27,代碼來源:server.go

示例5: StreamExecuteKeyRanges2

// StreamExecuteKeyRanges2 is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGateP3) StreamExecuteKeyRanges2(ctx context.Context, request *pb.StreamExecuteKeyRangesRequest, sendReply func(interface{}) error) (err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = callerid.NewContext(ctx,
		request.CallerId,
		callerid.NewImmediateCallerID("gorpc client"))
	vtgErr := vtg.server.StreamExecuteKeyRanges(ctx,
		string(request.Query.Sql),
		tproto.Proto3ToBindVariables(request.Query.BindVariables),
		request.Keyspace,
		key.ProtoToKeyRanges(request.KeyRanges),
		request.TabletType,
		func(reply *proto.QueryResult) error {
			return sendReply(&pb.StreamExecuteKeyRangesResponse{
				Error:  vtgate.VtGateErrorToVtRPCError(nil, reply.Error),
				Result: mproto.QueryResultToProto3(reply.Result),
			})
		})
	if vtgErr == nil {
		return nil
	}
	if *vtgate.RPCErrorOnlyInReply {
		// If there was an app error, send a QueryResult back with it.
		// 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(&pb.StreamExecuteKeyRangesResponse{
			Error: vtgate.VtGateErrorToVtRPCError(vtgErr, ""),
		})
	}
	return vtgErr
}
開發者ID:payintel,項目名稱:vitess,代碼行數:35,代碼來源:server.go

示例6: StreamExecuteKeyRanges2

func (conn *vtgateConn) StreamExecuteKeyRanges2(ctx context.Context, query string, keyspace string, keyRanges []*pb.KeyRange, bindVars map[string]interface{}, tabletType pb.TabletType) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) {
	req := &proto.KeyRangeQuery{
		CallerID:      getEffectiveCallerID(ctx),
		Sql:           query,
		BindVariables: bindVars,
		Keyspace:      keyspace,
		KeyRanges:     key.ProtoToKeyRanges(keyRanges),
		TabletType:    topo.ProtoToTabletType(tabletType),
		Session:       nil,
	}
	sr := make(chan *proto.QueryResult, 10)
	c := conn.rpcConn.StreamGo("VTGate.StreamExecuteKeyRanges2", req, sr)
	return sendStreamResults(c, sr)
}
開發者ID:payintel,項目名稱:vitess,代碼行數:14,代碼來源:conn.go

示例7: StreamExecuteKeyRanges

// StreamExecuteKeyRanges is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecuteKeyRanges(request *pb.StreamExecuteKeyRangesRequest, stream pbs.Vitess_StreamExecuteKeyRangesServer) (err error) {
	defer vtg.server.HandlePanic(&err)

	query := &proto.KeyRangeQuery{
		Sql:           string(request.Query.Sql),
		BindVariables: tproto.Proto3ToBindVariables(request.Query.BindVariables),
		Keyspace:      request.Keyspace,
		KeyRanges:     key.ProtoToKeyRanges(request.KeyRanges),
		TabletType:    topo.ProtoToTabletType(request.TabletType),
	}
	return vtg.server.StreamExecuteKeyRanges(stream.Context(), query, func(value *proto.QueryResult) error {
		return stream.Send(&pb.StreamExecuteKeyRangesResponse{
			Result: mproto.QueryResultToProto3(value.Result),
		})
	})
}
開發者ID:afrolovskiy,項目名稱:vitess,代碼行數:18,代碼來源:server.go

示例8: StreamExecuteKeyRanges

// StreamExecuteKeyRanges is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecuteKeyRanges(request *pb.StreamExecuteKeyRangesRequest, stream pbs.Vitess_StreamExecuteKeyRangesServer) (err error) {
	defer vtg.server.HandlePanic(&err)
	ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
		request.CallerId,
		callerid.NewImmediateCallerID("grpc client"))
	return vtg.server.StreamExecuteKeyRanges(ctx,
		string(request.Query.Sql),
		tproto.Proto3ToBindVariables(request.Query.BindVariables),
		request.Keyspace,
		key.ProtoToKeyRanges(request.KeyRanges),
		request.TabletType,
		func(value *proto.QueryResult) error {
			return stream.Send(&pb.StreamExecuteKeyRangesResponse{
				Result: mproto.QueryResultToProto3(value.Result),
			})
		})
}
開發者ID:payintel,項目名稱:vitess,代碼行數:19,代碼來源:server.go


注:本文中的github.com/youtube/vitess/go/vt/key.ProtoToKeyRanges函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。