`
mozhenghua
  • 浏览: 319487 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

cobar指定从读副本上读数据

阅读更多

 

 

下午花了一点时间看了一下cobar的源代码(无奈cobar的文档写的台稀稀拉拉了,只能看源代码了)
在cobar服务端的schema中配置了两个datasource,一主一从,在执行SQL的时候可以通过cobar的Hint语法,在查询的时候指定是从丛库上读取数据(默认是走master库的)
详细执行逻辑请查看 com.alibaba.cobar.route.hint.CobarHint 这个类
 
/*!cobar: $partitionOperand=('entity_id'='00005758') , $table='orderdetail' , $replica=1*/ 
select * from  orderdetail where entity_id='00005758'   limit 1 ;
  $replica的值为1表示从第1个(master是第0个)副本上读取数据,至于前面一段参数partitionOperand和table是必须加的不然执行会有问题,虽然看起来有点啰嗦但是加上也无妨。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics