`
fujohnwang
  • 浏览: 152791 次
社区版块
存档分类
最新评论

基于iBatis的开源分布式数据访问层

    博客分类:
  • Tech
阅读更多
http://code.alibabatech.com/wiki/display/cobarclient/Home

这个东西其实已经出来很长时间了,思路和成型也比其它相似的东西要早一些,公司近期才准备开源,所以就放出来了, 当然,不一定完美,东西比较简单, 所以开源出来希望能集思广益, 欢迎使用,拍砖,提意见

主要features:
1- data access support with horizontal or vertical partitions.
2- support 2-master active HA deployment infrustructure, of course, the applications still can choose other 3- HA solutions, like the ones specific to destination databases(e.g. RAC of Oracle).
4- Data aggregation support, currently only simple data merge functionality is available.
5- Local database transaction support(Currently, such requirement is fulfilled by using “Best Efforts 1PC Pattern” ).
6- SQL auditing, analysis, etc. [1]

公司要求文档和网站一概英文,所以看英文费力的,可以check out代码出来, 然后通过maven编译,之后可以在target/docs目录下找到一份中文的完整文档(实际上中文和英文各准备了一份)

GL&HF
分享到:
评论
28 楼 fujohnwang 2011-04-29  
<div class="quote_title">gzenzen 写道</div>
<div class="quote_div">
<pre name="code" class="java">&lt;rules&gt;
  &lt;rule&gt;
    &lt;namespace&gt;com.alibaba.cobar.client.entities.Offer&lt;/namespace&gt;
    &lt;shardingExpression&gt;hash.apply(memberId) == someValue&lt;/shardingExpression&gt;
    &lt;shards&gt;partition1&lt;/shards&gt;
  &lt;/rule&gt;
  &lt;rule&gt;
    &lt;namespace&gt;com.alibaba.cobar.client.entities.Offer&lt;/namespace&gt;
    &lt;shardingExpression&gt;hash.apply(memberId) == anotherValue&lt;/shardingExpression&gt;
    &lt;shards&gt;partition2&lt;/shards&gt;
  &lt;/rule&gt;
&lt;/rules&gt;
</pre>
<p>为什么我通过这种方法配置后,插入的时候切分到了不同的库里,但查询select * from 的时候却只返回一台机的数据</p>
<p> </p>
</div>
<p><span style="">要细化切分规则,最好用sqlmap元素, 明确指定路由到那个结点。<br><br>namespace 或者 sqlmap. 属于路由规则条件的一部分, 二者的唯一区别在于指定的条件明确程度不同, sqlmap直接对应每一个iBatis的SqlMap文件中某个statement的定义的id,而namespace则对应每一个iBatis的SqlMap文件中定义的namespace.<br><br>namespace是针对简单的规则, scope太大了, 特定场景下为了简化陆游规则定义的时候用</span></p>
27 楼 gzenzen 2011-04-28  
<pre name="code" class="java">&lt;rules&gt;
  &lt;rule&gt;
    &lt;namespace&gt;com.alibaba.cobar.client.entities.Offer&lt;/namespace&gt;
    &lt;shardingExpression&gt;hash.apply(memberId) == someValue&lt;/shardingExpression&gt;
    &lt;shards&gt;partition1&lt;/shards&gt;
  &lt;/rule&gt;
  &lt;rule&gt;
    &lt;namespace&gt;com.alibaba.cobar.client.entities.Offer&lt;/namespace&gt;
    &lt;shardingExpression&gt;hash.apply(memberId) == anotherValue&lt;/shardingExpression&gt;
    &lt;shards&gt;partition2&lt;/shards&gt;
  &lt;/rule&gt;
&lt;/rules&gt;
</pre>
<p>为什么我通过这种方法配置后,插入的时候切分到了不同的库里,但查询select * from 的时候却只返回一台机的数据</p>
26 楼 fujohnwang 2011-04-27  
bornwan 写道
我就很想知道分布式数据源,水平切分之后排序、分页的解决方案!

虽然不是完整的支持,但排序是指定支持的, 至于分页,我们没有需求,所以没有投入精力去支持。 我们希望的是,大家的融入社区并做贡献, 谢谢
25 楼 fujohnwang 2011-04-27  
gzenzen 写道
什么时候支持mybatis3、spring3

对于大多数网络应用, 以及不需要事务的应用, 现在的版本应该是可以平滑过度到3的, 但现在没有资源测试这方面的版本兼容性, 如果有心,你不妨可以测试一下然后反馈给社区啊
24 楼 bornwan 2011-04-26  
我就很想知道分布式数据源,水平切分之后排序、分页的解决方案!
23 楼 gzenzen 2011-04-25  
什么时候支持mybatis3、spring3
22 楼 fujohnwang 2011-04-06  
rendong 写道
升级到 ibatis3 和spring3 ,改动大么

Spring3的API有变动, 之前测试过,现在的处理会有问题,比如事务管理的concern。
21 楼 rendong 2011-04-03  
升级到 ibatis3 和spring3 ,改动大么
20 楼 fujohnwang 2011-03-31  
zhxing 写道
liuyes 写道
不错,编译成功,不知道有没有关于hibernate的,呵呵



hibernate 之前有个hibernate-share 的项目的。。现在不知道怎样了。。虽然没用过ibaits ,但大概了解比hibernate 简单很多,hiernate 感觉太过于复杂,封装了好多。。不容易扩展。。


是hibernate-shards吧?呵呵,其实要在这些ORM上面做扩展, 许多时候CUD不是大问题, R可能才是比较棘手的 :-)
19 楼 fujohnwang 2011-03-31  
tutu1982 写道
LZ,对于多应用服务器+分布式数据源中的事务管理目前这个方案能胜任么?



你好, 事务管理有几个层级,比如2PC, 1PC…, BestEffort 1PC, etc., CobarClient采用的是Best Effort 1PC模式的事务管理, 简单来讲就是可以保证一个数据操作过程中多个数据源各自的本地事务, 但不保证全局的分布式事务(因为这样的性能对大部分应用来说不可容忍)。

不过,CobarClient依赖的是DataSource粒度的资源管理,所以, 如果你的Middleware可以提供支持XA的DS, 那也是可以的。

CobarClient定位的是中小型应用, 如果非要在大规模集群使用,那建议引入某些中间件产品来统一资源的throttle等关注点。
另外, CobarClient因为是更高层次的封装(相对于protocol,driver等级别), 所以,用户可以根据自己的需要, 很容易的进行扩展。(CobarClient在设计的时候尽量在保证兼容性的前提下提高扩展性的考虑)

希望以上能够解答你的疑惑, 建议你check out代码读一下,代码不多,应该不难理解,也希望你能够提供建议和patch等 :-)
18 楼 hk8082 2011-03-31  
研究研究,正好要做分布式这块
17 楼 tutu1982 2011-03-31  
LZ,对于多应用服务器+分布式数据源中的事务管理目前这个方案能胜任么?

16 楼 www.oladdy.com 2011-03-30  
很好,有时间可以研究研究
15 楼 fujohnwang 2011-03-30  
hypgr 写道
还是有错,本地的一些依赖没有修改完成,下面是日志


[INFO] Failed to resolve artifact.

Missing:
----------
1) com.h2database:h2:jar:1.2.130

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=com.h2database -DartifactId=h2 -Dversion=1.2.130 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=com.h2database -DartifactId=h2 -Dversion=1.2.130 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) com.h2database:h2:jar:1.2.130

2) mysql:mysql-connector-java:jar:5.1.12

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.12 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.12 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) mysql:mysql-connector-java:jar:5.1.12

3) org.testng:testng:jar:jdk15:5.11

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.testng -DartifactId=testng -Dversion=5.11 -Dclassifier=jdk15 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.testng -DartifactId=testng -Dversion=5.11 -Dclassifier=jdk15 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) org.testng:testng:jar:jdk15:5.11

----------
3 required artifacts are missing.

for artifact:
  com.alibaba.cobar:cobar-client:jar:1.0.3

这些你可以修改你的settings去抓有这些库的repo, 或者你直接install到本地repo也可以, maven就是这样。
14 楼 Sink_deep 2011-03-29  
hypgr 写道
Missing:
----------
1) javax.jms:jms:jar:1.1

  Try downloading the file manually from:
      http://java.sun.com/products/jms/docs.html

  Then, install it using the command:
      mvn install:install-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) log4j:log4j:jar:1.2.15
  3) javax.jms:jms:jar:1.1

----------
1 required artifact is missing.

for artifact:
  com.alibaba.cobar:cobar-client:jar:1.0.3



这个问题是sun将这些jar包笼罩在license管理的淫威下,如果是单纯的记录日志,可以使用log4j1.2.14
13 楼 泛舟天下 2011-03-29  
fujohnwang 写道
泛舟天下 写道
楼主以前在英极?

はい

原来真是!
12 楼 SeanHe 2011-03-29  
mark 准备下载学习
11 楼 zhxing 2011-03-29  
liuyes 写道
不错,编译成功,不知道有没有关于hibernate的,呵呵



hibernate 之前有个hibernate-share 的项目的。。现在不知道怎样了。。虽然没用过ibaits ,但大概了解比hibernate 简单很多,hiernate 感觉太过于复杂,封装了好多。。不容易扩展。。
10 楼 liuyes 2011-03-29  
不错,编译成功,不知道有没有关于hibernate的,呵呵
9 楼 hypgr 2011-03-29  
还是有错,本地的一些依赖没有修改完成,下面是日志


[INFO] Failed to resolve artifact.

Missing:
----------
1) com.h2database:h2:jar:1.2.130

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=com.h2database -DartifactId=h2 -Dversion=1.2.130 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=com.h2database -DartifactId=h2 -Dversion=1.2.130 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) com.h2database:h2:jar:1.2.130

2) mysql:mysql-connector-java:jar:5.1.12

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.12 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.12 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) mysql:mysql-connector-java:jar:5.1.12

3) org.testng:testng:jar:jdk15:5.11

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.testng -DartifactId=testng -Dversion=5.11 -Dclassifier=jdk15 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.testng -DartifactId=testng -Dversion=5.11 -Dclassifier=jdk15 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
  1) com.alibaba.cobar:cobar-client:jar:1.0.3
  2) org.testng:testng:jar:jdk15:5.11

----------
3 required artifacts are missing.

for artifact:
  com.alibaba.cobar:cobar-client:jar:1.0.3

相关推荐

Global site tag (gtag.js) - Google Analytics