001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.regionserver; 020 021import java.util.concurrent.LinkedBlockingQueue; 022import java.util.concurrent.ThreadFactory; 023import java.util.concurrent.ThreadPoolExecutor; 024import java.util.concurrent.TimeUnit; 025 026import org.apache.hadoop.hbase.client.RegionInfo; 027import org.apache.hadoop.hbase.wal.WAL; 028import org.apache.yetus.audience.InterfaceAudience; 029 030import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; 031 032/** 033 * Services a Store needs from a Region. 034 * RegionServicesForStores class is the interface through which memstore access services at the 035 * region level. 036 * For example, when using alternative memory formats or due to compaction the memstore needs to 037 * take occasional lock and update size counters at the region level. 038 */ 039@InterfaceAudience.Private 040public class RegionServicesForStores { 041 042 private static final int POOL_SIZE = 10; 043 private static final ThreadPoolExecutor INMEMORY_COMPACTION_POOL = 044 new ThreadPoolExecutor(POOL_SIZE, POOL_SIZE, 60, TimeUnit.SECONDS, 045 new LinkedBlockingQueue<>(), 046 new ThreadFactory() { 047 @Override 048 public Thread newThread(Runnable r) { 049 String name = Thread.currentThread().getName() + "-inmemoryCompactions-" + 050 System.currentTimeMillis(); 051 return new Thread(r, name); 052 } 053 }); 054 private final HRegion region; 055 056 public RegionServicesForStores(HRegion region) { 057 this.region = region; 058 } 059 060 public void blockUpdates() { 061 region.blockUpdates(); 062 } 063 064 public void unblockUpdates() { 065 region.unblockUpdates(); 066 } 067 068 public void addMemStoreSize(long dataSizeDelta, long heapSizeDelta, long offHeapSizeDelta, 069 int cellsCountDelta) { 070 region.incMemStoreSize(dataSizeDelta, heapSizeDelta, offHeapSizeDelta, cellsCountDelta); 071 } 072 073 public RegionInfo getRegionInfo() { 074 return region.getRegionInfo(); 075 } 076 077 public WAL getWAL() { 078 return region.getWAL(); 079 } 080 081 public ThreadPoolExecutor getInMemoryCompactionPool() { return INMEMORY_COMPACTION_POOL; } 082 083 public long getMemStoreFlushSize() { 084 return region.getMemStoreFlushSize(); 085 } 086 087 public int getNumStores() { 088 return region.getTableDescriptor().getColumnFamilyCount(); 089 } 090 091 @VisibleForTesting 092 long getMemStoreSize() { 093 return region.getMemStoreDataSize(); 094 } 095}