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