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 org.apache.hadoop.hbase.CompatibilitySingletonFactory;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * This class is for maintaining the various regionserver's heap memory manager statistics and
025 * publishing them through the metrics interfaces.
026 */
027@InterfaceAudience.Private
028public class MetricsHeapMemoryManager {
029  private final MetricsHeapMemoryManagerSource source;
030
031  public MetricsHeapMemoryManager() {
032    this(CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
033      .getHeapMemoryManager());
034  }
035
036  public MetricsHeapMemoryManager(MetricsHeapMemoryManagerSource source) {
037    this.source = source;
038  }
039
040  public MetricsHeapMemoryManagerSource getMetricsSource() {
041    return source;
042  }
043
044  /**
045   * Update/Set the blocked flush count histogram/gauge
046   * @param blockedFlushCount the number of blocked memstore flush since last tuning.
047   */
048  public void updateBlockedFlushCount(final long blockedFlushCount) {
049    source.updateBlockedFlushCount(blockedFlushCount);
050  }
051
052  /**
053   * Update/Set the unblocked flush count histogram/gauge
054   * @param unblockedFlushCount the number of unblocked memstore flush since last tuning.
055   */
056  public void updateUnblockedFlushCount(final long unblockedFlushCount) {
057    source.updateUnblockedFlushCount(unblockedFlushCount);
058  }
059
060  /**
061   * Set the current blockcache size used gauge
062   * @param blockCacheSize the current memory usage in blockcache, in bytes.
063   */
064  public void setCurBlockCacheSizeGauge(final long blockCacheSize) {
065    source.setCurBlockCacheSizeGauge(blockCacheSize);
066  }
067
068  /**
069   * Set the current global memstore size used gauge
070   * @param memStoreSize the current memory usage in memstore, in bytes.
071   */
072  public void setCurMemStoreSizeGauge(final long memStoreSize) {
073    source.setCurMemStoreSizeGauge(memStoreSize);
074  }
075
076  /**
077   * Set the current global memstore on-heap size gauge
078   * @param memStoreOnHeapSize the current memory on-heap size in memstore, in bytes.
079   */
080  public void setCurMemStoreOnHeapSizeGauge(final long memStoreOnHeapSize) {
081    source.setCurMemStoreOnHeapSizeGauge(memStoreOnHeapSize);
082  }
083
084  /**
085   * Set the current global memstore off-heap size gauge
086   * @param memStoreOffHeapSize the current memory off-heap size in memstore, in bytes.
087   */
088  public void setCurMemStoreOffHeapSizeGauge(final long memStoreOffHeapSize) {
089    source.setCurMemStoreOffHeapSizeGauge(memStoreOffHeapSize);
090  }
091
092  /**
093   * Update the increase/decrease memstore size histogram
094   * @param memStoreDeltaSize the tuning result of memstore.
095   */
096  public void updateMemStoreDeltaSizeHistogram(final int memStoreDeltaSize) {
097    source.updateMemStoreDeltaSizeHistogram(memStoreDeltaSize);
098  }
099
100  /**
101   * Update the increase/decrease blockcache size histogram
102   * @param blockCacheDeltaSize the tuning result of blockcache.
103   */
104  public void updateBlockCacheDeltaSizeHistogram(final int blockCacheDeltaSize) {
105    source.updateBlockCacheDeltaSizeHistogram(blockCacheDeltaSize);
106  }
107
108  /**
109   * Increase the counter for tuner neither expanding memstore global size limit nor expanding
110   * blockcache max size.
111   */
112  public void increaseTunerDoNothingCounter() {
113    source.increaseTunerDoNothingCounter();
114  }
115
116  /**
117   * Increase the counter for heap occupancy percent above low watermark
118   */
119  public void increaseAboveHeapOccupancyLowWatermarkCounter() {
120    source.increaseAboveHeapOccupancyLowWatermarkCounter();
121  }
122}