001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import java.util.Collection; 021import java.util.HashSet; 022import java.util.Set; 023import org.apache.hadoop.hbase.HBaseInterfaceAudience; 024import org.apache.yetus.audience.InterfaceAudience; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028/** 029 * A {@link FlushPolicy} that only flushes store larger a given threshold. If no store is large 030 * enough, then all stores will be flushed. 031 */ 032@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG) 033public class FlushAllLargeStoresPolicy extends FlushLargeStoresPolicy { 034 035 private static final Logger LOG = LoggerFactory.getLogger(FlushAllLargeStoresPolicy.class); 036 037 @Override 038 protected void configureForRegion(HRegion region) { 039 super.configureForRegion(region); 040 int familyNumber = region.getTableDescriptor().getColumnFamilyCount(); 041 if (familyNumber <= 1) { 042 // No need to parse and set flush size lower bound if only one family 043 // Family number might also be zero in some of our unit test case 044 return; 045 } 046 setFlushSizeLowerBounds(region); 047 } 048 049 @Override 050 public Collection<HStore> selectStoresToFlush() { 051 // no need to select stores if only one family 052 if (region.getTableDescriptor().getColumnFamilyCount() == 1) { 053 return region.stores.values(); 054 } 055 // start selection 056 Collection<HStore> stores = region.stores.values(); 057 Set<HStore> specificStoresToFlush = new HashSet<>(); 058 for (HStore store : stores) { 059 if (shouldFlush(store)) { 060 specificStoresToFlush.add(store); 061 } 062 } 063 if (!specificStoresToFlush.isEmpty()) { 064 return specificStoresToFlush; 065 } 066 067 // Didn't find any CFs which were above the threshold for selection. 068 if (LOG.isDebugEnabled()) { 069 LOG.debug("Since none of the CFs were above the size, flushing all."); 070 } 071 return stores; 072 } 073 074 @Override 075 protected boolean shouldFlush(HStore store) { 076 return super.shouldFlush(store) || region.shouldFlushStore(store); 077 } 078 079}