• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang kvrpcpb.Request类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: handleRequest

func (h *rpcHandler) handleRequest(req *kvrpcpb.Request) *kvrpcpb.Response {
	resp := &kvrpcpb.Response{
		Type: req.Type,
	}
	if err := h.checkContext(req.GetContext()); err != nil {
		resp.RegionError = err
		return resp
	}
	switch req.GetType() {
	case kvrpcpb.MessageType_CmdGet:
		resp.CmdGetResp = h.onGet(req.CmdGetReq)
	case kvrpcpb.MessageType_CmdScan:
		resp.CmdScanResp = h.onScan(req.CmdScanReq)
	case kvrpcpb.MessageType_CmdPrewrite:
		resp.CmdPrewriteResp = h.onPrewrite(req.CmdPrewriteReq)
	case kvrpcpb.MessageType_CmdCommit:
		resp.CmdCommitResp = h.onCommit(req.CmdCommitReq)
	case kvrpcpb.MessageType_CmdCleanup:
		resp.CmdCleanupResp = h.onCleanup(req.CmdCleanupReq)
	case kvrpcpb.MessageType_CmdCommitThenGet:
		resp.CmdCommitGetResp = h.onCommitThenGet(req.CmdCommitGetReq)
	case kvrpcpb.MessageType_CmdRollbackThenGet:
		resp.CmdRbGetResp = h.onRollbackThenGet(req.CmdRbGetReq)
	case kvrpcpb.MessageType_CmdBatchGet:
		resp.CmdBatchGetResp = h.onBatchGet(req.CmdBatchGetReq)
	}
	return resp
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:28,代码来源:rpc.go


示例2: handleRequest

func (h *rpcHandler) handleRequest(req *kvrpcpb.Request) *kvrpcpb.Response {
	var resp kvrpcpb.Response
	if err := h.checkContext(req.GetContext()); err != nil {
		resp.RegionError = err
		return &resp
	}
	switch req.GetType() {
	case kvrpcpb.MessageType_CmdGet:
		resp.CmdGetResp = h.onGet(req.CmdGetReq)
	case kvrpcpb.MessageType_CmdScan:
		resp.CmdScanResp = h.onScan(req.CmdScanReq)
	case kvrpcpb.MessageType_CmdPrewrite:
		resp.CmdPrewriteResp = h.onPrewrite(req.CmdPrewriteReq)
	case kvrpcpb.MessageType_CmdCommit:
		resp.CmdCommitResp = h.onCommit(req.CmdCommitReq)
	case kvrpcpb.MessageType_CmdCleanup:
		resp.CmdCleanupResp = h.onCleanup(req.CmdCleanupReq)
	case kvrpcpb.MessageType_CmdBatchGet:
		resp.CmdBatchGetResp = h.onBatchGet(req.CmdBatchGetReq)
	case kvrpcpb.MessageType_CmdScanLock:
		resp.CmdResolveLockResp = h.onResolveLock(req.CmdResolveLockReq)
	case kvrpcpb.MessageType_CmdResolveLock:
		resp.CmdResolveLockResp = h.onResolveLock(req.CmdResolveLockReq)

	case kvrpcpb.MessageType_CmdRawGet:
		resp.CmdRawGetResp = h.onRawGet(req.CmdRawGetReq)
	case kvrpcpb.MessageType_CmdRawPut:
		resp.CmdRawPutResp = h.onRawPut(req.CmdRawPutReq)
	case kvrpcpb.MessageType_CmdRawDelete:
		resp.CmdRawDeleteResp = h.onRawDelete(req.CmdRawDeleteReq)
	}
	resp.Type = req.Type
	return &resp
}
开发者ID:pingcap,项目名称:tidb,代码行数:34,代码来源:rpc.go


示例3: TestRetryReadThenClose

// Server read message then close, so `Send` will return retry error.
func (s *testClientSuite) TestRetryReadThenClose(c *C) {
	l := startServer(":61236", c, readThenCloseRequest)
	defer l.Close()
	cli := newRPCClient()
	req := new(pb.Request)
	req.Type = pb.MessageType_CmdGet
	resp, err := cli.SendKVReq(":61236", req, readTimeoutShort)
	c.Assert(err, NotNil)
	c.Assert(resp, IsNil)
}
开发者ID:pingcap,项目名称:tidb,代码行数:11,代码来源:client_test.go


示例4: TestSendBySelf

// One normally `Send`.
func (s *testClientSuite) TestSendBySelf(c *C) {
	l := startServer(":61234", c, handleRequest)
	defer l.Close()
	cli := newRPCClient()
	req := new(pb.Request)
	req.Type = pb.MessageType_CmdGet
	getReq := new(pb.CmdGetRequest)
	getReq.Key = []byte("a")
	ver := uint64(0)
	getReq.Version = ver
	req.CmdGetReq = getReq
	resp, err := cli.SendKVReq(":61234", req, readTimeoutShort)
	c.Assert(err, IsNil)
	c.Assert(req.GetType(), Equals, resp.GetType())
}
开发者ID:pingcap,项目名称:tidb,代码行数:16,代码来源:client_test.go


示例5: SendKVReq

// sendKVReq sends req to tikv server. It will retry internally to find the right
// region leader if i) fails to establish a connection to server or ii) server
// returns `NotLeader`.
func (s *tikvStore) SendKVReq(bo *Backoffer, req *pb.Request, regionID RegionVerID) (*pb.Response, error) {
	for {
		region := s.regionCache.GetRegionByVerID(regionID)
		if region == nil {
			// If the region is not found in cache, it must be out
			// of date and already be cleaned up. We can skip the
			// RPC by returning RegionError directly.
			return &pb.Response{
				Type:        req.GetType(),
				RegionError: &errorpb.Error{StaleEpoch: &errorpb.StaleEpoch{}},
			}, nil
		}
		req.Context = region.GetContext()
		resp, err := s.client.SendKVReq(region.GetAddress(), req)
		if err != nil {
			s.regionCache.NextPeer(region.VerID())
			err = bo.Backoff(boTiKVRPC, errors.Errorf("send tikv request error: %v, ctx: %s, try next peer later", err, req.Context))
			if err != nil {
				return nil, errors.Trace(err)
			}
			continue
		}
		if regionErr := resp.GetRegionError(); regionErr != nil {
			// Retry if error is `NotLeader`.
			if notLeader := regionErr.GetNotLeader(); notLeader != nil {
				log.Warnf("tikv reports `NotLeader`: %s, ctx: %s, retry later", notLeader, req.Context)
				s.regionCache.UpdateLeader(region.VerID(), notLeader.GetLeader().GetId())
				if notLeader.GetLeader() == nil {
					err = bo.Backoff(boRegionMiss, errors.Errorf("not leader: %v, ctx: %s", notLeader, req.Context))
					if err != nil {
						return nil, errors.Trace(err)
					}
				}
				continue
			}
			// For other errors, we only drop cache here.
			// Because caller may need to re-split the request.
			log.Warnf("tikv reports region error: %s, ctx: %s", resp.GetRegionError(), req.Context)
			s.regionCache.DropRegion(region.VerID())
			return resp, nil
		}
		if resp.GetType() != req.GetType() {
			return nil, errors.Trace(errMismatch(resp, req))
		}
		return resp, nil
	}
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:50,代码来源:kv.go


示例6: SendKVReq

// SendKVReq sends a KV request to tikv server.
func (s *RegionRequestSender) SendKVReq(req *kvrpcpb.Request, regionID RegionVerID, timeout time.Duration) (*kvrpcpb.Response, error) {
	for {
		select {
		case <-s.bo.ctx.Done():
			return nil, errors.Trace(s.bo.ctx.Err())
		default:
		}

		ctx, err := s.regionCache.GetRPCContext(s.bo, regionID)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if ctx == nil {
			// If the region is not found in cache, it must be out
			// of date and already be cleaned up. We can skip the
			// RPC by returning RegionError directly.
			return &kvrpcpb.Response{
				Type:        req.GetType(),
				RegionError: &errorpb.Error{StaleEpoch: &errorpb.StaleEpoch{}},
			}, nil
		}

		resp, retry, err := s.sendKVReqToRegion(ctx, req, timeout)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if retry {
			continue
		}

		if regionErr := resp.GetRegionError(); regionErr != nil {
			retry, err := s.onRegionError(ctx, regionErr)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if retry {
				continue
			}
			return resp, nil
		}

		if resp.GetType() != req.GetType() {
			return nil, errors.Trace(errMismatch(resp, req))
		}
		return resp, nil
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:48,代码来源:region_request.go


示例7: sendKVReqToRegion

func (s *RegionRequestSender) sendKVReqToRegion(ctx *RPCContext, req *kvrpcpb.Request, timeout time.Duration) (resp *kvrpcpb.Response, retry bool, err error) {
	req.Context = ctx.KVCtx
	resp, err = s.client.SendKVReq(ctx.Addr, req, timeout)
	if err != nil {
		if e := s.onSendFail(ctx, err); e != nil {
			return nil, false, errors.Trace(e)
		}
		return nil, true, nil
	}
	return
}
开发者ID:pingcap,项目名称:tidb,代码行数:11,代码来源:region_request.go


示例8: errMismatch

// errMismatch if response mismatches request return error.
func errMismatch(resp *pb.Response, req *pb.Request) error {
	return errors.Errorf("message type mismatches, response[%s] request[%s]",
		resp.GetType(), req.GetType())
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:5,代码来源:error.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang kvrpcpb.Response类代码示例发布时间:2022-05-28
下一篇:
Golang kvrpcpb.CmdGetRequest类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap