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


Golang Request.Header方法代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/roachpb.Request.Header方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Header方法的具体用法?Golang Request.Header怎么用?Golang Request.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cockroachdb/cockroach/roachpb.Request的用法示例。


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

示例1: updateForBatch

// UpdateForBatch updates the first argument (the header of a request contained
// in a batch) from the second one (the batch header), returning an error when
// inconsistencies are found.
// It is checked that the individual call does not have a UserPriority
// or Txn set that differs from the batch's.
// TODO(tschottdorf): will go with #2143.
func updateForBatch(args roachpb.Request, bHeader roachpb.BatchRequest_Header) error {
	// Disallow transaction, user and priority on individual calls, unless
	// equal.
	aHeader := args.Header()
	if aPrio := aHeader.GetUserPriority(); aPrio != roachpb.Default_RequestHeader_UserPriority && aPrio != bHeader.GetUserPriority() {
		return util.Errorf("conflicting user priority on call in batch")
	}
	aHeader.UserPriority = bHeader.UserPriority
	aHeader.Txn = bHeader.Txn // reqs always take Txn from batch
	return nil
}
开发者ID:GokulSrinivas,项目名称:cockroach,代码行数:17,代码来源:txn_coord_sender.go

示例2: SendWrappedAt

// SendWrappedAt is a convenience function which wraps the request in a batch
// and sends it via the provided Sender at the given timestamp. It returns the
// unwrapped response or an error. It's valid to pass a `nil` context;
// context.Background() is used in that case.
func SendWrappedAt(sender Sender, ctx context.Context, ts roachpb.Timestamp, args roachpb.Request) (roachpb.Response, error) {
	if ctx == nil {
		ctx = context.Background()
	}
	ba, unwrap := func(args roachpb.Request) (*roachpb.BatchRequest, func(*roachpb.BatchResponse) roachpb.Response) {
		ba := &roachpb.BatchRequest{}
		ba.Timestamp = ts
		{
			h := args.Header()
			ba.Key, ba.EndKey = h.Key, h.EndKey
			ba.CmdID = h.CmdID
			ba.Replica = h.Replica
			ba.RangeID = h.RangeID
			ba.UserPriority = h.UserPriority
			ba.Txn = h.Txn
			ba.ReadConsistency = h.ReadConsistency
		}
		ba.Add(args)
		return ba, func(br *roachpb.BatchResponse) roachpb.Response {
			unwrappedReply := br.Responses[0].GetInner()
			// The ReplyTxn is propagated from one response to the next request,
			// and we adopt the mechanism that whenever the Txn changes, it needs
			// to be set in the reply, for example to ratchet up the transaction
			// timestamp on writes when necessary.
			// This is internally necessary to sequentially execute the batch,
			// so it makes some sense to take the burden of updating the Txn
			// from TxnCoordSender - it will only need to act on retries/aborts
			// in the future.
			unwrappedReply.Header().Txn = br.Txn
			return unwrappedReply
		}
	}(args)
	br, pErr := sender.Send(ctx, *ba)
	if err := pErr.GoError(); err != nil {
		return nil, err
	}
	return unwrap(br), nil
}
开发者ID:GokulSrinivas,项目名称:cockroach,代码行数:42,代码来源:sender.go


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