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


Golang Call.GetRegion方法代码示例

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


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

示例1: sendRPC

// sendRPC takes an RPC call, and will send it to the correct region server. If
// the correct region server is offline or otherwise unavailable, sendRPC will
// continually retry until the deadline set on the RPC's context is exceeded.
func (c *Client) sendRPC(rpc hrpc.Call) (proto.Message, error) {
	log.WithFields(log.Fields{
		"Type":  rpc.GetName(),
		"Table": string(rpc.Table()),
		"Key":   string(rpc.Key()),
	}).Debug("Sending RPC")
	err := c.queueRPC(rpc)
	if err == ErrDeadline {
		return nil, err
	} else if err != nil {
		log.WithFields(log.Fields{
			"Type":  rpc.GetName(),
			"Table": string(rpc.Table()),
			"Key":   string(rpc.Key()),
		}).Debug("We hit an error queuing the RPC. Resending.")
		// There was an error locating the region for the RPC, or the client
		// for the region encountered an error and has shut down.
		return c.sendRPC(rpc)
	}
	if err == nil {
		var res hrpc.RPCResult
		resch := rpc.GetResultChan()

		select {
		case res = <-resch:
		case <-rpc.GetContext().Done():
			return nil, ErrDeadline
		}

		err := res.Error
		log.WithFields(log.Fields{
			"Type":   rpc.GetName(),
			"Table":  string(rpc.Table()),
			"Key":    string(rpc.Key()),
			"Result": res.Msg,
			"Error":  err,
		}).Debug("Successfully sent RPC. Returning.")

		if _, ok := err.(region.RetryableError); ok {
			return c.sendRPC(rpc)
		} else if _, ok := err.(region.UnrecoverableError); ok {
			// Prevents dropping into the else block below,
			// error handling happens a few lines down
		} else {
			return res.Msg, res.Error
		}
	}

	// There was an issue related to the network, so we're going to mark the
	// region as unavailable, and generate the channel used for announcing
	// when it's available again
	region := rpc.GetRegion()

	log.WithFields(log.Fields{
		"Type":  rpc.GetName(),
		"Table": string(rpc.Table()),
		"Key":   string(rpc.Key()),
	}).Debug("Encountered a network error. Region unavailable?")

	if region != nil {
		succ := region.MarkUnavailable()
		if succ {
			go c.reestablishRegion(region)
		}
	}
	log.WithFields(log.Fields{
		"Type":  rpc.GetName(),
		"Table": string(rpc.Table()),
		"Key":   string(rpc.Key()),
	}).Debug("Retrying sendRPC")
	return c.sendRPC(rpc)
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:75,代码来源:client.go


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