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.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.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    * @return the data locality of region in the regionserver.
165    */
166   public float getDataLocality() {
167     if (regionLoadPB.hasDataLocality()) {
168       return regionLoadPB.getDataLocality();
169     }
170     return 0.0f;
171   }
172   /**
173    * @see java.lang.Object#toString()
174    */
175   @Override
176   public String toString() {
177     StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
178         this.getStores());
179     sb = Strings.appendKeyValue(sb, "numberOfStorefiles",
180         this.getStorefiles());
181     sb = Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
182         this.getStoreUncompressedSizeMB());
183     sb = Strings.appendKeyValue(sb, "storefileSizeMB",
184         this.getStorefileSizeMB());
185     if (this.getStoreUncompressedSizeMB() != 0) {
186       sb = Strings.appendKeyValue(sb, "compressionRatio",
187           String.format("%.4f", (float) this.getStorefileSizeMB() /
188               (float) this.getStoreUncompressedSizeMB()));
189     }
190     sb = Strings.appendKeyValue(sb, "memstoreSizeMB",
191         this.getMemStoreSizeMB());
192     sb = Strings.appendKeyValue(sb, "storefileIndexSizeMB",
193         this.getStorefileIndexSizeMB());
194     sb = Strings.appendKeyValue(sb, "readRequestsCount",
195         this.getReadRequestsCount());
196     sb = Strings.appendKeyValue(sb, "writeRequestsCount",
197         this.getWriteRequestsCount());
198     sb = Strings.appendKeyValue(sb, "rootIndexSizeKB",
199         this.getRootIndexSizeKB());
200     sb = Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
201         this.getTotalStaticIndexSizeKB());
202     sb = Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
203         this.getTotalStaticBloomSizeKB());
204     sb = Strings.appendKeyValue(sb, "totalCompactingKVs",
205         this.getTotalCompactingKVs());
206     sb = Strings.appendKeyValue(sb, "currentCompactedKVs",
207         this.getCurrentCompactedKVs());
208     float compactionProgressPct = Float.NaN;
209     if (this.getTotalCompactingKVs() > 0) {
210       compactionProgressPct = ((float) this.getCurrentCompactedKVs() /
211           (float) this.getTotalCompactingKVs());
212     }
213     sb = Strings.appendKeyValue(sb, "compactionProgressPct",
214         compactionProgressPct);
215     sb = Strings.appendKeyValue(sb, "completeSequenceId",
216         this.getCompleteSequenceId());
217     sb = Strings.appendKeyValue(sb, "dataLocality",
218         this.getDataLocality());
219     return sb.toString();
220   }
221 }