当前位置: 首页>>代码示例>>Golang>>正文


Golang vterrors.ToGRPCError函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/vterrors.ToGRPCError函数的典型用法代码示例。如果您正苦于以下问题:Golang ToGRPCError函数的具体用法?Golang ToGRPCError怎么用?Golang ToGRPCError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ToGRPCError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SplitQuery

// SplitQuery is part of the queryservice.QueryServer interface
func (q *query) SplitQuery(ctx context.Context, request *querypb.SplitQueryRequest) (response *querypb.SplitQueryResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)

	bq, err := querytypes.Proto3ToBoundQuery(request.Query)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	splits := []querytypes.QuerySplit{}
	splits, err = queryservice.CallCorrectSplitQuery(
		q.server,
		request.UseSplitQueryV2,
		ctx,
		request.Target,
		bq.Sql,
		bq.BindVariables,
		request.SplitColumn,
		request.SplitCount,
		request.NumRowsPerQueryPart,
		request.Algorithm)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	qs, err := querytypes.QuerySplitsToProto3(splits)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	return &querypb.SplitQueryResponse{Queries: qs}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:33,代码来源:server.go

示例2: ExecuteBatchKeyspaceIds

// ExecuteBatchKeyspaceIds is the RPC version of
// vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteBatchKeyspaceIds(ctx context.Context, request *pb.ExecuteBatchKeyspaceIdsRequest) (response *pb.ExecuteBatchKeyspaceIdsResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.CallerId,
		callerid.NewImmediateCallerID("grpc client"))
	reply := new(proto.QueryResultList)
	bq, err := proto.ProtoToBoundKeyspaceIdQueries(request.Queries)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	executeErr := vtg.server.ExecuteBatchKeyspaceIds(ctx,
		bq,
		request.TabletType,
		request.AsTransaction,
		request.Session,
		reply)
	response = &pb.ExecuteBatchKeyspaceIdsResponse{
		Error: vtgate.RPCErrorToVtRPCError(reply.Err),
	}
	if executeErr != nil {
		return nil, vterrors.ToGRPCError(executeErr)
	}
	response.Results = tproto.QueryResultListToProto3(reply.List)
	response.Session = reply.Session
	return response, nil
}
开发者ID:tjyang,项目名称:vitess,代码行数:28,代码来源:server.go

示例3: ExecuteKeyspaceIds

// ExecuteKeyspaceIds is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyspaceIds(ctx context.Context, request *pb.ExecuteKeyspaceIdsRequest) (response *pb.ExecuteKeyspaceIdsResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.CallerId,
		callerid.NewImmediateCallerID("grpc client"))
	reply := new(proto.QueryResult)
	bv, err := tproto.Proto3ToBindVariables(request.Query.BindVariables)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	executeErr := vtg.server.ExecuteKeyspaceIds(ctx,
		string(request.Query.Sql),
		bv,
		request.Keyspace,
		request.KeyspaceIds,
		request.TabletType,
		request.Session,
		request.NotInTransaction,
		reply)
	response = &pb.ExecuteKeyspaceIdsResponse{
		Error: vtgate.RPCErrorToVtRPCError(reply.Err),
	}
	if executeErr != nil {
		return nil, vterrors.ToGRPCError(executeErr)
	}
	response.Result = sqltypes.ResultToProto3(reply.Result)
	response.Session = reply.Session
	return response, nil
}
开发者ID:tjyang,项目名称:vitess,代码行数:30,代码来源:server.go

示例4: SplitQuery

// SplitQuery is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) SplitQuery(ctx context.Context, request *vtgatepb.SplitQueryRequest) (response *vtgatepb.SplitQueryResponse, err error) {

	defer vtg.server.HandlePanic(&err)
	ctx = withCallerIDContext(ctx, request.CallerId)
	bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	splits, vtgErr := vtgateservice.CallCorrectSplitQuery(
		vtg.server,
		request.UseSplitQueryV2,
		ctx,
		request.Keyspace,
		string(request.Query.Sql),
		bv,
		request.SplitColumn,
		request.SplitCount,
		request.NumRowsPerQueryPart,
		request.Algorithm)
	if vtgErr != nil {
		return nil, vterrors.ToGRPCError(vtgErr)
	}
	return &vtgatepb.SplitQueryResponse{
		Splits: splits,
	}, nil
}
开发者ID:CowLeo,项目名称:vitess,代码行数:27,代码来源:server.go

示例5: BeginExecuteBatch

