View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.master;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.classification.InterfaceAudience;
23  import org.apache.hadoop.classification.InterfaceStability;
24  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
25  import org.apache.hadoop.hbase.master.MetricsMasterSource;
26  import org.apache.hadoop.hbase.master.MetricsMasterSourceFactory;
27  import org.apache.hadoop.hbase.master.MetricsMasterWrapper;
28  
29  /**
30   * This class is for maintaining the various master statistics
31   * and publishing them through the metrics interfaces.
32   * <p>
33   * This class has a number of metrics variables that are publicly accessible;
34   * these variables (objects) have methods to update their values.
35   */
36  @InterfaceStability.Evolving
37  @InterfaceAudience.Private
38  public class MetricsMaster {
39    private final Log LOG = LogFactory.getLog(this.getClass());
40    private MetricsMasterSource masterSource;
41  
42    public MetricsMaster(MetricsMasterWrapper masterWrapper) {
43      masterSource = CompatibilitySingletonFactory.getInstance(MetricsMasterSourceFactory.class).create(masterWrapper);
44    }
45  
46    // for unit-test usage
47    public MetricsMasterSource getMetricsSource() {
48      return masterSource;
49    }
50  
51    /**
52     * Record a single instance of a split
53     * @param time time that the split took
54     * @param size length of original HLogs that were split
55     */
56    public synchronized void addSplit(long time, long size) {
57      masterSource.updateSplitTime(time);
58      masterSource.updateSplitSize(size);
59    }
60  
61    /**
62     * @param inc How much to add to requests.
63     */
64    public void incrementRequests(final int inc) {
65      masterSource.incRequests(inc);
66  
67    }
68  
69    /**
70     * set new value for number of regions in transition.
71     * @param ritCount
72     */
73    public void updateRITCount(int ritCount) {
74      masterSource.setRIT(ritCount);
75    }
76  
77    /**
78     * update RIT count that are in this state for more than the threshold
79     * as defined by the property rit.metrics.threshold.time.
80     * @param ritCountOverThreshold
81     */
82    public void updateRITCountOverThreshold(int ritCountOverThreshold) {
83      masterSource.setRITCountOverThreshold(ritCountOverThreshold);
84    }
85    /**
86     * update the timestamp for oldest region in transition metrics.
87     * @param timestamp
88     */
89    public void updateRITOldestAge(long timestamp) {
90      masterSource.setRITOldestAge(timestamp);
91    }
92  }