예제 #1
0
파일: server.go 프로젝트: hadmagic/vitess
// SplitQuery is part of the queryservice.QueryServer interface
func (q *query) SplitQuery(ctx context.Context, request *pb.SplitQueryRequest) (response *pb.SplitQueryResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	reply := &proto.SplitQueryResult{}
	bq, err := proto.Proto3ToBoundQuery(request.Query)
	if err != nil {
		return nil, tabletserver.ToGRPCError(err)
	}
	if err := q.server.SplitQuery(ctx, request.Target, &proto.SplitQueryRequest{
		Query:       *bq,
		SplitColumn: request.SplitColumn,
		SplitCount:  int(request.SplitCount),
		SessionID:   request.SessionId,
	}, reply); err != nil {
		return nil, tabletserver.ToGRPCError(err)
	}
	qs, err := proto.QuerySplitsToProto3(reply.Queries)
	if err != nil {
		return nil, tabletserver.ToGRPCError(err)
	}
	return &pb.SplitQueryResponse{Queries: qs}, nil
}
예제 #2
0
파일: topo_utils.go 프로젝트: BobbWu/vitess
func boundShardQueriesToScatterBatchRequest(boundQueries []*vtgatepb.BoundShardQuery) (*scatterBatchRequest, error) {
	requests := &scatterBatchRequest{
		Length:   len(boundQueries),
		Requests: make(map[string]*shardBatchRequest),
	}
	for i, boundQuery := range boundQueries {
		for shard := range unique(boundQuery.Shards) {
			key := boundQuery.Keyspace + ":" + shard
			request := requests.Requests[key]
			if request == nil {
				request = &shardBatchRequest{
					Keyspace: boundQuery.Keyspace,
					Shard:    shard,
				}
				requests.Requests[key] = request
			}
			bq, err := tproto.Proto3ToBoundQuery(boundQuery.Query)
			if err != nil {
				return nil, err
			}
			request.Queries = append(request.Queries, *bq)
			request.ResultIndexes = append(request.ResultIndexes, i)
		}
	}
	return requests, nil
}