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