Exemple #1
0
// StreamExecute is part of the queryservice.QueryServer interface
func (q *query) StreamExecute(request *pb.StreamExecuteRequest, stream pbs.Query_StreamExecuteServer) (err error) {
	defer q.server.HandlePanic(&err)
	ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
		request.GetEffectiveCallerId(),
		request.GetImmediateCallerId(),
	)
	seErr := q.server.StreamExecute(ctx, &proto.Query{
		Sql:           string(request.Query.Sql),
		BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables),
		SessionId:     request.SessionId,
	}, func(reply *mproto.QueryResult) error {
		return stream.Send(&pb.StreamExecuteResponse{
			Result: mproto.QueryResultToProto3(reply),
		})
	})
	if seErr != nil {
		response := &pb.StreamExecuteResponse{
			Error: tabletserver.TabletErrorToRPCError(seErr),
		}
		if err := stream.Send(response); err != nil {
			return err
		}
	}
	return nil
}
Exemple #2
0
// Commit is part of the queryservice.QueryServer interface
func (q *query) Commit(ctx context.Context, request *pb.CommitRequest) (response *pb.CommitResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callinfo.GRPCCallInfo(ctx)

	commitErr := q.server.Commit(ctx, &proto.Session{
		SessionId:     request.SessionId,
		TransactionId: request.TransactionId,
	})
	return &pb.CommitResponse{
		Error: tabletserver.TabletErrorToRPCError(commitErr),
	}, nil
}
Exemple #3
0
// GetSessionId is part of the queryservice.QueryServer interface
func (q *query) GetSessionId(ctx context.Context, request *pb.GetSessionIdRequest) (response *pb.GetSessionIdResponse, err error) {
	defer q.server.HandlePanic(&err)

	sessionInfo := new(proto.SessionInfo)
	gsiErr := q.server.GetSessionId(&proto.SessionParams{
		Keyspace: request.Keyspace,
		Shard:    request.Shard,
	}, sessionInfo)

	return &pb.GetSessionIdResponse{
		SessionId: sessionInfo.SessionId,
		Error:     tabletserver.TabletErrorToRPCError(gsiErr),
	}, nil
}
Exemple #4
0
// Rollback is part of the queryservice.QueryServer interface
func (q *query) Rollback(ctx context.Context, request *pb.RollbackRequest) (response *pb.RollbackResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.GetEffectiveCallerId(),
		request.GetImmediateCallerId(),
	)
	rollbackErr := q.server.Rollback(ctx, &proto.Session{
		SessionId:     request.SessionId,
		TransactionId: request.TransactionId,
	})

	return &pb.RollbackResponse{
		Error: tabletserver.TabletErrorToRPCError(rollbackErr),
	}, nil
}
Exemple #5
0
// Begin is part of the queryservice.QueryServer interface
func (q *query) Begin(ctx context.Context, request *pb.BeginRequest) (response *pb.BeginResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callinfo.GRPCCallInfo(ctx)

	txInfo := new(proto.TransactionInfo)
	if beginErr := q.server.Begin(ctx, &proto.Session{
		SessionId: request.SessionId,
	}, txInfo); beginErr != nil {
		return &pb.BeginResponse{
			Error: tabletserver.TabletErrorToRPCError(beginErr),
		}, nil
	}

	return &pb.BeginResponse{
		TransactionId: txInfo.TransactionId,
	}, nil
}
Exemple #6
0
// ExecuteBatch is part of the queryservice.QueryServer interface
func (q *query) ExecuteBatch(ctx context.Context, request *pb.ExecuteBatchRequest) (response *pb.ExecuteBatchResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callinfo.GRPCCallInfo(ctx)

	reply := new(proto.QueryResultList)
	execErr := q.server.ExecuteBatch(ctx, &proto.QueryList{
		Queries:       proto.Proto3ToBoundQueryList(request.Queries),
		SessionId:     request.SessionId,
		TransactionId: request.TransactionId,
	}, reply)
	if execErr != nil {
		return &pb.ExecuteBatchResponse{
			Error: tabletserver.TabletErrorToRPCError(execErr),
		}, nil
	}
	return &pb.ExecuteBatchResponse{
		Results: proto.QueryResultListToProto3(reply.List),
	}, nil
}
Exemple #7
0
// 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 = callinfo.GRPCCallInfo(ctx)

	reply := &proto.SplitQueryResult{}
	if sqErr := q.server.SplitQuery(ctx, &proto.SplitQueryRequest{
		Query:       *proto.Proto3ToBoundQuery(request.Query),
		SplitColumn: request.SplitColumn,
		SplitCount:  int(request.SplitCount),
		SessionID:   request.SessionId,
	}, reply); sqErr != nil {
		return &pb.SplitQueryResponse{
			Error: tabletserver.TabletErrorToRPCError(sqErr),
		}, nil
	}
	return &pb.SplitQueryResponse{
		Queries: proto.QuerySplitsToProto3(reply.Queries),
	}, nil
}
Exemple #8
0
// Execute is part of the queryservice.QueryServer interface
func (q *query) Execute(ctx context.Context, request *pb.ExecuteRequest) (response *pb.ExecuteResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callinfo.GRPCCallInfo(ctx)

	reply := new(mproto.QueryResult)
	execErr := q.server.Execute(ctx, &proto.Query{
		Sql:           string(request.Query.Sql),
		BindVariables: proto.Proto3ToBindVariables(request.Query.BindVariables),
		SessionId:     request.SessionId,
		TransactionId: request.TransactionId,
	}, reply)
	if execErr != nil {
		return &pb.ExecuteResponse{
			Error: tabletserver.TabletErrorToRPCError(execErr),
		}, nil
	}
	return &pb.ExecuteResponse{
		Result: mproto.QueryResultToProto3(reply),
	}, nil
}