View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase;
22  
23  import org.apache.hadoop.classification.InterfaceAudience;
24  import org.apache.hadoop.classification.InterfaceStability;
25  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
26  import org.apache.hadoop.hbase.util.Bytes;
27  import org.apache.hadoop.hbase.util.Strings;
28  
29  /**
30    * Encapsulates per-region load metrics.
31    */
32  @InterfaceAudience.Public
33  @InterfaceStability.Evolving
34  public class RegionLoad {
35  
36    protected ClusterStatusProtos.RegionLoad regionLoadPB;
37  
38    public RegionLoad(ClusterStatusProtos.RegionLoad regionLoadPB) {
39      this.regionLoadPB = regionLoadPB;
40    }
41  
42    /**
43     * @return the region name
44     */
45    public byte[] getName() {
46      return regionLoadPB.getRegionSpecifier().getValue().toByteArray();
47    }
48  
49    /**
50     * @return the region name as a string
51     */
52    public String getNameAsString() {
53      return Bytes.toString(getName());
54    }
55  
56    /**
57     * @return the number of stores
58     */
59    public int getStores() {
60      return regionLoadPB.getStores();
61    }
62  
63    /**
64     * @return the number of storefiles
65     */
66    public int getStorefiles() {
67      return regionLoadPB.getStorefiles();
68    }
69  
70    /**
71     * @return the total size of the storefiles, in MB
72     */
73    public int getStorefileSizeMB() {
74      return regionLoadPB.getStorefileSizeMB();
75    }
76  
77    /**
78     * @return the memstore size, in MB
79     */
80    public int getMemStoreSizeMB() {
81      return regionLoadPB.getMemstoreSizeMB();
82    }
83  
84    /**
85     * @return the approximate size of storefile indexes on the heap, in MB
86     */
87    public int getStorefileIndexSizeMB() {
88      return regionLoadPB.getStorefileIndexSizeMB();
89    }
90  
91    /**
92     * @return the number of requests made to region
93     */
94    public long getRequestsCount() {
95      return getReadRequestsCount() + getWriteRequestsCount();
96    }
97  
98    /**
99     * @return the number of read requests made to region
100    */
101   public long getReadRequestsCount() {
102     return regionLoadPB.getReadRequestsCount();
103   }
104 
105   /**
106    * @return the number of write requests made to region
107    */
108   public long getWriteRequestsCount() {
109     return regionLoadPB.getWriteRequestsCount();
110   }
111 
112   /**
113    * @return The current total size of root-level indexes for the region, in KB.
114    */
115   public int getRootIndexSizeKB() {
116     return regionLoadPB.getRootIndexSizeKB();
117   }
118 
119   /**
120    * @return The total size of all index blocks, not just the root level, in KB.
121    */
122   public int getTotalStaticIndexSizeKB() {
123     return regionLoadPB.getTotalStaticIndexSizeKB();
124   }
125 
126   /**
127    * @return The total size of all Bloom filter blocks, not just loaded into the
128    * block cache, in KB.
129    */
130   public int getTotalStaticBloomSizeKB() {
131     return regionLoadPB.getTotalStaticBloomSizeKB();
132   }
133 
134   /**
135    * @return the total number of kvs in current compaction
136    */
137   public long getTotalCompactingKVs() {
138     return regionLoadPB.getTotalCompactingKVs();
139   }
140 
141   /**
142    * @return the number of already compacted kvs in current compaction
143    */
144   public long getCurrentCompactedKVs() {
145     return regionLoadPB.getCurrentCompactedKVs();
146   }
147 
148   /**
149    * This does not really belong inside RegionLoad but its being done in the name of expediency.
150    * @return the completed sequence Id for the region
151    */
152   public long getCompleteSequenceId() {
153     return regionLoadPB.getCompleteSequenceId();
154   }
155 
156   /**
157    * @return the uncompressed size of the storefiles in MB.
158    */
159   public int getStoreUncompressedSizeMB() {
160     return regionLoadPB.getStoreUncompressedSizeMB();
161   }
162 
163   /**
164    * @see java.lang.Object#toString()
165    */
166   @Override
167   public String toString() {
168     StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
169         this.getStores());
170     sb = Strings.appendKeyValue(sb, "numberOfStorefiles",
171         this.getStorefiles());
172     sb = Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
173         this.getStoreUncompressedSizeMB());
174     sb = Strings.appendKeyValue(sb, "storefileSizeMB",
175         this.getStorefileSizeMB());
176     if (this.getStoreUncompressedSizeMB() != 0) {
177       sb = Strings.appendKeyValue(sb, "compressionRatio",
178           String.format("%.4f", (float) this.getStorefileSizeMB() /
179               (float) this.getStoreUncompressedSizeMB()));
180     }
181     sb = Strings.appendKeyValue(sb, "memstoreSizeMB",
182         this.getMemStoreSizeMB());
183     sb = Strings.appendKeyValue(sb, "storefileIndexSizeMB",
184         this.getStorefileIndexSizeMB());
185     sb = Strings.appendKeyValue(sb, "readRequestsCount",
186         this.getReadRequestsCount());
187     sb = Strings.appendKeyValue(sb, "writeRequestsCount",
188         this.getWriteRequestsCount());
189     sb = Strings.appendKeyValue(sb, "rootIndexSizeKB",
190         this.getRootIndexSizeKB());
191     sb = Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
192         this.getTotalStaticIndexSizeKB());
193     sb = Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
194         this.getTotalStaticBloomSizeKB());
195     sb = Strings.appendKeyValue(sb, "totalCompactingKVs",
196         this.getTotalCompactingKVs());
197     sb = Strings.appendKeyValue(sb, "currentCompactedKVs",
198         this.getCurrentCompactedKVs());
199     float compactionProgressPct = Float.NaN;
200     if (this.getTotalCompactingKVs() > 0) {
201       compactionProgressPct = ((float) this.getCurrentCompactedKVs() /
202           (float) this.getTotalCompactingKVs());
203     }
204     sb = Strings.appendKeyValue(sb, "compactionProgressPct",
205         compactionProgressPct);
206     return sb.toString();
207   }
208 }