001/** 002 * Copyright The Apache Software Foundation 003 * 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package org.apache.hadoop.hbase; 022 023import java.util.List; 024import java.util.Map; 025import java.util.stream.Collectors; 026import org.apache.hadoop.hbase.client.CompactionState; 027import org.apache.hadoop.hbase.util.Strings; 028import org.apache.yetus.audience.InterfaceAudience; 029 030import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations; 031import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos; 032 033/** 034 * Encapsulates per-region load metrics. 035 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 036 * Use {@link RegionMetrics} instead. 037 */ 038@InterfaceAudience.Public 039@Deprecated 040public class RegionLoad implements RegionMetrics { 041 // DONT use this pb object since the byte array backed may be modified in rpc layer 042 // we keep this pb object for BC. 043 protected ClusterStatusProtos.RegionLoad regionLoadPB; 044 private final RegionMetrics metrics; 045 046 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 047 public RegionLoad(ClusterStatusProtos.RegionLoad regionLoadPB) { 048 this.regionLoadPB = regionLoadPB; 049 this.metrics = RegionMetricsBuilder.toRegionMetrics(regionLoadPB); 050 } 051 052 RegionLoad(RegionMetrics metrics) { 053 this.metrics = metrics; 054 this.regionLoadPB = RegionMetricsBuilder.toRegionLoad(metrics); 055 } 056 057 /** 058 * @return the region name 059 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 060 * Use {@link #getRegionName} instead. 061 */ 062 @Deprecated 063 public byte[] getName() { 064 return metrics.getRegionName(); 065 } 066 067 @Override 068 public byte[] getRegionName() { 069 return metrics.getRegionName(); 070 } 071 072 @Override 073 public int getStoreCount() { 074 return metrics.getStoreCount(); 075 } 076 077 @Override 078 public int getStoreFileCount() { 079 return metrics.getStoreFileCount(); 080 } 081 082 @Override 083 public Size getStoreFileSize() { 084 return metrics.getStoreFileSize(); 085 } 086 087 @Override 088 public Size getMemStoreSize() { 089 return metrics.getMemStoreSize(); 090 } 091 092 @Override 093 public long getReadRequestCount() { 094 return metrics.getReadRequestCount(); 095 } 096 097 @Override 098 public long getFilteredReadRequestCount() { 099 return metrics.getFilteredReadRequestCount(); 100 } 101 102 @Override 103 public Size getStoreFileIndexSize() { 104 return metrics.getStoreFileIndexSize(); 105 } 106 107 @Override 108 public long getWriteRequestCount() { 109 return metrics.getWriteRequestCount(); 110 } 111 112 @Override 113 public Size getStoreFileRootLevelIndexSize() { 114 return metrics.getStoreFileRootLevelIndexSize(); 115 } 116 117 @Override 118 public Size getStoreFileUncompressedDataIndexSize() { 119 return metrics.getStoreFileUncompressedDataIndexSize(); 120 } 121 122 @Override 123 public Size getBloomFilterSize() { 124 return metrics.getBloomFilterSize(); 125 } 126 127 @Override 128 public long getCompactingCellCount() { 129 return metrics.getCompactingCellCount(); 130 } 131 132 @Override 133 public long getCompactedCellCount() { 134 return metrics.getCompactedCellCount(); 135 } 136 137 @Override 138 public long getCompletedSequenceId() { 139 return metrics.getCompletedSequenceId(); 140 } 141 142 @Override 143 public Map<byte[], Long> getStoreSequenceId() { 144 return metrics.getStoreSequenceId(); 145 } 146 147 @Override 148 public Size getUncompressedStoreFileSize() { 149 return metrics.getUncompressedStoreFileSize(); 150 } 151 152 /** 153 * @return the number of stores 154 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 155 * Use {@link #getStoreCount} instead. 156 */ 157 @Deprecated 158 public int getStores() { 159 return metrics.getStoreCount(); 160 } 161 162 /** 163 * @return the number of storefiles 164 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 165 * Use {@link #getStoreFileCount} instead. 166 */ 167 @Deprecated 168 public int getStorefiles() { 169 return metrics.getStoreFileCount(); 170 } 171 172 /** 173 * @return the total size of the storefiles, in MB 174 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 175 * Use {@link #getStoreFileSize} instead. 176 */ 177 @Deprecated 178 public int getStorefileSizeMB() { 179 return (int) metrics.getStoreFileSize().get(Size.Unit.MEGABYTE); 180 } 181 182 /** 183 * @return the memstore size, in MB 184 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 185 * Use {@link #getMemStoreSize} instead. 186 */ 187 @Deprecated 188 public int getMemStoreSizeMB() { 189 return (int) metrics.getMemStoreSize().get(Size.Unit.MEGABYTE); 190 } 191 192 /** 193 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 194 * ((<a href="https://issues.apache.org/jira/browse/HBASE-3935">HBASE-3935</a>)). 195 * Use {@link #getStoreFileRootLevelIndexSize} instead. 196 */ 197 @Deprecated 198 public int getStorefileIndexSizeMB() { 199 // Return value divided by 1024 200 return (getRootIndexSizeKB() >> 10); 201 } 202 203 /** 204 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 205 * Use {@link #getStoreFileRootLevelIndexSize()} instead. 206 */ 207 @Deprecated 208 public int getStorefileIndexSizeKB() { 209 return getRootIndexSizeKB(); 210 } 211 212 /** 213 * @return the number of requests made to region 214 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 215 * Use {@link #getRequestCount()} instead. 216 */ 217 @Deprecated 218 public long getRequestsCount() { 219 return metrics.getRequestCount(); 220 } 221 222 /** 223 * @return the number of read requests made to region 224 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 225 * Use {@link #getReadRequestCount} instead. 226 */ 227 @Deprecated 228 public long getReadRequestsCount() { 229 return metrics.getReadRequestCount(); 230 } 231 232 /** 233 * @return the number of filtered read requests made to region 234 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 235 * Use {@link #getFilteredReadRequestCount} instead. 236 */ 237 @Deprecated 238 public long getFilteredReadRequestsCount() { 239 return metrics.getFilteredReadRequestCount(); 240 } 241 242 /** 243 * @return the number of write requests made to region 244 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 245 * Use {@link #getWriteRequestCount} instead. 246 */ 247 @Deprecated 248 public long getWriteRequestsCount() { 249 return metrics.getWriteRequestCount(); 250 } 251 252 /** 253 * @return The current total size of root-level indexes for the region, in KB. 254 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 255 * Use {@link #getStoreFileRootLevelIndexSize} instead. 256 */ 257 @Deprecated 258 public int getRootIndexSizeKB() { 259 return (int) metrics.getStoreFileRootLevelIndexSize().get(Size.Unit.KILOBYTE); 260 } 261 262 /** 263 * @return The total size of all index blocks, not just the root level, in KB. 264 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 265 * Use {@link #getStoreFileUncompressedDataIndexSize} instead. 266 */ 267 @Deprecated 268 public int getTotalStaticIndexSizeKB() { 269 return (int) metrics.getStoreFileUncompressedDataIndexSize().get(Size.Unit.KILOBYTE); 270 } 271 272 /** 273 * @return The total size of all Bloom filter blocks, not just loaded into the 274 * block cache, in KB. 275 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 276 * Use {@link #getBloomFilterSize} instead. 277 */ 278 @Deprecated 279 public int getTotalStaticBloomSizeKB() { 280 return (int) metrics.getBloomFilterSize().get(Size.Unit.KILOBYTE); 281 } 282 283 /** 284 * @return the total number of kvs in current compaction 285 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 286 * Use {@link #getCompactingCellCount} instead. 287 */ 288 @Deprecated 289 public long getTotalCompactingKVs() { 290 return metrics.getCompactingCellCount(); 291 } 292 293 /** 294 * @return the number of already compacted kvs in current compaction 295 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 296 * Use {@link #getCompactedCellCount} instead. 297 */ 298 @Deprecated 299 public long getCurrentCompactedKVs() { 300 return metrics.getCompactedCellCount(); 301 } 302 303 /** 304 * This does not really belong inside RegionLoad but its being done in the name of expediency. 305 * @return the completed sequence Id for the region 306 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 307 * Use {@link #getCompletedSequenceId} instead. 308 */ 309 @Deprecated 310 public long getCompleteSequenceId() { 311 return metrics.getCompletedSequenceId(); 312 } 313 314 /** 315 * @return completed sequence id per store. 316 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 317 * Use {@link #getStoreSequenceId} instead. 318 */ 319 @Deprecated 320 public List<ClusterStatusProtos.StoreSequenceId> getStoreCompleteSequenceId() { 321 return metrics.getStoreSequenceId().entrySet().stream() 322 .map(s -> ClusterStatusProtos.StoreSequenceId.newBuilder() 323 .setFamilyName(UnsafeByteOperations.unsafeWrap(s.getKey())) 324 .setSequenceId(s.getValue()) 325 .build()) 326 .collect(Collectors.toList()); 327 } 328 329 /** 330 * @return the uncompressed size of the storefiles in MB. 331 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 332 * Use {@link #getUncompressedStoreFileSize} instead. 333 */ 334 @Deprecated 335 public int getStoreUncompressedSizeMB() { 336 return (int) metrics.getUncompressedStoreFileSize().get(Size.Unit.KILOBYTE); 337 } 338 339 /** 340 * @return the data locality of region in the regionserver. 341 */ 342 @Override 343 public float getDataLocality() { 344 return metrics.getDataLocality(); 345 } 346 347 @Override 348 public long getLastMajorCompactionTimestamp() { 349 return metrics.getLastMajorCompactionTimestamp(); 350 } 351 352 /** 353 * @return the timestamp of the oldest hfile for any store of this region. 354 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 355 * Use {@link #getLastMajorCompactionTimestamp} instead. 356 */ 357 @Deprecated 358 public long getLastMajorCompactionTs() { 359 return metrics.getLastMajorCompactionTimestamp(); 360 } 361 362 /** 363 * @return the reference count for the stores of this region 364 */ 365 public int getStoreRefCount() { 366 return metrics.getStoreRefCount(); 367 } 368 369 @Override 370 public int getMaxCompactedStoreFileRefCount() { 371 return metrics.getMaxCompactedStoreFileRefCount(); 372 } 373 374 @Override 375 public float getDataLocalityForSsd() { 376 return metrics.getDataLocalityForSsd(); 377 } 378 379 @Override 380 public long getBlocksLocalWeight() { 381 return metrics.getBlocksLocalWeight(); 382 } 383 384 @Override 385 public long getBlocksLocalWithSsdWeight() { 386 return metrics.getBlocksLocalWithSsdWeight(); 387 } 388 389 @Override 390 public long getBlocksTotalWeight() { 391 return metrics.getBlocksTotalWeight(); 392 } 393 394 @Override 395 public CompactionState getCompactionState() { 396 return metrics.getCompactionState(); 397 } 398 399 /** 400 * @see java.lang.Object#toString() 401 */ 402 @Override 403 public String toString() { 404 StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores", 405 this.getStores()); 406 Strings.appendKeyValue(sb, "numberOfStorefiles", this.getStorefiles()); 407 Strings.appendKeyValue(sb, "storeRefCount", this.getStoreRefCount()); 408 Strings.appendKeyValue(sb, "storefileUncompressedSizeMB", 409 this.getStoreUncompressedSizeMB()); 410 Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp", 411 this.getLastMajorCompactionTs()); 412 Strings.appendKeyValue(sb, "storefileSizeMB", this.getStorefileSizeMB()); 413 if (this.getStoreUncompressedSizeMB() != 0) { 414 Strings.appendKeyValue(sb, "compressionRatio", 415 String.format("%.4f", (float) this.getStorefileSizeMB() / 416 (float) this.getStoreUncompressedSizeMB())); 417 } 418 Strings.appendKeyValue(sb, "memstoreSizeMB", 419 this.getMemStoreSizeMB()); 420 Strings.appendKeyValue(sb, "readRequestsCount", 421 this.getReadRequestsCount()); 422 Strings.appendKeyValue(sb, "writeRequestsCount", 423 this.getWriteRequestsCount()); 424 Strings.appendKeyValue(sb, "rootIndexSizeKB", 425 this.getRootIndexSizeKB()); 426 Strings.appendKeyValue(sb, "totalStaticIndexSizeKB", 427 this.getTotalStaticIndexSizeKB()); 428 Strings.appendKeyValue(sb, "totalStaticBloomSizeKB", 429 this.getTotalStaticBloomSizeKB()); 430 Strings.appendKeyValue(sb, "totalCompactingKVs", 431 this.getTotalCompactingKVs()); 432 Strings.appendKeyValue(sb, "currentCompactedKVs", 433 this.getCurrentCompactedKVs()); 434 float compactionProgressPct = Float.NaN; 435 if (this.getTotalCompactingKVs() > 0) { 436 compactionProgressPct = ((float) this.getCurrentCompactedKVs() / 437 (float) this.getTotalCompactingKVs()); 438 } 439 Strings.appendKeyValue(sb, "compactionProgressPct", 440 compactionProgressPct); 441 Strings.appendKeyValue(sb, "completeSequenceId", 442 this.getCompleteSequenceId()); 443 Strings.appendKeyValue(sb, "dataLocality", 444 this.getDataLocality()); 445 return sb.toString(); 446 } 447}