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 */
018package org.apache.hadoop.hbase.regionserver;
019
020import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTED_INPUT_BYTES;
021import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTED_INPUT_BYTES_DESC;
022import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTED_OUTPUT_BYTES;
023import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTED_OUTPUT_BYTES_DESC;
024import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_INPUT_FILE_COUNT;
025import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_INPUT_FILE_COUNT_DESC;
026import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_INPUT_SIZE;
027import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_INPUT_SIZE_DESC;
028import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_OUTPUT_FILE_COUNT;
029import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_OUTPUT_FILE_COUNT_DESC;
030import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_OUTPUT_SIZE;
031import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_OUTPUT_SIZE_DESC;
032import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_TIME;
033import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.COMPACTION_TIME_DESC;
034import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSHED_MEMSTORE_BYTES;
035import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSHED_MEMSTORE_BYTES_DESC;
036import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSHED_OUTPUT_BYTES;
037import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSHED_OUTPUT_BYTES_DESC;
038import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_MEMSTORE_SIZE;
039import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_MEMSTORE_SIZE_DESC;
040import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_OUTPUT_SIZE;
041import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_OUTPUT_SIZE_DESC;
042import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_TIME;
043import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.FLUSH_TIME_DESC;
044import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTED_INPUT_BYTES;
045import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTED_INPUT_BYTES_DESC;
046import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTED_OUTPUT_BYTES;
047import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTED_OUTPUT_BYTES_DESC;
048import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_INPUT_FILE_COUNT;
049import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_INPUT_FILE_COUNT_DESC;
050import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_INPUT_SIZE;
051import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_INPUT_SIZE_DESC;
052import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_OUTPUT_FILE_COUNT;
053import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_OUTPUT_FILE_COUNT_DESC;
054import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_OUTPUT_SIZE;
055import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_OUTPUT_SIZE_DESC;
056import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_TIME;
057import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.MAJOR_COMPACTION_TIME_DESC;
058import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.SPLIT_KEY;
059import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.SPLIT_REQUEST_DESC;
060import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.SPLIT_REQUEST_KEY;
061import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.SPLIT_SUCCESS_DESC;
062import static org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource.SPLIT_SUCCESS_KEY;
063
064import java.util.Map;
065import java.util.Map.Entry;
066import java.util.concurrent.atomic.AtomicBoolean;
067import org.apache.hadoop.hbase.TableName;
068import org.apache.hadoop.hbase.metrics.Interns;
069import org.apache.hadoop.metrics2.MetricHistogram;
070import org.apache.hadoop.metrics2.MetricsRecordBuilder;
071import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
072import org.apache.hadoop.metrics2.lib.MutableFastCounter;
073import org.apache.yetus.audience.InterfaceAudience;
074import org.slf4j.Logger;
075import org.slf4j.LoggerFactory;
076
077@InterfaceAudience.Private
078public class MetricsTableSourceImpl implements MetricsTableSource {
079
080  private static final String _COLUMNFAMILY = "_columnfamily_";
081
082  private static final Logger LOG = LoggerFactory.getLogger(MetricsTableSourceImpl.class);
083
084  private AtomicBoolean closed = new AtomicBoolean(false);
085
086  // Non-final so that we can null out the wrapper
087  // This is just paranoia. We really really don't want to
088  // leak a whole table by way of keeping the
089  // tableWrapper around too long.
090  private MetricsTableWrapperAggregate tableWrapperAgg;
091  private final MetricsTableAggregateSourceImpl agg;
092  private final DynamicMetricsRegistry registry;
093  private final String tableNamePrefix;
094  private final String tableNamePrefixPart1;
095  private final String tableNamePrefixPart2;
096  private final TableName tableName;
097  private final int hashCode;
098
099  // split related metrics
100  private MutableFastCounter splitRequest;
101  private MutableFastCounter splitSuccess;
102  private MetricHistogram splitTimeHisto;
103
104  // flush related metrics
105  private MetricHistogram flushTimeHisto;
106  private MetricHistogram flushMemstoreSizeHisto;
107  private MetricHistogram flushOutputSizeHisto;
108  private MutableFastCounter flushedMemstoreBytes;
109  private MutableFastCounter flushedOutputBytes;
110
111  // compaction related metrics
112  private MetricHistogram compactionTimeHisto;
113  private MetricHistogram compactionInputFileCountHisto;
114  private MetricHistogram compactionInputSizeHisto;
115  private MetricHistogram compactionOutputFileCountHisto;
116  private MetricHistogram compactionOutputSizeHisto;
117  private MutableFastCounter compactedInputBytes;
118  private MutableFastCounter compactedOutputBytes;
119
120  private MetricHistogram majorCompactionTimeHisto;
121  private MetricHistogram majorCompactionInputFileCountHisto;
122  private MetricHistogram majorCompactionInputSizeHisto;
123  private MetricHistogram majorCompactionOutputFileCountHisto;
124  private MetricHistogram majorCompactionOutputSizeHisto;
125  private MutableFastCounter majorCompactedInputBytes;
126  private MutableFastCounter majorCompactedOutputBytes;
127
128  public MetricsTableSourceImpl(String tblName, MetricsTableAggregateSourceImpl aggregate,
129    MetricsTableWrapperAggregate tblWrapperAgg) {
130    LOG.debug("Creating new MetricsTableSourceImpl for table '{}'", tblName);
131    this.tableName = TableName.valueOf(tblName);
132    this.agg = aggregate;
133
134    this.tableWrapperAgg = tblWrapperAgg;
135    this.registry = agg.getMetricsRegistry();
136    this.tableNamePrefixPart1 = "Namespace_" + this.tableName.getNamespaceAsString() + "_table_"
137      + this.tableName.getQualifierAsString();
138    this.tableNamePrefixPart2 = "_metric_";
139    this.tableNamePrefix = tableNamePrefixPart1 + tableNamePrefixPart2;
140    this.hashCode = this.tableName.hashCode();
141  }
142
143  @Override
144  public synchronized void registerMetrics() {
145    flushTimeHisto = registry.newTimeHistogram(tableNamePrefix + FLUSH_TIME, FLUSH_TIME_DESC);
146    flushMemstoreSizeHisto =
147      registry.newSizeHistogram(tableNamePrefix + FLUSH_MEMSTORE_SIZE, FLUSH_MEMSTORE_SIZE_DESC);
148    flushOutputSizeHisto =
149      registry.newSizeHistogram(tableNamePrefix + FLUSH_OUTPUT_SIZE, FLUSH_OUTPUT_SIZE_DESC);
150    flushedOutputBytes =
151      registry.newCounter(tableNamePrefix + FLUSHED_OUTPUT_BYTES, FLUSHED_OUTPUT_BYTES_DESC, 0L);
152    flushedMemstoreBytes = registry.newCounter(tableNamePrefix + FLUSHED_MEMSTORE_BYTES,
153      FLUSHED_MEMSTORE_BYTES_DESC, 0L);
154
155    compactionTimeHisto =
156      registry.newTimeHistogram(tableNamePrefix + COMPACTION_TIME, COMPACTION_TIME_DESC);
157    compactionInputFileCountHisto = registry.newHistogram(
158      tableNamePrefix + COMPACTION_INPUT_FILE_COUNT, COMPACTION_INPUT_FILE_COUNT_DESC);
159    compactionInputSizeHisto = registry.newSizeHistogram(tableNamePrefix + COMPACTION_INPUT_SIZE,
160      COMPACTION_INPUT_SIZE_DESC);
161    compactionOutputFileCountHisto = registry.newHistogram(
162      tableNamePrefix + COMPACTION_OUTPUT_FILE_COUNT, COMPACTION_OUTPUT_FILE_COUNT_DESC);
163    compactionOutputSizeHisto = registry.newSizeHistogram(tableNamePrefix + COMPACTION_OUTPUT_SIZE,
164      COMPACTION_OUTPUT_SIZE_DESC);
165    compactedInputBytes =
166      registry.newCounter(tableNamePrefix + COMPACTED_INPUT_BYTES, COMPACTED_INPUT_BYTES_DESC, 0L);
167    compactedOutputBytes = registry.newCounter(tableNamePrefix + COMPACTED_OUTPUT_BYTES,
168      COMPACTED_OUTPUT_BYTES_DESC, 0L);
169
170    majorCompactionTimeHisto = registry.newTimeHistogram(tableNamePrefix + MAJOR_COMPACTION_TIME,
171      MAJOR_COMPACTION_TIME_DESC);
172    majorCompactionInputFileCountHisto = registry.newHistogram(
173      tableNamePrefix + MAJOR_COMPACTION_INPUT_FILE_COUNT, MAJOR_COMPACTION_INPUT_FILE_COUNT_DESC);
174    majorCompactionInputSizeHisto = registry.newSizeHistogram(
175      tableNamePrefix + MAJOR_COMPACTION_INPUT_SIZE, MAJOR_COMPACTION_INPUT_SIZE_DESC);
176    majorCompactionOutputFileCountHisto =
177      registry.newHistogram(tableNamePrefix + MAJOR_COMPACTION_OUTPUT_FILE_COUNT,
178        MAJOR_COMPACTION_OUTPUT_FILE_COUNT_DESC);
179    majorCompactionOutputSizeHisto = registry.newSizeHistogram(
180      tableNamePrefix + MAJOR_COMPACTION_OUTPUT_SIZE, MAJOR_COMPACTION_OUTPUT_SIZE_DESC);
181    majorCompactedInputBytes = registry.newCounter(tableNamePrefix + MAJOR_COMPACTED_INPUT_BYTES,
182      MAJOR_COMPACTED_INPUT_BYTES_DESC, 0L);
183    majorCompactedOutputBytes = registry.newCounter(tableNamePrefix + MAJOR_COMPACTED_OUTPUT_BYTES,
184      MAJOR_COMPACTED_OUTPUT_BYTES_DESC, 0L);
185
186    splitTimeHisto = registry.newTimeHistogram(tableNamePrefix + SPLIT_KEY);
187    splitRequest = registry.newCounter(tableNamePrefix + SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0L);
188    splitSuccess = registry.newCounter(tableNamePrefix + SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0L);
189  }
190
191  private void deregisterMetrics() {
192    registry.removeHistogramMetrics(tableNamePrefix + FLUSH_TIME);
193    registry.removeHistogramMetrics(tableNamePrefix + FLUSH_MEMSTORE_SIZE);
194    registry.removeHistogramMetrics(tableNamePrefix + FLUSH_OUTPUT_SIZE);
195    registry.removeMetric(tableNamePrefix + FLUSHED_OUTPUT_BYTES);
196    registry.removeMetric(tableNamePrefix + FLUSHED_MEMSTORE_BYTES);
197    registry.removeHistogramMetrics(tableNamePrefix + COMPACTION_TIME);
198    registry.removeHistogramMetrics(tableNamePrefix + COMPACTION_INPUT_FILE_COUNT);
199    registry.removeHistogramMetrics(tableNamePrefix + COMPACTION_INPUT_SIZE);
200    registry.removeHistogramMetrics(tableNamePrefix + COMPACTION_OUTPUT_FILE_COUNT);
201    registry.removeHistogramMetrics(tableNamePrefix + COMPACTION_OUTPUT_SIZE);
202    registry.removeMetric(tableNamePrefix + COMPACTED_INPUT_BYTES);
203    registry.removeMetric(tableNamePrefix + COMPACTED_OUTPUT_BYTES);
204    registry.removeHistogramMetrics(tableNamePrefix + MAJOR_COMPACTION_TIME);
205    registry.removeHistogramMetrics(tableNamePrefix + MAJOR_COMPACTION_INPUT_FILE_COUNT);
206    registry.removeHistogramMetrics(tableNamePrefix + MAJOR_COMPACTION_INPUT_SIZE);
207    registry.removeHistogramMetrics(tableNamePrefix + MAJOR_COMPACTION_OUTPUT_FILE_COUNT);
208    registry.removeHistogramMetrics(tableNamePrefix + MAJOR_COMPACTION_OUTPUT_SIZE);
209    registry.removeMetric(tableNamePrefix + MAJOR_COMPACTED_INPUT_BYTES);
210    registry.removeMetric(tableNamePrefix + MAJOR_COMPACTED_OUTPUT_BYTES);
211    registry.removeHistogramMetrics(tableNamePrefix + SPLIT_KEY);
212    registry.removeMetric(tableNamePrefix + SPLIT_REQUEST_KEY);
213    registry.removeMetric(tableNamePrefix + SPLIT_SUCCESS_KEY);
214  }
215
216  @Override
217  public void close() {
218    boolean wasClosed = closed.getAndSet(true);
219
220    // Has someone else already closed this for us?
221    if (wasClosed) {
222      return;
223    }
224
225    // Before removing the metrics remove this table from the aggregate table bean.
226    // This should mean that it's unlikely that snapshot and close happen at the same time.
227    agg.deleteTableSource(tableName.getNameAsString());
228
229    // While it's un-likely that snapshot and close happen at the same time it's still possible.
230    // So grab the lock to ensure that all calls to snapshot are done before we remove the metrics
231    synchronized (this) {
232      if (LOG.isTraceEnabled()) {
233        LOG.trace("Removing table Metrics for table ");
234      }
235      deregisterMetrics();
236      tableWrapperAgg = null;
237    }
238  }
239
240  @Override
241  public MetricsTableAggregateSource getAggregateSource() {
242    return agg;
243  }
244
245  @Override
246  public int compareTo(MetricsTableSource source) {
247    if (!(source instanceof MetricsTableSourceImpl)) {
248      return -1;
249    }
250    MetricsTableSourceImpl impl = (MetricsTableSourceImpl) source;
251    return Long.compare(hashCode, impl.hashCode);
252  }
253
254  void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
255    // If there is a close that started be double extra sure
256    // that we're not getting any locks and not putting data
257    // into the metrics that should be removed. So early out
258    // before even getting the lock.
259    if (closed.get()) {
260      return;
261    }
262
263    // Grab the read
264    // This ensures that removes of the metrics
265    // can't happen while we are putting them back in.
266    synchronized (this) {
267      // It's possible that a close happened between checking
268      // the closed variable and getting the lock.
269      if (closed.get()) {
270        return;
271      }
272
273      if (this.tableWrapperAgg != null) {
274        mrb.addCounter(
275          Interns.info(tableNamePrefix + MetricsRegionServerSource.CP_REQUEST_COUNT,
276            MetricsRegionServerSource.CP_REQUEST_COUNT_DESC),
277          tableWrapperAgg.getCpRequestsCount(tableName.getNameAsString()));
278        mrb.addCounter(
279          Interns.info(tableNamePrefix + MetricsRegionServerSource.READ_REQUEST_COUNT,
280            MetricsRegionServerSource.READ_REQUEST_COUNT_DESC),
281          tableWrapperAgg.getReadRequestCount(tableName.getNameAsString()));
282        mrb.addCounter(
283          Interns.info(tableNamePrefix + MetricsRegionServerSource.FILTERED_READ_REQUEST_COUNT,
284            MetricsRegionServerSource.FILTERED_READ_REQUEST_COUNT_DESC),
285          tableWrapperAgg.getFilteredReadRequestCount(tableName.getNameAsString()));
286        mrb.addCounter(
287          Interns.info(tableNamePrefix + MetricsRegionServerSource.WRITE_REQUEST_COUNT,
288            MetricsRegionServerSource.WRITE_REQUEST_COUNT_DESC),
289          tableWrapperAgg.getWriteRequestCount(tableName.getNameAsString()));
290        mrb.addCounter(
291          Interns.info(tableNamePrefix + MetricsRegionServerSource.TOTAL_REQUEST_COUNT,
292            MetricsRegionServerSource.TOTAL_REQUEST_COUNT_DESC),
293          tableWrapperAgg.getTotalRequestsCount(tableName.getNameAsString()));
294        mrb.addGauge(
295          Interns.info(tableNamePrefix + MetricsRegionServerSource.MEMSTORE_SIZE,
296            MetricsRegionServerSource.MEMSTORE_SIZE_DESC),
297          tableWrapperAgg.getMemStoreSize(tableName.getNameAsString()));
298        mrb.addGauge(
299          Interns.info(tableNamePrefix + MetricsRegionServerSource.STOREFILE_COUNT,
300            MetricsRegionServerSource.STOREFILE_COUNT_DESC),
301          tableWrapperAgg.getNumStoreFiles(tableName.getNameAsString()));
302        mrb.addGauge(
303          Interns.info(tableNamePrefix + MetricsRegionServerSource.STOREFILE_SIZE,
304            MetricsRegionServerSource.STOREFILE_SIZE_DESC),
305          tableWrapperAgg.getStoreFileSize(tableName.getNameAsString()));
306        mrb.addGauge(
307          Interns.info(tableNamePrefix + MetricsTableSource.TABLE_SIZE,
308            MetricsTableSource.TABLE_SIZE_DESC),
309          tableWrapperAgg.getTableSize(tableName.getNameAsString()));
310        mrb.addGauge(
311          Interns.info(tableNamePrefix + MetricsRegionServerSource.AVERAGE_REGION_SIZE,
312            MetricsRegionServerSource.AVERAGE_REGION_SIZE_DESC),
313          tableWrapperAgg.getAvgRegionSize(tableName.getNameAsString()));
314        mrb.addGauge(
315          Interns.info(tableNamePrefix + MetricsRegionServerSource.REGION_COUNT,
316            MetricsRegionServerSource.REGION_COUNT_DESC),
317          tableWrapperAgg.getNumRegions(tableName.getNameAsString()));
318        mrb.addGauge(
319          Interns.info(tableNamePrefix + MetricsRegionServerSource.STORE_COUNT,
320            MetricsRegionServerSource.STORE_COUNT_DESC),
321          tableWrapperAgg.getNumStores(tableName.getNameAsString()));
322        mrb.addGauge(
323          Interns.info(tableNamePrefix + MetricsRegionServerSource.MAX_STORE_FILE_AGE,
324            MetricsRegionServerSource.MAX_STORE_FILE_AGE_DESC),
325          tableWrapperAgg.getMaxStoreFileAge(tableName.getNameAsString()));
326        mrb.addGauge(
327          Interns.info(tableNamePrefix + MetricsRegionServerSource.MIN_STORE_FILE_AGE,
328            MetricsRegionServerSource.MIN_STORE_FILE_AGE_DESC),
329          tableWrapperAgg.getMinStoreFileAge(tableName.getNameAsString()));
330        mrb.addGauge(
331          Interns.info(tableNamePrefix + MetricsRegionServerSource.AVG_STORE_FILE_AGE,
332            MetricsRegionServerSource.AVG_STORE_FILE_AGE_DESC),
333          tableWrapperAgg.getAvgStoreFileAge(tableName.getNameAsString()));
334        mrb.addGauge(
335          Interns.info(tableNamePrefix + MetricsRegionServerSource.NUM_REFERENCE_FILES,
336            MetricsRegionServerSource.NUM_REFERENCE_FILES_DESC),
337          tableWrapperAgg.getNumReferenceFiles(tableName.getNameAsString()));
338        addGauge(mrb, tableWrapperAgg.getMemstoreOnlyRowReadsCount(tableName.getNameAsString()),
339          MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE,
340          MetricsRegionSource.ROW_READS_ONLY_ON_MEMSTORE_DESC);
341        addGauge(mrb, tableWrapperAgg.getMixedRowReadsCount(tableName.getNameAsString()),
342          MetricsRegionSource.MIXED_ROW_READS, MetricsRegionSource.MIXED_ROW_READS_ON_STORE_DESC);
343      }
344    }
345  }
346
347  private void addGauge(MetricsRecordBuilder mrb, Map<String, Long> metricMap, String metricName,
348    String metricDesc) {
349    if (metricMap != null) {
350      for (Entry<String, Long> entry : metricMap.entrySet()) {
351        // append 'store' and its name to the metric
352        mrb.addGauge(Interns.info(this.tableNamePrefixPart1 + _COLUMNFAMILY
353          + entry.getKey().split(MetricsTableWrapperAggregate.HASH)[1] + this.tableNamePrefixPart2
354          + metricName, metricDesc), entry.getValue());
355      }
356    }
357  }
358
359  @Override
360  public String getTableName() {
361    return tableName.getNameAsString();
362  }
363
364  @Override
365  public int hashCode() {
366    return hashCode;
367  }
368
369  @Override
370  public boolean equals(Object o) {
371    if (this == o) {
372      return true;
373    }
374
375    if (o == null || getClass() != o.getClass()) {
376      return false;
377    }
378
379    return (compareTo((MetricsTableSourceImpl) o) == 0);
380  }
381
382  public MetricsTableWrapperAggregate getTableWrapper() {
383    return tableWrapperAgg;
384  }
385
386  public String getTableNamePrefix() {
387    return tableNamePrefix;
388  }
389
390  @Override
391  public void incrSplitRequest() {
392    splitRequest.incr();
393  }
394
395  @Override
396  public void incrSplitSuccess() {
397    splitSuccess.incr();
398  }
399
400  @Override
401  public void updateSplitTime(long t) {
402    splitTimeHisto.add(t);
403  }
404
405  @Override
406  public void updateFlushTime(long t) {
407    flushTimeHisto.add(t);
408  }
409
410  @Override
411  public synchronized void updateFlushMemstoreSize(long bytes) {
412    flushMemstoreSizeHisto.add(bytes);
413    flushedMemstoreBytes.incr(bytes);
414  }
415
416  @Override
417  public synchronized void updateFlushOutputSize(long bytes) {
418    flushOutputSizeHisto.add(bytes);
419    flushedOutputBytes.incr(bytes);
420  }
421
422  @Override
423  public synchronized void updateCompactionTime(boolean isMajor, long t) {
424    compactionTimeHisto.add(t);
425    if (isMajor) {
426      majorCompactionTimeHisto.add(t);
427    }
428  }
429
430  @Override
431  public synchronized void updateCompactionInputFileCount(boolean isMajor, long c) {
432    compactionInputFileCountHisto.add(c);
433    if (isMajor) {
434      majorCompactionInputFileCountHisto.add(c);
435    }
436  }
437
438  @Override
439  public synchronized void updateCompactionInputSize(boolean isMajor, long bytes) {
440    compactionInputSizeHisto.add(bytes);
441    compactedInputBytes.incr(bytes);
442    if (isMajor) {
443      majorCompactionInputSizeHisto.add(bytes);
444      majorCompactedInputBytes.incr(bytes);
445    }
446  }
447
448  @Override
449  public synchronized void updateCompactionOutputFileCount(boolean isMajor, long c) {
450    compactionOutputFileCountHisto.add(c);
451    if (isMajor) {
452      majorCompactionOutputFileCountHisto.add(c);
453    }
454  }
455
456  @Override
457  public synchronized void updateCompactionOutputSize(boolean isMajor, long bytes) {
458    compactionOutputSizeHisto.add(bytes);
459    compactedOutputBytes.incr(bytes);
460    if (isMajor) {
461      majorCompactionOutputSizeHisto.add(bytes);
462      majorCompactedOutputBytes.incr(bytes);
463    }
464  }
465}