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