// BeginExecuteBatch is part of the queryservice.QueryServer interface
func (q *query) BeginExecuteBatch(ctx context.Context, request *querypb.BeginExecuteBatchRequest) (response *querypb.BeginExecuteBatchResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	bql, err := querytypes.Proto3ToBoundQueryList(request.Queries)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}

	results, transactionID, err := q.server.BeginExecuteBatch(ctx, request.Target, bql, request.AsTransaction, request.Options)
	if err != nil {
		// if we have a valid transactionID, return the error in-band
		if transactionID != 0 {
			return &querypb.BeginExecuteBatchResponse{
				Error:         vterrors.VtRPCErrorFromVtError(err),
				TransactionId: transactionID,
			}, nil
		}
		return nil, vterrors.ToGRPCError(err)
	}
	return &querypb.BeginExecuteBatchResponse{
		Results:       sqltypes.ResultsToProto3(results),
		TransactionId: transactionID,
	}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:28,代码来源:server.go

示例6: BeginExecute

// BeginExecute is part of the queryservice.QueryServer interface
func (q *query) BeginExecute(ctx context.Context, request *querypb.BeginExecuteRequest) (response *querypb.BeginExecuteResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}

	result, transactionID, err := q.server.BeginExecute(ctx, request.Target, request.Query.Sql, bv)
	if err != nil {
		// if we have a valid transactionID, return the error in-band
		if transactionID != 0 {
			return &querypb.BeginExecuteResponse{
				Error:         vterrors.VtRPCErrorFromVtError(err),
				TransactionId: transactionID,
			}, nil
		}
		return nil, vterrors.ToGRPCError(err)
	}
	return &querypb.BeginExecuteResponse{
		Result:        sqltypes.ResultToProto3(result),
		TransactionId: transactionID,
	}, nil
}
开发者ID:erzel,项目名称:vitess,代码行数:28,代码来源:server.go

示例7: SplitQuery

// SplitQuery is part of tabletconn.TabletConn
func (itc *internalTabletConn) SplitQuery(ctx context.Context, target *querypb.Target, query querytypes.BoundQuery, splitColumn string, splitCount int64) ([]querytypes.QuerySplit, error) {
	splits, err := itc.tablet.qsc.QueryService().SplitQuery(ctx, target, query.Sql, query.BindVariables, splitColumn, splitCount)
	if err != nil {
		return nil, tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(err))
	}
	return splits, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:8,代码来源:tablet_map.go

示例8: StreamHealth

// StreamHealth is part of tabletconn.TabletConn
func (itc *internalTabletConn) StreamHealth(ctx context.Context) (tabletconn.StreamHealthReader, error) {
	result := make(chan *querypb.StreamHealthResponse, 10)

	id, err := itc.tablet.qsc.QueryService().StreamHealthRegister(result)
	if err != nil {
		return nil, err
	}

	var finalErr error
	go func() {
		select {
		case <-ctx.Done():
		}

		// We populate finalErr before closing the channel.
		// The consumer first waits on the channel closure,
		// then read finalErr
		finalErr = itc.tablet.qsc.QueryService().StreamHealthUnregister(id)
		finalErr = tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(finalErr))
		close(result)
	}()

	return &streamHealthReader{
		c:   result,
		err: &finalErr,
	}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:28,代码来源:tablet_map.go

示例9: Begin

// Begin is part of tabletconn.TabletConn
func (itc *internalTabletConn) Begin(ctx context.Context, target *querypb.Target) (int64, error) {
	transactionID, err := itc.tablet.qsc.QueryService().Begin(ctx, target)
	if err != nil {
		return 0, tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(err))
	}
	return transactionID, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:8,代码来源:tablet_map.go

示例10: ExecuteVtworkerCommand

