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  package org.apache.hadoop.hbase.regionserver;
19  
20  import java.io.IOException;
21  import java.util.Collection;
22  import java.util.List;
23  import java.util.concurrent.ScheduledExecutorService;
24  import java.util.concurrent.TimeUnit;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.hadoop.hbase.classification.InterfaceAudience;
30  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
31  import org.apache.hadoop.hbase.HConstants;
32  import org.apache.hadoop.hbase.HDFSBlocksDistribution;
33  import org.apache.hadoop.hbase.HRegionInfo;
34  import org.apache.hadoop.hbase.ServerName;
35  import org.apache.hadoop.hbase.io.hfile.BlockCache;
36  import org.apache.hadoop.hbase.io.hfile.CacheConfig;
37  import org.apache.hadoop.hbase.io.hfile.CacheStats;
38  import org.apache.hadoop.hbase.mob.MobCacheConfig;
39  import org.apache.hadoop.hbase.mob.MobFileCache;
40  import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource;
41  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
42  import org.apache.hadoop.hbase.util.FSUtils;
43  import org.apache.hadoop.hbase.wal.WALProvider;
44  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
45  import org.apache.hadoop.hdfs.DFSHedgedReadMetrics;
46  import org.apache.hadoop.metrics2.MetricsExecutor;
47  
48  /**
49   * Impl for exposing HRegionServer Information through Hadoop's metrics 2 system.
50   */
51  @InterfaceAudience.Private
52  class MetricsRegionServerWrapperImpl
53      implements MetricsRegionServerWrapper {
54  
55    private static final Log LOG = LogFactory.getLog(MetricsRegionServerWrapperImpl.class);
56  
57    private final HRegionServer regionServer;
58    private final MetricsWALSource metricsWALSource;
59  
60    private BlockCache blockCache;
61    private MobFileCache mobFileCache;
62  
63    private volatile long numStores = 0;
64    private volatile long numWALFiles = 0;
65    private volatile long walFileSize = 0;
66    private volatile long numStoreFiles = 0;
67    private volatile long memstoreSize = 0;
68    private volatile long storeFileSize = 0;
69    private volatile long maxStoreFileAge = 0;
70    private volatile long minStoreFileAge = 0;
71    private volatile long avgStoreFileAge = 0;
72    private volatile long numReferenceFiles = 0;
73    private volatile double requestsPerSecond = 0.0;
74    private volatile long readRequestsCount = 0;
75    private volatile long filteredReadRequestsCount = 0;
76    private volatile long writeRequestsCount = 0;
77    private volatile long checkAndMutateChecksFailed = 0;
78    private volatile long checkAndMutateChecksPassed = 0;
79    private volatile long storefileIndexSize = 0;
80    private volatile long totalStaticIndexSize = 0;
81    private volatile long totalStaticBloomSize = 0;
82    private volatile long numMutationsWithoutWAL = 0;
83    private volatile long dataInMemoryWithoutWAL = 0;
84    private volatile double percentFileLocal = 0;
85    private volatile double percentFileLocalSecondaryRegions = 0;
86    private volatile long flushedCellsCount = 0;
87    private volatile long compactedCellsCount = 0;
88    private volatile long majorCompactedCellsCount = 0;
89    private volatile long flushedCellsSize = 0;
90    private volatile long compactedCellsSize = 0;
91    private volatile long majorCompactedCellsSize = 0;
92    private volatile long cellsCountCompactedToMob = 0;
93    private volatile long cellsCountCompactedFromMob = 0;
94    private volatile long cellsSizeCompactedToMob = 0;
95    private volatile long cellsSizeCompactedFromMob = 0;
96    private volatile long mobFlushCount = 0;
97    private volatile long mobFlushedCellsCount = 0;
98    private volatile long mobFlushedCellsSize = 0;
99    private volatile long mobScanCellsCount = 0;
100   private volatile long mobScanCellsSize = 0;
101   private volatile long mobFileCacheAccessCount = 0;
102   private volatile long mobFileCacheMissCount = 0;
103   private volatile double mobFileCacheHitRatio = 0;
104   private volatile long mobFileCacheEvictedCount = 0;
105   private volatile long mobFileCacheCount = 0;
106   private volatile long blockedRequestsCount = 0L;
107   private volatile long averageRegionSize = 0L;
108 
109   private CacheStats cacheStats;
110   private ScheduledExecutorService executor;
111   private Runnable runnable;
112   private long period;
113 
114   /**
115    * Can be null if not on hdfs.
116    */
117   private DFSHedgedReadMetrics dfsHedgedReadMetrics;
118 
119   public MetricsRegionServerWrapperImpl(final HRegionServer regionServer) {
120     this.regionServer = regionServer;
121     initBlockCache();
122     initMobFileCache();
123 
124     this.period =
125         regionServer.conf.getLong(HConstants.REGIONSERVER_METRICS_PERIOD,
126           HConstants.DEFAULT_REGIONSERVER_METRICS_PERIOD);
127 
128     this.executor = CompatibilitySingletonFactory.getInstance(MetricsExecutor.class).getExecutor();
129     this.runnable = new RegionServerMetricsWrapperRunnable();
130     this.executor.scheduleWithFixedDelay(this.runnable, this.period, this.period,
131       TimeUnit.MILLISECONDS);
132     this.metricsWALSource = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
133 
134     try {
135       this.dfsHedgedReadMetrics = FSUtils.getDFSHedgedReadMetrics(regionServer.getConfiguration());
136     } catch (IOException e) {
137       LOG.warn("Failed to get hedged metrics", e);
138     }
139     if (LOG.isInfoEnabled()) {
140       LOG.info("Computing regionserver metrics every " + this.period + " milliseconds");
141     }
142   }
143 
144   /**
145    * It's possible that due to threading the block cache could not be initialized
146    * yet (testing multiple region servers in one jvm).  So we need to try and initialize
147    * the blockCache and cacheStats reference multiple times until we succeed.
148    */
149   private synchronized  void initBlockCache() {
150     CacheConfig cacheConfig = this.regionServer.cacheConfig;
151     if (cacheConfig != null && this.blockCache == null) {
152       this.blockCache = cacheConfig.getBlockCache();
153     }
154 
155     if (this.blockCache != null && this.cacheStats == null) {
156       this.cacheStats = blockCache.getStats();
157     }
158   }
159 
160   /**
161    * Initializes the mob file cache.
162    */
163   private synchronized void initMobFileCache() {
164     MobCacheConfig mobCacheConfig = this.regionServer.mobCacheConfig;
165     if (mobCacheConfig != null && this.mobFileCache == null) {
166       this.mobFileCache = mobCacheConfig.getMobFileCache();
167     }
168   }
169 
170   @Override
171   public String getClusterId() {
172     return regionServer.getClusterId();
173   }
174 
175   @Override
176   public long getStartCode() {
177     return regionServer.getStartcode();
178   }
179 
180   @Override
181   public String getZookeeperQuorum() {
182     ZooKeeperWatcher zk = regionServer.getZooKeeper();
183     if (zk == null) {
184       return "";
185     }
186     return zk.getQuorum();
187   }
188 
189   @Override
190   public String getCoprocessors() {
191     String[] coprocessors = regionServer.getRegionServerCoprocessors();
192     if (coprocessors == null || coprocessors.length == 0) {
193       return "";
194     }
195     return StringUtils.join(coprocessors, ", ");
196   }
197 
198   @Override
199   public String getServerName() {
200     ServerName serverName = regionServer.getServerName();
201     if (serverName == null) {
202       return "";
203     }
204     return serverName.getServerName();
205   }
206 
207   @Override
208   public long getNumOnlineRegions() {
209     Collection<Region> onlineRegionsLocalContext = regionServer.getOnlineRegionsLocalContext();
210     if (onlineRegionsLocalContext == null) {
211       return 0;
212     }
213     return onlineRegionsLocalContext.size();
214   }
215 
216   @Override
217   public long getTotalRequestCount() {
218     return regionServer.rpcServices.requestCount.get();
219   }
220 
221   @Override
222   public int getSplitQueueSize() {
223     if (this.regionServer.compactSplitThread == null) {
224       return 0;
225     }
226     return this.regionServer.compactSplitThread.getSplitQueueSize();
227   }
228 
229   @Override
230   public int getCompactionQueueSize() {
231     //The thread could be zero.  if so assume there is no queue.
232     if (this.regionServer.compactSplitThread == null) {
233       return 0;
234     }
235     return this.regionServer.compactSplitThread.getCompactionQueueSize();
236   }
237 
238   @Override
239   public int getSmallCompactionQueueSize() {
240     //The thread could be zero.  if so assume there is no queue.
241     if (this.regionServer.compactSplitThread == null) {
242       return 0;
243     }
244     return this.regionServer.compactSplitThread.getSmallCompactionQueueSize();
245   }
246 
247   @Override
248   public int getLargeCompactionQueueSize() {
249     //The thread could be zero.  if so assume there is no queue.
250     if (this.regionServer.compactSplitThread == null) {
251       return 0;
252     }
253     return this.regionServer.compactSplitThread.getLargeCompactionQueueSize();
254   }
255 
256   @Override
257   public int getFlushQueueSize() {
258     //If there is no flusher there should be no queue.
259     if (this.regionServer.cacheFlusher == null) {
260       return 0;
261     }
262     return this.regionServer.cacheFlusher.getFlushQueueSize();
263   }
264 
265   @Override
266   public long getBlockCacheCount() {
267     if (this.blockCache == null) {
268       return 0;
269     }
270     return this.blockCache.getBlockCount();
271   }
272 
273   @Override
274   public long getBlockCacheSize() {
275     if (this.blockCache == null) {
276       return 0;
277     }
278     return this.blockCache.getCurrentSize();
279   }
280 
281   @Override
282   public long getBlockCacheFreeSize() {
283     if (this.blockCache == null) {
284       return 0;
285     }
286     return this.blockCache.getFreeSize();
287   }
288 
289   @Override
290   public long getBlockCacheHitCount() {
291     if (this.cacheStats == null) {
292       return 0;
293     }
294     return this.cacheStats.getHitCount();
295   }
296 
297   @Override
298   public long getBlockCachePrimaryHitCount() {
299     if (this.cacheStats == null) {
300       return 0;
301     }
302     return this.cacheStats.getPrimaryHitCount();
303   }
304 
305   @Override
306   public long getBlockCacheMissCount() {
307     if (this.cacheStats == null) {
308       return 0;
309     }
310     return this.cacheStats.getMissCount();
311   }
312 
313   @Override
314   public long getBlockCachePrimaryMissCount() {
315     if (this.cacheStats == null) {
316       return 0;
317     }
318     return this.cacheStats.getPrimaryMissCount();
319   }
320 
321   @Override
322   public long getBlockCacheEvictedCount() {
323     if (this.cacheStats == null) {
324       return 0;
325     }
326     return this.cacheStats.getEvictedCount();
327   }
328 
329   @Override
330   public long getBlockCachePrimaryEvictedCount() {
331     if (this.cacheStats == null) {
332       return 0;
333     }
334     return this.cacheStats.getPrimaryEvictedCount();
335   }
336 
337   @Override
338   public double getBlockCacheHitPercent() {
339     if (this.cacheStats == null) {
340       return 0;
341     }
342     double ratio = this.cacheStats.getHitRatio();
343     if (Double.isNaN(ratio)) {
344       ratio = 0;
345     }
346     return (ratio * 100);
347   }
348 
349   @Override
350   public double getBlockCacheHitCachingPercent() {
351     if (this.cacheStats == null) {
352       return 0;
353     }
354 
355     double ratio = this.cacheStats.getHitCachingRatio();
356 
357     if (Double.isNaN(ratio)) {
358       ratio = 0;
359     }
360     return (ratio * 100);
361   }
362 
363   @Override
364   public long getBlockCacheFailedInsertions() {
365     if (this.cacheStats == null) {
366       return 0;
367     }
368     return this.cacheStats.getFailedInserts();
369   }
370
371   @Override public void forceRecompute() {
372     this.runnable.run();
373   }
374
375   @Override
376   public long getNumStores() {
377     return numStores;
378   }
379
380   @Override
381   public long getNumWALFiles() {
382     return numWALFiles;
383   }
384
385   @Override
386   public long getWALFileSize() {
387     return walFileSize;
388   }
389
390   @Override
391   public long getNumWALSlowAppend() {
392     return metricsWALSource.getSlowAppendCount();
393   }
394
395   @Override
396   public long getNumStoreFiles() {
397     return numStoreFiles;
398   }
399
400   @Override
401   public long getMaxStoreFileAge() {
402     return maxStoreFileAge;
403   }
404
405   @Override
406   public long getMinStoreFileAge() {
407     return minStoreFileAge;
408   }
409
410   @Override
411   public long getAvgStoreFileAge() {
412     return avgStoreFileAge;
413   }
414
415   @Override
416   public long getNumReferenceFiles() {
417     return numReferenceFiles;
418   }
419
420   @Override
421   public long getMemstoreSize() {
422     return memstoreSize;
423   }
424
425   @Override
426   public long getStoreFileSize() {
427     return storeFileSize;
428   }
429
430   @Override public double getRequestsPerSecond() {
431     return requestsPerSecond;
432   }
433
434   @Override
435   public long getReadRequestsCount() {
436     return readRequestsCount;
437   }
438
439   @Override
440   public long getFilteredReadRequestsCount() {
441     return filteredReadRequestsCount;
442   }
443
444   @Override
445   public long getWriteRequestsCount() {
446     return writeRequestsCount;
447   }
448
449   @Override
450   public long getRpcGetRequestsCount() {
451     return regionServer.rpcServices.rpcGetRequestCount.get();
452   }
453
454   @Override
455   public long getRpcScanRequestsCount() {
456     return regionServer.rpcServices.rpcScanRequestCount.get();
457   }
458
459   @Override
460   public long getRpcMultiRequestsCount() {
461     return regionServer.rpcServices.rpcMultiRequestCount.get();
462   }
463
464   @Override
465   public long getRpcMutateRequestsCount() {
466     return regionServer.rpcServices.rpcMutateRequestCount.get();
467   }
468
469   @Override
470   public long getCheckAndMutateChecksFailed() {
471     return checkAndMutateChecksFailed;
472   }
473
474   @Override
475   public long getCheckAndMutateChecksPassed() {
476     return checkAndMutateChecksPassed;
477   }
478
479   @Override
480   public long getStoreFileIndexSize() {
481     return storefileIndexSize;
482   }
483
484   @Override
485   public long getTotalStaticIndexSize() {
486     return totalStaticIndexSize;
487   }
488
489   @Override
490   public long getTotalStaticBloomSize() {
491     return totalStaticBloomSize;
492   }
493
494   @Override
495   public long getNumMutationsWithoutWAL() {
496     return numMutationsWithoutWAL;
497   }
498
499   @Override
500   public long getDataInMemoryWithoutWAL() {
501     return dataInMemoryWithoutWAL;
502   }
503
504   @Override
505   public double getPercentFileLocal() {
506     return percentFileLocal;
507   }
508
509   @Override
510   public double getPercentFileLocalSecondaryRegions() {
511     return percentFileLocalSecondaryRegions;
512   }
513
514   @Override
515   public long getUpdatesBlockedTime() {
516     if (this.regionServer.cacheFlusher == null) {
517       return 0;
518     }
519     return this.regionServer.cacheFlusher.getUpdatesBlockedMsHighWater().get();
520   }
521
522   @Override
523   public long getFlushedCellsCount() {
524     return flushedCellsCount;
525   }
526
527   @Override
528   public long getCompactedCellsCount() {
529     return compactedCellsCount;
530   }
531
532   @Override
533   public long getMajorCompactedCellsCount() {
534     return majorCompactedCellsCount;
535   }
536
537   @Override
538   public long getFlushedCellsSize() {
539     return flushedCellsSize;
540   }
541
542   @Override
543   public long getCompactedCellsSize() {
544     return compactedCellsSize;
545   }
546
547   @Override
548   public long getMajorCompactedCellsSize() {
549     return majorCompactedCellsSize;
550   }
551
552   @Override
553   public long getCellsCountCompactedFromMob() {
554     return cellsCountCompactedFromMob;
555   }
556
557   @Override
558   public long getCellsCountCompactedToMob() {
559     return cellsCountCompactedToMob;
560   }
561
562   @Override
563   public long getCellsSizeCompactedFromMob() {
564     return cellsSizeCompactedFromMob;
565   }
566
567   @Override
568   public long getCellsSizeCompactedToMob() {
569     return cellsSizeCompactedToMob;
570   }
571
572   @Override
573   public long getMobFlushCount() {
574     return mobFlushCount;
575   }
576
577   @Override
578   public long getMobFlushedCellsCount() {
579     return mobFlushedCellsCount;
580   }
581
582   @Override
583   public long getMobFlushedCellsSize() {
584     return mobFlushedCellsSize;
585   }
586
587   @Override
588   public long getMobScanCellsCount() {
589     return mobScanCellsCount;
590   }
591
592   @Override
593   public long getMobScanCellsSize() {
594     return mobScanCellsSize;
595   }
596
597   @Override
598   public long getMobFileCacheAccessCount() {
599     return mobFileCacheAccessCount;
600   }
601
602   @Override
603   public long getMobFileCacheMissCount() {
604     return mobFileCacheMissCount;
605   }
606
607   @Override
608   public long getMobFileCacheCount() {
609     return mobFileCacheCount;
610   }
611
612   @Override
613   public long getMobFileCacheEvictedCount() {
614     return mobFileCacheEvictedCount;
615   }
616
617   @Override
618   public double getMobFileCacheHitPercent() {
619     return mobFileCacheHitRatio * 100;
620   }
621
622   /**
623    * This is the runnable that will be executed on the executor every PERIOD number of seconds
624    * It will take metrics/numbers from all of the regions and use them to compute point in
625    * time metrics.
626    */
627   public class RegionServerMetricsWrapperRunnable implements Runnable {
628 
629     private long lastRan = 0;
630     private long lastRequestCount = 0;
631
632     @Override
633     synchronized public void run() {
634       try {
635         initBlockCache();
636         initMobFileCache();
637
638         HDFSBlocksDistribution hdfsBlocksDistribution =
639             new HDFSBlocksDistribution();
640         HDFSBlocksDistribution hdfsBlocksDistributionSecondaryRegions =
641             new HDFSBlocksDistribution();
642
643         long tempNumStores = 0, tempNumStoreFiles = 0, tempMemstoreSize = 0, tempStoreFileSize = 0;
644         long tempMaxStoreFileAge = 0, tempNumReferenceFiles = 0;
645         long avgAgeNumerator = 0, numHFiles = 0;
646         long tempMinStoreFileAge = Long.MAX_VALUE;
647         long tempReadRequestsCount = 0, tempFilteredReadRequestsCount = 0,
648           tempWriteRequestsCount = 0;
649         long tempCheckAndMutateChecksFailed = 0;
650         long tempCheckAndMutateChecksPassed = 0;
651         long tempStorefileIndexSize = 0;
652         long tempTotalStaticIndexSize = 0;
653         long tempTotalStaticBloomSize = 0;
654         long tempNumMutationsWithoutWAL = 0;
655         long tempDataInMemoryWithoutWAL = 0;
656         double tempPercentFileLocal = 0;
657         double tempPercentFileLocalSecondaryRegions = 0;
658         long tempFlushedCellsCount = 0;
659         long tempCompactedCellsCount = 0;
660         long tempMajorCompactedCellsCount = 0;
661         long tempFlushedCellsSize = 0;
662         long tempCompactedCellsSize = 0;
663         long tempMajorCompactedCellsSize = 0;
664         long tempCellsCountCompactedToMob = 0;
665         long tempCellsCountCompactedFromMob = 0;
666         long tempCellsSizeCompactedToMob = 0;
667         long tempCellsSizeCompactedFromMob = 0;
668         long tempMobFlushCount = 0;
669         long tempMobFlushedCellsCount = 0;
670         long tempMobFlushedCellsSize = 0;
671         long tempMobScanCellsCount = 0;
672         long tempMobScanCellsSize = 0;
673         long tempBlockedRequestsCount = 0;
674         int regionCount = 0;
675         for (Region r : regionServer.getOnlineRegionsLocalContext()) {
676           tempNumMutationsWithoutWAL += r.getNumMutationsWithoutWAL();
677           tempDataInMemoryWithoutWAL += r.getDataInMemoryWithoutWAL();
678           tempReadRequestsCount += r.getReadRequestsCount();
679           tempFilteredReadRequestsCount += r.getFilteredReadRequestsCount();
680           tempWriteRequestsCount += r.getWriteRequestsCount();
681           tempCheckAndMutateChecksFailed += r.getCheckAndMutateChecksFailed();
682           tempCheckAndMutateChecksPassed += r.getCheckAndMutateChecksPassed();
683           tempBlockedRequestsCount += r.getBlockedRequestsCount();
684           List<Store> storeList = r.getStores();
685           tempNumStores += storeList.size();
686           for (Store store : storeList) {
687             tempNumStoreFiles += store.getStorefilesCount();
688             tempMemstoreSize += store.getMemStoreSize();
689             tempStoreFileSize += store.getStorefilesSize();
690
691             long storeMaxStoreFileAge = store.getMaxStoreFileAge();
692             tempMaxStoreFileAge = (storeMaxStoreFileAge > tempMaxStoreFileAge) ?
693               storeMaxStoreFileAge : tempMaxStoreFileAge;
694
695             long storeMinStoreFileAge = store.getMinStoreFileAge();
696             tempMinStoreFileAge = (storeMinStoreFileAge < tempMinStoreFileAge) ?
697               storeMinStoreFileAge : tempMinStoreFileAge;
698
699             long storeHFiles = store.getNumHFiles();
700             avgAgeNumerator += store.getAvgStoreFileAge() * storeHFiles;
701             numHFiles += storeHFiles;
702             tempNumReferenceFiles += store.getNumReferenceFiles();
703
704             tempStorefileIndexSize += store.getStorefilesIndexSize();
705             tempTotalStaticBloomSize += store.getTotalStaticBloomSize();
706             tempTotalStaticIndexSize += store.getTotalStaticIndexSize();
707             tempFlushedCellsCount += store.getFlushedCellsCount();
708             tempCompactedCellsCount += store.getCompactedCellsCount();
709             tempMajorCompactedCellsCount += store.getMajorCompactedCellsCount();
710             tempFlushedCellsSize += store.getFlushedCellsSize();
711             tempCompactedCellsSize += store.getCompactedCellsSize();
712             tempMajorCompactedCellsSize += store.getMajorCompactedCellsSize();
713             if (store instanceof HMobStore) {
714               HMobStore mobStore = (HMobStore) store;
715               tempCellsCountCompactedToMob += mobStore.getCellsCountCompactedToMob();
716               tempCellsCountCompactedFromMob += mobStore.getCellsCountCompactedFromMob();
717               tempCellsSizeCompactedToMob += mobStore.getCellsSizeCompactedToMob();
718               tempCellsSizeCompactedFromMob += mobStore.getCellsSizeCompactedFromMob();
719               tempMobFlushCount += mobStore.getMobFlushCount();
720               tempMobFlushedCellsCount += mobStore.getMobFlushedCellsCount();
721               tempMobFlushedCellsSize += mobStore.getMobFlushedCellsSize();
722               tempMobScanCellsCount += mobStore.getMobScanCellsCount();
723               tempMobScanCellsSize += mobStore.getMobScanCellsSize();
724             }
725           }
726
727           HDFSBlocksDistribution distro = r.getHDFSBlocksDistribution();
728           hdfsBlocksDistribution.add(distro);
729           if (r.getRegionInfo().getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID) {
730             hdfsBlocksDistributionSecondaryRegions.add(distro);
731           }
732           regionCount++;
733         }
734         float localityIndex = hdfsBlocksDistribution.getBlockLocalityIndex(
735             regionServer.getServerName().getHostname());
736         tempPercentFileLocal = Double.isNaN(tempBlockedRequestsCount) ? 0 : (localityIndex * 100);
737
738         float localityIndexSecondaryRegions = hdfsBlocksDistributionSecondaryRegions
739             .getBlockLocalityIndex(regionServer.getServerName().getHostname());
740         tempPercentFileLocalSecondaryRegions = Double.
741             isNaN(localityIndexSecondaryRegions) ? 0 : (localityIndexSecondaryRegions * 100);
742
743         // Compute the number of requests per second
744         long currentTime = EnvironmentEdgeManager.currentTime();
745
746         // assume that it took PERIOD seconds to start the executor.
747         // this is a guess but it's a pretty good one.
748         if (lastRan == 0) {
749           lastRan = currentTime - period;
750         }
751         // If we've time traveled keep the last requests per second.
752         if ((currentTime - lastRan) > 0) {
753           long currentRequestCount = getTotalRequestCount();
754           requestsPerSecond = (currentRequestCount - lastRequestCount) /
755               ((currentTime - lastRan) / 1000.0);
756           lastRequestCount = currentRequestCount;
757         }
758         lastRan = currentTime;
759
760         WALProvider provider = regionServer.walFactory.getWALProvider();
761         WALProvider metaProvider = regionServer.walFactory.getMetaWALProvider();
762         numWALFiles = (provider == null ? 0 : provider.getNumLogFiles()) +
763             (metaProvider == null ? 0 : metaProvider.getNumLogFiles());
764         walFileSize = (provider == null ? 0 : provider.getLogFileSize()) +
765             (provider == null ? 0 : provider.getLogFileSize());
766         // Copy over computed values so that no thread sees half computed values.
767         numStores = tempNumStores;
768         numStoreFiles = tempNumStoreFiles;
769         memstoreSize = tempMemstoreSize;
770         storeFileSize = tempStoreFileSize;
771         maxStoreFileAge = tempMaxStoreFileAge;
772         if (regionCount > 0) {
773           averageRegionSize = (memstoreSize + storeFileSize) / regionCount;
774         }
775         if (tempMinStoreFileAge != Long.MAX_VALUE) {
776           minStoreFileAge = tempMinStoreFileAge;
777         }
778
779         if (numHFiles != 0) {
780           avgStoreFileAge = avgAgeNumerator / numHFiles;
781         }
782
783         numReferenceFiles= tempNumReferenceFiles;
784         readRequestsCount = tempReadRequestsCount;
785         filteredReadRequestsCount = tempFilteredReadRequestsCount;
786         writeRequestsCount = tempWriteRequestsCount;
787         checkAndMutateChecksFailed = tempCheckAndMutateChecksFailed;
788         checkAndMutateChecksPassed = tempCheckAndMutateChecksPassed;
789         storefileIndexSize = tempStorefileIndexSize;
790         totalStaticIndexSize = tempTotalStaticIndexSize;
791         totalStaticBloomSize = tempTotalStaticBloomSize;
792         numMutationsWithoutWAL = tempNumMutationsWithoutWAL;
793         dataInMemoryWithoutWAL = tempDataInMemoryWithoutWAL;
794         percentFileLocal = tempPercentFileLocal;
795         percentFileLocalSecondaryRegions = tempPercentFileLocalSecondaryRegions;
796         flushedCellsCount = tempFlushedCellsCount;
797         compactedCellsCount = tempCompactedCellsCount;
798         majorCompactedCellsCount = tempMajorCompactedCellsCount;
799         flushedCellsSize = tempFlushedCellsSize;
800         compactedCellsSize = tempCompactedCellsSize;
801         majorCompactedCellsSize = tempMajorCompactedCellsSize;
802         cellsCountCompactedToMob = tempCellsCountCompactedToMob;
803         cellsCountCompactedFromMob = tempCellsCountCompactedFromMob;
804         cellsSizeCompactedToMob = tempCellsSizeCompactedToMob;
805         cellsSizeCompactedFromMob = tempCellsSizeCompactedFromMob;
806         mobFlushCount = tempMobFlushCount;
807         mobFlushedCellsCount = tempMobFlushedCellsCount;
808         mobFlushedCellsSize = tempMobFlushedCellsSize;
809         mobScanCellsCount = tempMobScanCellsCount;
810         mobScanCellsSize = tempMobScanCellsSize;
811         mobFileCacheAccessCount = mobFileCache.getAccessCount();
812         mobFileCacheMissCount = mobFileCache.getMissCount();
813         mobFileCacheHitRatio = Double.
814             isNaN(mobFileCache.getHitRatio())?0:mobFileCache.getHitRatio();
815         mobFileCacheEvictedCount = mobFileCache.getEvictedFileCount();
816         mobFileCacheCount = mobFileCache.getCacheSize();
817         blockedRequestsCount = tempBlockedRequestsCount;
818       } catch (Throwable e) {
819         LOG.warn("Caught exception! Will suppress and retry.", e);
820       }
821     }
822   }
823
824   @Override
825   public long getHedgedReadOps() {
826     return this.dfsHedgedReadMetrics == null? 0: this.dfsHedgedReadMetrics.getHedgedReadOps();
827   }
828
829   @Override
830   public long getHedgedReadWins() {
831     return this.dfsHedgedReadMetrics == null? 0: this.dfsHedgedReadMetrics.getHedgedReadWins();
832   }
833
834   @Override
835   public long getBlockedRequestsCount() {
836     return blockedRequestsCount;
837   }
838
839   @Override
840   public long getAverageRegionSize() {
841     return averageRegionSize;
842   }
843
844   public long getDataMissCount() {
845     if (this.cacheStats == null) {
846       return 0;
847     }
848     return cacheStats.getDataMissCount();
849   }
850
851   @Override
852   public long getLeafIndexMissCount() {
853     if (this.cacheStats == null) {
854       return 0;
855     }
856     return cacheStats.getLeafIndexMissCount();
857   }
858
859   @Override
860   public long getBloomChunkMissCount() {
861     if (this.cacheStats == null) {
862       return 0;
863     }
864     return cacheStats.getBloomChunkMissCount();
865   }
866
867   @Override
868   public long getMetaMissCount() {
869     if (this.cacheStats == null) {
870       return 0;
871     }
872     return cacheStats.getMetaMissCount();
873   }
874
875   @Override
876   public long getRootIndexMissCount() {
877     if (this.cacheStats == null) {
878       return 0;
879     }
880     return cacheStats.getRootIndexMissCount();
881   }
882
883   @Override
884   public long getIntermediateIndexMissCount() {
885     if (this.cacheStats == null) {
886       return 0;
887     }
888     return cacheStats.getIntermediateIndexMissCount();
889   }
890
891   @Override
892   public long getFileInfoMissCount() {
893     if (this.cacheStats == null) {
894       return 0;
895     }
896     return cacheStats.getFileInfoMissCount();
897   }
898
899   @Override
900   public long getGeneralBloomMetaMissCount() {
901     if (this.cacheStats == null) {
902       return 0;
903     }
904     return cacheStats.getGeneralBloomMetaMissCount();
905   }
906
907   @Override
908   public long getDeleteFamilyBloomMissCount() {
909     if (this.cacheStats == null) {
910       return 0;
911     }
912     return cacheStats.getDeleteFamilyBloomMissCount();
913   }
914
915   @Override
916   public long getTrailerMissCount() {
917     if (this.cacheStats == null) {
918       return 0;
919     }
920     return cacheStats.getTrailerMissCount();
921   }
922
923   @Override
924   public long getDataHitCount() {
925     if (this.cacheStats == null) {
926       return 0;
927     }
928     return cacheStats.getDataHitCount();
929   }
930
931   @Override
932   public long getLeafIndexHitCount() {
933     if (this.cacheStats == null) {
934       return 0;
935     }
936     return cacheStats.getLeafIndexHitCount();
937   }
938
939   @Override
940   public long getBloomChunkHitCount() {
941     if (this.cacheStats == null) {
942       return 0;
943     }
944     return cacheStats.getBloomChunkHitCount();
945   }
946
947   @Override
948   public long getMetaHitCount() {
949     if (this.cacheStats == null) {
950       return 0;
951     }
952     return cacheStats.getMetaHitCount();
953   }
954
955   @Override
956   public long getRootIndexHitCount() {
957     if (this.cacheStats == null) {
958       return 0;
959     }
960     return cacheStats.getRootIndexHitCount();
961   }
962
963   @Override
964   public long getIntermediateIndexHitCount() {
965     if (this.cacheStats == null) {
966       return 0;
967     }
968     return cacheStats.getIntermediateIndexHitCount();
969   }
970
971   @Override
972   public long getFileInfoHitCount() {
973     if (this.cacheStats == null) {
974       return 0;
975     }
976     return cacheStats.getFileInfoHitCount();
977   }
978
979   @Override
980   public long getGeneralBloomMetaHitCount() {
981     if (this.cacheStats == null) {
982       return 0;
983     }
984     return cacheStats.getGeneralBloomMetaHitCount();
985   }
986
987   @Override
988   public long getDeleteFamilyBloomHitCount() {
989     if (this.cacheStats == null) {
990       return 0;
991     }
992     return cacheStats.getDeleteFamilyBloomHitCount();
993   }
994
995   @Override
996   public long getTrailerHitCount() {
997     if (this.cacheStats == null) {
998       return 0;
999     }
1000     return cacheStats.getTrailerHitCount();
1001   }
1002 }