001/*
002 * Copyright The Apache Software Foundation
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with this
006 * work for additional information regarding copyright ownership. The ASF
007 * licenses this file to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance with the License.
009 * 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, WITHOUT
015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016 * License for the specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.hadoop.hbase.regionserver;
020
021import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
022import org.apache.yetus.audience.InterfaceAudience;
023
024
025/**
026 * This class is for maintaining the various regionserver's heap memory manager statistics and
027 * publishing them through the metrics interfaces.
028 */
029@InterfaceAudience.Private
030public class MetricsHeapMemoryManager {
031  private final MetricsHeapMemoryManagerSource source;
032
033  public MetricsHeapMemoryManager() {
034    this(CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
035        .getHeapMemoryManager());
036  }
037
038  public MetricsHeapMemoryManager(MetricsHeapMemoryManagerSource source) {
039    this.source = source;
040  }
041
042  public MetricsHeapMemoryManagerSource getMetricsSource() {
043    return source;
044  }
045
046  /**
047   * Update/Set the blocked flush count histogram/gauge
048   * @param blockedFlushCount the number of blocked memstore flush since last tuning.
049   */
050  public void updateBlockedFlushCount(final long blockedFlushCount) {
051    source.updateBlockedFlushCount(blockedFlushCount);
052  }
053
054  /**
055   * Update/Set the unblocked flush count histogram/gauge
056   * @param unblockedFlushCount the number of unblocked memstore flush since last tuning.
057   */
058  public void updateUnblockedFlushCount(final long unblockedFlushCount) {
059    source.updateUnblockedFlushCount(unblockedFlushCount);
060  }
061
062  /**
063   * Set the current blockcache size used gauge
064   * @param blockCacheSize the current memory usage in blockcache, in bytes.
065   */
066  public void setCurBlockCacheSizeGauge(final long blockCacheSize) {
067    source.setCurBlockCacheSizeGauge(blockCacheSize);
068  }
069
070  /**
071   * Set the current global memstore size used gauge
072   * @param memStoreSize the current memory usage in memstore, in bytes.
073   */
074  public void setCurMemStoreSizeGauge(final long memStoreSize) {
075    source.setCurMemStoreSizeGauge(memStoreSize);
076  }
077
078  /**
079   * Update the increase/decrease memstore size histogram
080   * @param memStoreDeltaSize the tuning result of memstore.
081   */
082  public void updateMemStoreDeltaSizeHistogram(final int memStoreDeltaSize) {
083    source.updateMemStoreDeltaSizeHistogram(memStoreDeltaSize);
084  }
085
086  /**
087   * Update the increase/decrease blockcache size histogram
088   * @param blockCacheDeltaSize the tuning result of blockcache.
089   */
090  public void updateBlockCacheDeltaSizeHistogram(final int blockCacheDeltaSize) {
091    source.updateBlockCacheDeltaSizeHistogram(blockCacheDeltaSize);
092  }
093
094  /**
095   * Increase the counter for tuner neither expanding memstore global size limit nor expanding
096   * blockcache max size.
097   */
098  public void increaseTunerDoNothingCounter() {
099    source.increaseTunerDoNothingCounter();
100  }
101
102  /**
103   * Increase the counter for heap occupancy percent above low watermark
104   */
105  public void increaseAboveHeapOccupancyLowWatermarkCounter() {
106    source.increaseAboveHeapOccupancyLowWatermarkCounter();
107  }
108}