HBASE-17748 Include HBase snapshots in space quotas
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / master / MetricsMaster.java
blobc896441c5f24ebef7265d6583abeb36664ff6289
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org.apache.hadoop.hbase.master;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
26 import org.apache.hadoop.hbase.metrics.Counter;
27 import org.apache.hadoop.hbase.metrics.Histogram;
28 import org.apache.hadoop.hbase.metrics.OperationMetrics;
29 import org.apache.hadoop.hbase.procedure2.ProcedureMetrics;
31 /**
32 * This class is for maintaining the various master statistics
33 * and publishing them through the metrics interfaces.
34 * <p>
35 * This class has a number of metrics variables that are publicly accessible;
36 * these variables (objects) have methods to update their values.
38 @InterfaceStability.Evolving
39 @InterfaceAudience.Private
40 public class MetricsMaster {
41 private static final Log LOG = LogFactory.getLog(MetricsMaster.class);
42 private MetricsMasterSource masterSource;
43 private MetricsMasterProcSource masterProcSource;
44 private MetricsMasterQuotaSource masterQuotaSource;
46 private ProcedureMetrics serverCrashProcMetrics;
48 public MetricsMaster(MetricsMasterWrapper masterWrapper) {
49 masterSource = CompatibilitySingletonFactory.getInstance(MetricsMasterSourceFactory.class).create(masterWrapper);
50 masterProcSource =
51 CompatibilitySingletonFactory.getInstance(MetricsMasterProcSourceFactory.class).create(masterWrapper);
52 masterQuotaSource =
53 CompatibilitySingletonFactory.getInstance(MetricsMasterQuotaSourceFactory.class).create(masterWrapper);
55 serverCrashProcMetrics = convertToProcedureMetrics(masterSource.getServerCrashMetrics());
58 // for unit-test usage
59 public MetricsMasterSource getMetricsSource() {
60 return masterSource;
63 public MetricsMasterProcSource getMetricsProcSource() {
64 return masterProcSource;
67 public MetricsMasterQuotaSource getMetricsQuotaSource() {
68 return masterQuotaSource;
71 /**
72 * @param inc How much to add to requests.
74 public void incrementRequests(final long inc) {
75 masterSource.incRequests(inc);
78 /**
79 * Sets the number of space quotas defined.
81 * @see MetricsMasterQuotaSource#updateNumSpaceQuotas(long)
83 public void setNumSpaceQuotas(final long numSpaceQuotas) {
84 masterQuotaSource.updateNumSpaceQuotas(numSpaceQuotas);
87 /**
88 * Sets the number of table in violation of a space quota.
90 * @see MetricsMasterQuotaSource#updateNumTablesInSpaceQuotaViolation(long)
92 public void setNumTableInSpaceQuotaViolation(final long numTablesInViolation) {
93 masterQuotaSource.updateNumTablesInSpaceQuotaViolation(numTablesInViolation);
96 /**
97 * Sets the number of namespaces in violation of a space quota.
99 * @see MetricsMasterQuotaSource#updateNumNamespacesInSpaceQuotaViolation(long)
101 public void setNumNamespacesInSpaceQuotaViolation(final long numNamespacesInViolation) {
102 masterQuotaSource.updateNumNamespacesInSpaceQuotaViolation(numNamespacesInViolation);
106 * Sets the number of region size reports the master currently has in memory.
108 * @see MetricsMasterQuotaSource#updateNumCurrentSpaceQuotaRegionSizeReports(long)
110 public void setNumRegionSizeReports(final long numRegionReports) {
111 masterQuotaSource.updateNumCurrentSpaceQuotaRegionSizeReports(numRegionReports);
115 * Sets the execution time of a period of the QuotaObserverChore.
117 * @param executionTime The execution time in milliseconds.
118 * @see MetricsMasterQuotaSource#incrementSpaceQuotaObserverChoreTime(long)
120 public void incrementQuotaObserverTime(final long executionTime) {
121 masterQuotaSource.incrementSpaceQuotaObserverChoreTime(executionTime);
125 * @return Set of metrics for assign procedure
127 public ProcedureMetrics getServerCrashProcMetrics() {
128 return serverCrashProcMetrics;
132 * This is utility function that converts {@link OperationMetrics} to {@link ProcedureMetrics}.
134 * NOTE: Procedure framework in hbase-procedure module accesses metrics common to most procedures
135 * through {@link ProcedureMetrics} interface. Metrics source classes in hbase-hadoop-compat
136 * module provides similar interface {@link OperationMetrics} that contains metrics common to
137 * most operations. As both hbase-procedure and hbase-hadoop-compat are lower level modules used
138 * by hbase-server (this) module and there is no dependency between them, this method does the
139 * required conversion.
141 public static ProcedureMetrics convertToProcedureMetrics(final OperationMetrics metrics) {
142 return new ProcedureMetrics() {
143 @Override
144 public Counter getSubmittedCounter() {
145 return metrics.getSubmittedCounter();
148 @Override
149 public Histogram getTimeHisto() {
150 return metrics.getTimeHisto();
153 @Override
154 public Counter getFailedCounter() {
155 return metrics.getFailedCounter();
161 * Sets the execution time of a period of the {@code SnapshotQuotaObserverChore}.
163 public void incrementSnapshotObserverTime(final long executionTime) {
164 masterQuotaSource.incrementSnapshotObserverChoreTime(executionTime);
168 * Sets the execution time to compute the size of a single snapshot.
170 public void incrementSnapshotSizeComputationTime(final long executionTime) {
171 masterQuotaSource.incrementSnapshotObserverSnapshotComputationTime(executionTime);
175 * Sets the execution time to fetch the mapping of snapshots to originating table.
177 public void incrementSnapshotFetchTime(long executionTime) {
178 masterQuotaSource.incrementSnapshotObserverSnapshotFetchTime(executionTime);