本文整理汇总了Golang中github.com/cockroachdb/cockroach/rpc.Context.GetLocalInternalServerForAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetLocalInternalServerForAddr方法的具体用法?Golang Context.GetLocalInternalServerForAddr怎么用?Golang Context.GetLocalInternalServerForAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/rpc.Context
的用法示例。
在下文中一共展示了Context.GetLocalInternalServerForAddr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendOne
// sendOne invokes the specified RPC on the supplied client when the
// client is ready. On success, the reply is sent on the channel;
// otherwise an error is sent.
//
// Do not call directly, but instead use sendOneFn. Tests mock out this method
// via sendOneFn in order to test various error cases.
func sendOne(client batchClient, timeout time.Duration,
rpcContext *rpc.Context, done chan batchCall) {
addr := client.remoteAddr
if log.V(2) {
log.Infof("sending request to %s: %+v", addr, client.args)
}
// TODO(tamird/tschottdorf): pass this in from DistSender.
ctx := context.TODO()
if timeout != 0 {
ctx, _ = context.WithTimeout(ctx, timeout)
}
if localServer := rpcContext.GetLocalInternalServerForAddr(addr); enableLocalCalls && localServer != nil {
reply, err := localServer.Batch(ctx, &client.args)
done <- batchCall{reply: reply, err: err}
return
}
go func() {
c := client.conn
for state, err := c.State(); state != grpc.Ready; state, err = c.WaitForStateChange(ctx, state) {
if err != nil {
done <- batchCall{err: newRPCError(
util.Errorf("rpc to %s failed: %s", addr, err))}
return
}
if state == grpc.Shutdown {
done <- batchCall{err: newRPCError(
util.Errorf("rpc to %s failed as client connection was closed", addr))}
return
}
}
reply, err := client.client.Batch(ctx, &client.args)
done <- batchCall{reply: reply, err: err}
}()
}
示例2: sendOne
// sendOne invokes the specified RPC on the supplied client when the
// client is ready. On success, the reply is sent on the channel;
// otherwise an error is sent.
//
// Do not call directly, but instead use sendOneFn. Tests mock out this method
// via sendOneFn in order to test various error cases.
func sendOne(opts SendOptions, rpcContext *rpc.Context, client batchClient, done chan batchCall) {
addr := client.remoteAddr
if log.V(2) {
log.Infof("sending request to %s: %+v", addr, client.args)
}
if localServer := rpcContext.GetLocalInternalServerForAddr(addr); enableLocalCalls && localServer != nil {
ctx, cancel := opts.contextWithTimeout()
defer cancel()
reply, err := localServer.Batch(ctx, &client.args)
done <- batchCall{reply: reply, err: err}
return
}
go func() {
ctx, cancel := opts.contextWithTimeout()
defer cancel()
c := client.conn
for state, err := c.State(); state != grpc.Ready; state, err = c.WaitForStateChange(ctx, state) {
if err != nil {
done <- batchCall{err: newRPCError(
util.Errorf("rpc to %s failed: %s", addr, err))}
return
}
if state == grpc.Shutdown {
done <- batchCall{err: newRPCError(
util.Errorf("rpc to %s failed as client connection was closed", addr))}
return
}
}
reply, err := client.client.Batch(ctx, &client.args)
done <- batchCall{reply: reply, err: err}
}()
}