本文整理汇总了Golang中github.com/pingcap/kvproto/pkg/coprocessor.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: handleCopRequest
func (h *rpcHandler) handleCopRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
resp := &coprocessor.Response{}
if err := h.checkContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
}
if len(req.Ranges) == 0 {
return resp, nil
}
if req.GetTp() == kv.ReqTypeSelect || req.GetTp() == kv.ReqTypeIndex {
sel := new(tipb.SelectRequest)
err := proto.Unmarshal(req.Data, sel)
if err != nil {
return nil, errors.Trace(err)
}
ctx := &selectContext{
sel: sel,
}
ctx.eval = &xeval.Evaluator{Row: make(map[int64]types.Datum)}
if sel.Where != nil {
ctx.whereColumns = make(map[int64]*tipb.ColumnInfo)
collectColumnsInWhere(sel.Where, ctx)
}
ctx.aggregate = len(sel.Aggregates) > 0 || len(sel.GetGroupBy()) > 0
if ctx.aggregate {
// compose aggregateFuncExpr
ctx.aggregates = make([]*aggregateFuncExpr, 0, len(sel.Aggregates))
for _, agg := range sel.Aggregates {
aggExpr := &aggregateFuncExpr{expr: agg}
ctx.aggregates = append(ctx.aggregates, aggExpr)
}
ctx.groups = make(map[string]bool)
ctx.groupKeys = make([][]byte, 0)
}
var rows []*tipb.Row
if req.GetTp() == kv.ReqTypeSelect {
rows, err = h.getRowsFromSelectReq(ctx)
} else {
rows, err = h.getRowsFromIndexReq(ctx)
}
selResp := new(tipb.SelectResponse)
selResp.Error = toPBError(err)
selResp.Rows = rows
if err != nil {
resp.OtherError = proto.String(err.Error())
}
data, err := proto.Marshal(selResp)
if err != nil {
return nil, errors.Trace(err)
}
resp.Data = data
}
return resp, nil
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:55,代码来源:cop_handler.go
示例2: sendCopReqToRegion
func (s *RegionRequestSender) sendCopReqToRegion(ctx *RPCContext, req *coprocessor.Request, timeout time.Duration) (resp *coprocessor.Response, retry bool, err error) {
req.Context = ctx.KVCtx
resp, err = s.client.SendCopReq(ctx.Addr, req, timeout)
if err != nil {
if e := s.onSendFail(ctx, err); e != nil {
return nil, false, errors.Trace(err)
}
return nil, true, nil
}
return
}
开发者ID:pingcap,项目名称:tidb,代码行数:11,代码来源:region_request.go
示例3: handleCopRequest
func (h *rpcHandler) handleCopRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
resp := &coprocessor.Response{}
if err := h.checkContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
}
if len(req.Ranges) == 0 {
return resp, nil
}
if req.GetTp() == kv.ReqTypeSelect || req.GetTp() == kv.ReqTypeIndex {
sel := new(tipb.SelectRequest)
err := proto.Unmarshal(req.Data, sel)
if err != nil {
return nil, errors.Trace(err)
}
ctx := &selectContext{
sel: sel,
}
if sel.Where != nil {
ctx.eval = &xeval.Evaluator{Row: make(map[int64]types.Datum)}
ctx.whereColumns = make(map[int64]*tipb.ColumnInfo)
collectColumnsInWhere(sel.Where, ctx)
}
var rows []*tipb.Row
if req.GetTp() == kv.ReqTypeSelect {
rows, err = h.getRowsFromSelectReq(ctx)
} else {
rows, err = h.getRowsFromIndexReq(ctx)
}
selResp := new(tipb.SelectResponse)
selResp.Error = toPBError(err)
selResp.Rows = rows
if err != nil {
resp.OtherError = proto.String(err.Error())
}
data, err := proto.Marshal(selResp)
if err != nil {
return nil, errors.Trace(err)
}
resp.Data = data
}
return resp, nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:43,代码来源:cop_handler.go
示例4: handleCopRequest
func (h *rpcHandler) handleCopRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
resp := &coprocessor.Response{}
if err := h.checkContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
}
if len(req.Ranges) == 0 {
return resp, nil
}
if req.GetTp() == kv.ReqTypeSelect || req.GetTp() == kv.ReqTypeIndex {
sel := new(tipb.SelectRequest)
err := proto.Unmarshal(req.Data, sel)
if err != nil {
return nil, errors.Trace(err)
}
ctx := &selectContext{
sel: sel,
keyRanges: req.Ranges,
}
ctx.eval = &xeval.Evaluator{Row: make(map[int64]types.Datum)}
if sel.Where != nil {
ctx.whereColumns = make(map[int64]*tipb.ColumnInfo)
collectColumnsInExpr(sel.Where, ctx, ctx.whereColumns)
}
ctx.aggregate = len(sel.Aggregates) > 0 || len(sel.GetGroupBy()) > 0
if ctx.aggregate {
// compose aggregateFuncExpr
ctx.aggregates = make([]*aggregateFuncExpr, 0, len(sel.Aggregates))
ctx.aggColumns = make(map[int64]*tipb.ColumnInfo)
for _, agg := range sel.Aggregates {
aggExpr := &aggregateFuncExpr{expr: agg}
ctx.aggregates = append(ctx.aggregates, aggExpr)
collectColumnsInExpr(agg, ctx, ctx.aggColumns)
}
ctx.groups = make(map[string]bool)
ctx.groupKeys = make([][]byte, 0)
for _, item := range ctx.sel.GetGroupBy() {
collectColumnsInExpr(item.Expr, ctx, ctx.aggColumns)
}
for k := range ctx.whereColumns {
// It is will be handled in where.
delete(ctx.aggColumns, k)
}
}
var rows []*tipb.Row
if req.GetTp() == kv.ReqTypeSelect {
rows, err = h.getRowsFromSelectReq(ctx)
} else {
// The PKHandle column info has been collected in ctx, so we can remove it in IndexInfo.
length := len(sel.IndexInfo.Columns)
if sel.IndexInfo.Columns[length-1].GetPkHandle() {
sel.IndexInfo.Columns = sel.IndexInfo.Columns[:length-1]
}
rows, err = h.getRowsFromIndexReq(ctx)
}
selResp := new(tipb.SelectResponse)
selResp.Error = toPBError(err)
selResp.Rows = rows
if err != nil {
resp.OtherError = err.Error()
}
data, err := proto.Marshal(selResp)
if err != nil {
return nil, errors.Trace(err)
}
resp.Data = data
}
return resp, nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:70,代码来源:cop_handler.go
示例5: handleCopRequest
func (h *rpcHandler) handleCopRequest(req *coprocessor.Request) (*coprocessor.Response, error) {
resp := &coprocessor.Response{}
if err := h.checkContext(req.GetContext()); err != nil {
resp.RegionError = err
return resp, nil
}
if len(req.Ranges) == 0 {
return resp, nil
}
if req.GetTp() == kv.ReqTypeSelect || req.GetTp() == kv.ReqTypeIndex {
sel := new(tipb.SelectRequest)
err := proto.Unmarshal(req.Data, sel)
if err != nil {
return nil, errors.Trace(err)
}
ctx := &selectContext{
sel: sel,
keyRanges: req.Ranges,
sc: xeval.FlagsToStatementContext(sel.Flags),
}
ctx.eval = xeval.NewEvaluator(ctx.sc)
if sel.Where != nil {
ctx.whereColumns = make(map[int64]*tipb.ColumnInfo)
collectColumnsInExpr(sel.Where, ctx, ctx.whereColumns)
}
ctx.aggregate = len(sel.Aggregates) > 0 || len(sel.GetGroupBy()) > 0
if ctx.aggregate {
// compose aggregateFuncExpr
ctx.aggregates = make([]*aggregateFuncExpr, 0, len(sel.Aggregates))
ctx.aggColumns = make(map[int64]*tipb.ColumnInfo)
for _, agg := range sel.Aggregates {
aggExpr := &aggregateFuncExpr{expr: agg}
ctx.aggregates = append(ctx.aggregates, aggExpr)
collectColumnsInExpr(agg, ctx, ctx.aggColumns)
}
ctx.groups = make(map[string]bool)
ctx.groupKeys = make([][]byte, 0)
for _, item := range ctx.sel.GetGroupBy() {
collectColumnsInExpr(item.Expr, ctx, ctx.aggColumns)
}
for k := range ctx.whereColumns {
// It is will be handled in where.
delete(ctx.aggColumns, k)
}
}
var chunks []tipb.Chunk
if req.GetTp() == kv.ReqTypeSelect {
chunks, err = h.getChunksFromSelectReq(ctx)
} else {
// The PKHandle column info has been collected in ctx, so we can remove it in IndexInfo.
length := len(sel.IndexInfo.Columns)
if sel.IndexInfo.Columns[length-1].GetPkHandle() {
sel.IndexInfo.Columns = sel.IndexInfo.Columns[:length-1]
}
chunks, err = h.getChunksFromIndexReq(ctx)
}
selResp := new(tipb.SelectResponse)
selResp.Error = toPBError(err)
selResp.Chunks = chunks
if err != nil {
if locked, ok := errors.Cause(err).(*ErrLocked); ok {
resp.Locked = &kvrpcpb.LockInfo{
Key: locked.Key,
PrimaryLock: locked.Primary,
LockVersion: locked.StartTS,
LockTtl: locked.TTL,
}
} else {
resp.OtherError = err.Error()
}
}
data, err := proto.Marshal(selResp)
if err != nil {
return nil, errors.Trace(err)
}
resp.Data = data
}
return resp, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:81,代码来源:cop_handler.go
注:本文中的github.com/pingcap/kvproto/pkg/coprocessor.Request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论