关于开源工具Sqoop源码解读----Mysql字符串作为主键主键分片

一、背景

       最近在做Mysql的数据库的迁移的过程中遇到一个问题,如果用户建的表的主键是字符串,这就导致了一个非常头痛的问题,如果对整张表进行分片?均匀的分片? 如果说采用limit轮询的方式查,但是这种效率太差,比如说几十亿的表,几百亿的表,要查出所有的boundary也是个非常头痛的事情....

     偶尔看到Appache有个类似的开源工具Sqoop,专门用来进行数据迁移,支持关系型数据库mysql,oracle迁移到大数据平台,不如Hbase,Hadoop等,于是就非常好奇其中的实现,尝试这了解了这款工具,说不定对现在遇到的问题,有所帮助,对于Mysql作为源端,我最关心的就是其中如果利用并发对一张表进行迁移?既然是并发,那就涉及到一个问题,如何进行切片了....


二、源码分析

     下面是我对这个源码进行阅读的一点分析过程,希望能够帮到大家...

    整体的逻辑也是在官方一小段解释,主要是将现有的Unicode字符进行数字化处理,具体的处理下面的源码分析

 The algorithm used is as follows:
   * Since there are 2**16 unicode characters, we interpret characters as
   * digits in base 65536. Given a string 's' containing characters s_0, s_1
   * .. s_n, we interpret the string as the number: 0.s_0 s_1 s_2.. s_n in
   * base 65536. Having mapped the low and high strings into floating-point
   * values, we then use the BigDecimalSplitter to establish the even split
   * points, then map the resulting floating point values back into strings.

   首先,字符串分片的主要功能类在 TextSplitter类中,该类提供了split方法作为入口,下面我们就对这个分片的过程进行分析一下,下面仅仅展示一些主要的代码,无关的代码就直接注释掉。。

 public List<InputSplit> split(Configuration conf, ResultSet results,
      String colName) throws SQLException, ValidationException {
    if (!conf.getBoolean(ALLOW_TEXT_SPLITTER_PROPERTY, false)) {
      throw new ValidationException("Generating splits for a textual index column " + "allowed only in case of \"-D"
          + ALLOW_TEXT_SPLITTER_PROPERTY + "=true\" property " + "passed as a parameter");
    }

    LOG.warn("Generating splits for a textual index column.")
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值