// ExecuteVtworkerCommand is part of the vtworkerdatapb.VtworkerServer interface
func (s *VtworkerServer) ExecuteVtworkerCommand(args *vtworkerdatapb.ExecuteVtworkerCommandRequest, stream vtworkerservicepb.Vtworker_ExecuteVtworkerCommandServer) (err error) {
	// Please note that this panic handler catches only panics occuring in the code below.
	// The actual execution of the vtworker command takes place in a new go routine
	// (started in Instance.setAndStartWorker()) which has its own panic handler.
	defer servenv.HandlePanic("vtworker", &err)

	// Stream everything back what the Wrangler is logging.
	logstream := logutil.NewCallbackLogger(func(e *logutilpb.Event) {
		stream.Send(&vtworkerdatapb.ExecuteVtworkerCommandResponse{
			Event: e,
		})
	})
	// Let the Wrangler also log everything to the console (and thereby
	// effectively to a logfile) to make sure that any information or errors
	// is preserved in the logs in case the RPC or vtworker crashes.
	logger := logutil.NewTeeLogger(logstream, logutil.NewConsoleLogger())

	wr := s.wi.CreateWrangler(logger)

	// Run the command as long as the RPC Context is valid.
	worker, done, err := s.wi.RunCommand(stream.Context(), args.Args, wr, false /*runFromCli*/)
	if err == nil && worker != nil && done != nil {
		err = s.wi.WaitForCommand(worker, done)
	}

	return vterrors.ToGRPCError(err)
}
开发者ID:dumbunny,项目名称:vitess,代码行数:28,代码来源:server.go

示例11: StreamExecute

// StreamExecute is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) StreamExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]interface{}, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error) {
	bv, err := querytypes.BindVariablesToProto3(bindVars)
	if err != nil {
		return nil, err
	}
	bindVars, err = querytypes.Proto3ToBindVariables(bv)
	if err != nil {
		return nil, err
	}
	result := make(chan *sqltypes.Result, 10)
	var finalErr error

	go func() {
		finalErr = itc.tablet.qsc.QueryService().StreamExecute(ctx, target, query, bindVars, options, func(reply *sqltypes.Result) error {
			// We need to deep-copy the reply before returning,
			// because the underlying buffers are reused.
			result <- reply.Copy()
			return nil
		})
		finalErr = tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(finalErr))

		// the client will only access finalErr after the
		// channel is closed, and then it's already set.
		close(result)
	}()

	return &streamExecuteAdapter{result, &finalErr}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:30,代码来源:tablet_map.go

示例12: ExecuteBatch

// ExecuteBatch is part of the queryservice.QueryServer interface
func (q *query) ExecuteBatch(ctx context.Context, request *querypb.ExecuteBatchRequest) (response *querypb.ExecuteBatchResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	bql, err := querytypes.Proto3ToBoundQueryList(request.Queries)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	results, err := q.server.ExecuteBatch(ctx, request.Target, bql, request.AsTransaction, request.TransactionId, request.Options)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	return &querypb.ExecuteBatchResponse{
		Results: sqltypes.ResultsToProto3(results),
	}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:19,代码来源:server.go

示例13: Execute

// Execute is part of the queryservice.QueryServer interface
func (q *query) Execute(ctx context.Context, request *querypb.ExecuteRequest) (response *querypb.ExecuteResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	result, err := q.server.Execute(ctx, request.Target, request.Query.Sql, bv, request.TransactionId, request.Options)
	if err != nil {
		return nil, vterrors.ToGRPCError(err)
	}
	return &querypb.ExecuteResponse{
		Result: sqltypes.ResultToProto3(result),
	}, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:19,代码来源:server.go

示例14: StreamExecute

// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(request *vtgatepb.StreamExecuteRequest, stream vtgateservicepb.Vitess_StreamExecuteServer) (err error) {
	defer vtg.server.HandlePanic(&err)
	ctx := withCallerIDContext(stream.Context(), request.CallerId)
	bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
	if err != nil {
		return vterrors.ToGRPCError(err)
	}
	vtgErr := vtg.server.StreamExecute(ctx,
		string(request.Query.Sql),
		bv,
		request.Keyspace,
		request.TabletType,
		func(value *sqltypes.Result) error {
			return stream.Send(&vtgatepb.StreamExecuteResponse{
				Result: sqltypes.ResultToProto3(value),
			})
		})
	return vterrors.ToGRPCError(vtgErr)
}
开发者ID:CowLeo,项目名称:vitess,代码行数:20,代码来源:server.go

示例15: Rollback

// Rollback is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) Rollback(ctx context.Context, request *vtgatepb.RollbackRequest) (response *vtgatepb.RollbackResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = withCallerIDContext(ctx, request.CallerId)
	vtgErr := vtg.server.Rollback(ctx, request.Session)
	response = &vtgatepb.RollbackResponse{}
	if vtgErr == nil {
		return response, nil
	}
	return nil, vterrors.ToGRPCError(vtgErr)
}
开发者ID:CowLeo,项目名称:vitess,代码行数:11,代码来源:server.go


注:本文中的github.com/youtube/vitess/go/vt/vterrors.ToGRPCError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。