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  
19  package org.apache.hadoop.hbase.replication.regionserver;
20  
21  import org.apache.hadoop.metrics2.lib.MutableFastCounter;
22  import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
23  import org.apache.hadoop.metrics2.lib.MutableHistogram;
24  
25  public class MetricsReplicationGlobalSourceSource implements MetricsReplicationSourceSource{
26    private final MetricsReplicationSourceImpl rms;
27  
28    @Deprecated
29    private final MutableGaugeLong ageOfLastShippedOpGauge;
30    private final MutableHistogram ageOfLastShippedOpHist;
31    private final MutableGaugeLong sizeOfLogQueueGauge;
32    private final MutableFastCounter logReadInEditsCounter;
33    private final MutableFastCounter logEditsFilteredCounter;
34    private final MutableFastCounter shippedBatchesCounter;
35    private final MutableFastCounter shippedOpsCounter;
36    private final MutableFastCounter shippedBytesCounter;
37    @Deprecated
38    private final MutableFastCounter shippedKBsCounter;
39    private final MutableFastCounter logReadInBytesCounter;
40    private final MutableFastCounter shippedHFilesCounter;
41    private final MutableGaugeLong sizeOfHFileRefsQueueGauge;
42    private final MutableFastCounter unknownFileLengthForClosedWAL;
43    private final MutableFastCounter uncleanlyClosedWAL;
44    private final MutableFastCounter uncleanlyClosedSkippedBytes;
45    private final MutableFastCounter restartWALReading;
46    private final MutableFastCounter repeatedFileBytes;
47    private final MutableFastCounter completedWAL;
48    private final MutableFastCounter completedRecoveryQueue;
49  
50    public MetricsReplicationGlobalSourceSource(MetricsReplicationSourceImpl rms) {
51      this.rms = rms;
52  
53      ageOfLastShippedOpHist = rms.getMetricsRegistry().getHistogram(SOURCE_AGE_OF_LAST_SHIPPED_OP);
54      ageOfLastShippedOpGauge = rms.getMetricsRegistry()
55          .getCompatibilityRegistry().getGauge(SOURCE_AGE_OF_LAST_SHIPPED_OP, 0L);
56  
57      sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(SOURCE_SIZE_OF_LOG_QUEUE, 0L);
58  
59      shippedBatchesCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_BATCHES, 0L);
60  
61      shippedOpsCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_OPS, 0L);
62  
63      shippedKBsCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_KBS, 0L);
64  
65      shippedBytesCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_BYTES, 0L);
66  
67      logReadInBytesCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_READ_IN_BYTES, 0L);
68  
69      logReadInEditsCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_READ_IN_EDITS, 0L);
70  
71      logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_EDITS_FILTERED, 0L);
72  
73      shippedHFilesCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_HFILES, 0L);
74  
75      sizeOfHFileRefsQueueGauge =
76          rms.getMetricsRegistry().getGauge(SOURCE_SIZE_OF_HFILE_REFS_QUEUE, 0L);
77  
78      unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getCounter(SOURCE_CLOSED_LOGS_WITH_UNKNOWN_LENGTH, 0L);
79      uncleanlyClosedWAL = rms.getMetricsRegistry().getCounter(SOURCE_UNCLEANLY_CLOSED_LOGS, 0L);
80      uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getCounter(SOURCE_UNCLEANLY_CLOSED_IGNORED_IN_BYTES, 0L);
81      restartWALReading = rms.getMetricsRegistry().getCounter(SOURCE_RESTARTED_LOG_READING, 0L);
82      repeatedFileBytes = rms.getMetricsRegistry().getCounter(SOURCE_REPEATED_LOG_FILE_BYTES, 0L);
83      completedWAL = rms.getMetricsRegistry().getCounter(SOURCE_COMPLETED_LOGS, 0L);
84      completedRecoveryQueue = rms.getMetricsRegistry().getCounter(SOURCE_COMPLETED_RECOVERY_QUEUES, 0L);
85    }
86  
87    @Override public void setLastShippedAge(long age) {
88      ageOfLastShippedOpHist.add(age);
89      ageOfLastShippedOpGauge.set(getLastShippedAge());
90    }
91  
92    @Override public void incrSizeOfLogQueue(int size) {
93      sizeOfLogQueueGauge.incr(size);
94    }
95  
96    @Override public void decrSizeOfLogQueue(int size) {
97      sizeOfLogQueueGauge.decr(size);
98    }
99  
100   @Override public void incrLogReadInEdits(long size) {
101     logReadInEditsCounter.incr(size);
102   }
103 
104   @Override public void incrLogEditsFiltered(long size) {
105     logEditsFilteredCounter.incr(size);
106   }
107 
108   @Override public void incrBatchesShipped(int batches) {
109     shippedBatchesCounter.incr(batches);
110   }
111 
112   @Override public void incrOpsShipped(long ops) {
113     shippedOpsCounter.incr(ops);
114   }
115 
116   @Override public void incrShippedBytes(long size) {
117     shippedBytesCounter.incr(size);
118     // obtained value maybe smaller than 1024. We should make sure that KB count
119     // eventually picks up even from multiple smaller updates.
120     incrementKBsCounter(shippedBytesCounter, shippedKBsCounter);
121   }
122 
123   static void incrementKBsCounter(MutableFastCounter bytesCounter, MutableFastCounter kbsCounter) {
124     // Following code should be thread-safe.
125     long delta = 0;
126     while(true) {
127       long bytes = bytesCounter.value();
128       delta = (bytes / 1024) - kbsCounter.value();
129       if (delta > 0) {
130         kbsCounter.incr(delta);
131       } else {
132         break;
133       }
134     }
135   }
136 
137   @Override public void incrLogReadInBytes(long size) {
138     logReadInBytesCounter.incr(size);
139   }
140 
141   @Override public void clear() {
142   }
143 
144   @Override
145   public long getLastShippedAge() {
146     return ageOfLastShippedOpHist.getMax();
147   }
148 
149   @Override public void incrHFilesShipped(long hfiles) {
150     shippedHFilesCounter.incr(hfiles);
151   }
152 
153   @Override
154   public void incrSizeOfHFileRefsQueue(long size) {
155     sizeOfHFileRefsQueueGauge.incr(size);
156   }
157 
158   @Override
159   public void decrSizeOfHFileRefsQueue(long size) {
160     sizeOfHFileRefsQueueGauge.decr(size);
161   }
162 
163   @Override
164   public int getSizeOfLogQueue() {
165     return (int)sizeOfLogQueueGauge.value();
166   }
167 
168   @Override
169   public void incrUnknownFileLengthForClosedWAL() {
170     unknownFileLengthForClosedWAL.incr(1L);
171   }
172   @Override
173   public void incrUncleanlyClosedWALs() {
174     uncleanlyClosedWAL.incr(1L);
175   }
176   @Override
177   public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
178     uncleanlyClosedSkippedBytes.incr(bytes);
179   }
180   @Override
181   public void incrRestartedWALReading() {
182     restartWALReading.incr(1L);
183   }
184   @Override
185   public void incrRepeatedFileBytes(final long bytes) {
186     repeatedFileBytes.incr(bytes);
187   }
188   @Override
189   public void incrCompletedWAL() {
190     completedWAL.incr(1L);
191   }
192   @Override
193   public void incrCompletedRecoveryQueue() {
194     completedRecoveryQueue.incr(1L);
195   }
196 
197 }