HBase的FlushLargeStoresPolicy多例族支持

众所周知,HBase的一个例族flush时,会导致所有例族都跟着被flush。在HBase-0.94的官方说明(http://hbase.apache.org/0.94/book/number.of.cfs.html)也明确HBase不能很好的支持一个以上的例族。

 

HBase-2.0.0HBase-1.1.0https://issues.apache.org/jira/browse/HBASE-10201)引入FlushLargeStoresPolicy来解决这个问题。

 

FlushLargeStoresPolicy的实现非常简单,就是在flush之前先判断下Store的大小,当超过指定大小时才flush注:实际上不仅仅受此决定,具体可查看HRegion类的shouldFlushStore()的实现)。

 

相关的类(之前只有FlushAllStoresPolicy一种flush策略,也就是flush一个例族时也会flush其它所有例族):

 

 

flush过程:

 

相关源代码:

public abstract class FlushPolicy {

    protected HRegion region;

    

    protected void configureForRegion(HRegion region) {

        this.region = region;

    }

    

    public abstract Collection<Store> selectStoresToFlush();

}

 

public class FlushLargeStoresPolicy extends FlushPolicy {

    private boolean shouldFlush(Store store) {

        if (store.getMemStoreSize() > this.flushSizeLowerBound) {

            return true;

        }

        

        // 请注意下面这句

        return region.shouldFlushStore(store);

    }

    

    public Collection<Store> selectStoresToFlush() {

        Collection<Store> stores = region.stores.values();

        Set<Store> specificStoresToFlush = new HashSet<Store>();

        for (Store store : stores) {

            if (shouldFlush(store)) {

                specificStoresToFlush.add(store);

            }

        }

        

        return specificStoresToFlush;

    }

}

 

public class FlushAllStoresPolicy extends FlushPolicy {

  public Collection<Store> selectStoresToFlush() {

    return region.stores.values();

  }

}

 

public class HRegion {

    boolean shouldFlushStore(Store store) {

        if ((maxFlushedSeqId > 0)

           && (maxFlushedSeqId + flushPerChanges < sequenceId.get())) {

            return true;

        }

        

        if (flushCheckInterval <= 0) {

            return false;

        }

        

        long now = EnvironmentEdgeManager.currentTime();

        if (store.timeOfOldestEdit() < now - flushCheckInterval) {

            return true;

        }

        

        return false;

    }

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值