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 */ 018 019package org.apache.hadoop.hbase.master; 020 021import static org.apache.hadoop.hbase.master.MetricsMaster.convertToProcedureMetrics; 022 023import org.apache.hadoop.hbase.CompatibilitySingletonFactory; 024import org.apache.hadoop.hbase.procedure2.ProcedureMetrics; 025import org.apache.yetus.audience.InterfaceAudience; 026 027@InterfaceAudience.Private 028public class MetricsAssignmentManager { 029 private final MetricsAssignmentManagerSource assignmentManagerSource; 030 031 private final ProcedureMetrics assignProcMetrics; 032 private final ProcedureMetrics unassignProcMetrics; 033 private final ProcedureMetrics splitProcMetrics; 034 private final ProcedureMetrics mergeProcMetrics; 035 036 public MetricsAssignmentManager() { 037 assignmentManagerSource = CompatibilitySingletonFactory.getInstance( 038 MetricsAssignmentManagerSource.class); 039 040 assignProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getAssignMetrics()); 041 unassignProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getUnassignMetrics()); 042 splitProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getSplitMetrics()); 043 mergeProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getMergeMetrics()); 044 } 045 046 public MetricsAssignmentManagerSource getMetricsProcSource() { 047 return assignmentManagerSource; 048 } 049 050 /** 051 * set new value for number of regions in transition. 052 * @param ritCount 053 */ 054 public void updateRITCount(final int ritCount) { 055 assignmentManagerSource.setRIT(ritCount); 056 } 057 058 /** 059 * update RIT count that are in this state for more than the threshold 060 * as defined by the property rit.metrics.threshold.time. 061 * @param ritCountOverThreshold 062 */ 063 public void updateRITCountOverThreshold(final int ritCountOverThreshold) { 064 assignmentManagerSource.setRITCountOverThreshold(ritCountOverThreshold); 065 } 066 067 /** 068 * update the timestamp for oldest region in transition metrics. 069 * @param timestamp 070 */ 071 public void updateRITOldestAge(final long timestamp) { 072 assignmentManagerSource.setRITOldestAge(timestamp); 073 } 074 075 /** 076 * update the duration metrics of region is transition 077 * @param duration 078 */ 079 public void updateRitDuration(long duration) { 080 assignmentManagerSource.updateRitDuration(duration); 081 } 082 083 /* 084 * TODO: Remove. This may not be required as assign and unassign operations are tracked separately 085 * Increment the count of assignment operation (assign/unassign). 086 */ 087 public void incrementOperationCounter() { 088 assignmentManagerSource.incrementOperationCounter(); 089 } 090 091 /** 092 * @return Set of common metrics for assign procedure 093 */ 094 public ProcedureMetrics getAssignProcMetrics() { 095 return assignProcMetrics; 096 } 097 098 /** 099 * @return Set of common metrics for unassign procedure 100 */ 101 public ProcedureMetrics getUnassignProcMetrics() { 102 return unassignProcMetrics; 103 } 104 105 /** 106 * @return Set of common metrics for split procedure 107 */ 108 public ProcedureMetrics getSplitProcMetrics() { 109 return splitProcMetrics; 110 } 111 112 /** 113 * @return Set of common metrics for merge procedure 114 */ 115 public ProcedureMetrics getMergeProcMetrics() { 116 return mergeProcMetrics; 117 } 118}