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   * Update the increase/decrease memstore size histogram
078   * @param memStoreDeltaSize the tuning result of memstore.
079   */
080  public void updateMemStoreDeltaSizeHistogram(final int memStoreDeltaSize) {
081    source.updateMemStoreDeltaSizeHistogram(memStoreDeltaSize);
082  }
083
084  /**
085   * Update the increase/decrease blockcache size histogram
086   * @param blockCacheDeltaSize the tuning result of blockcache.
087   */
088  public void updateBlockCacheDeltaSizeHistogram(final int blockCacheDeltaSize) {
089    source.updateBlockCacheDeltaSizeHistogram(blockCacheDeltaSize);
090  }
091
092  /**
093   * Increase the counter for tuner neither expanding memstore global size limit nor expanding
094   * blockcache max size.
095   */
096  public void increaseTunerDoNothingCounter() {
097    source.increaseTunerDoNothingCounter();
098  }
099
100  /**
101   * Increase the counter for heap occupancy percent above low watermark
102   */
103  public void increaseAboveHeapOccupancyLowWatermarkCounter() {
104    source.increaseAboveHeapOccupancyLowWatermarkCounter();
105  }
106}