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