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 * Record a single instance of a split
63 * @param time time that the split took
64 * @param size length of original HLogs that were split
65 */
66 public synchronized void addMetaWALSplit(long time, long size) {
67 masterSource.updateMetaWALSplitTime(time);
68 masterSource.updateMetaWALSplitSize(size);
69 }
70
71 /**
72 * @param inc How much to add to requests.
73 */
74 public void incrementRequests(final int inc) {
75 masterSource.incRequests(inc);
76
77 }
78
79 /**
80 * set new value for number of regions in transition.
81 * @param ritCount
82 */
83 public void updateRITCount(int ritCount) {
84 masterSource.setRIT(ritCount);
85 }
86
87 /**
88 * update RIT count that are in this state for more than the threshold
89 * as defined by the property rit.metrics.threshold.time.
90 * @param ritCountOverThreshold
91 */
92 public void updateRITCountOverThreshold(int ritCountOverThreshold) {
93 masterSource.setRITCountOverThreshold(ritCountOverThreshold);
94 }
95 /**
96 * update the timestamp for oldest region in transition metrics.
97 * @param timestamp
98 */
99 public void updateRITOldestAge(long timestamp) {
100 masterSource.setRITOldestAge(timestamp);
101 }
102
103 /**
104 * Record a single instance of a snapshot
105 * @param time time that the snapshot took
106 */
107 public void addSnapshot(long time) {
108 masterSource.updateSnapshotTime(time);
109 }
110
111 /**
112 * Record a single instance of a snapshot
113 * @param time time that the snapshot restore took
114 */
115 public void addSnapshotRestore(long time) {
116 masterSource.updateSnapshotRestoreTime(time);
117 }
118
119 /**
120 * Record a single instance of a snapshot cloned table
121 * @param time time that the snapshot clone took
122 */
123 public void addSnapshotClone(long time) {
124 masterSource.updateSnapshotCloneTime(time);
125 }
126 }