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 java.util.List;
24  
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.classification.InterfaceStability;
27  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
28  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.StoreSequenceId;
29  import org.apache.hadoop.hbase.util.Bytes;
30  import org.apache.hadoop.hbase.util.Strings;
31  
32  /**
33    * Encapsulates per-region load metrics.
34    */
35  @InterfaceAudience.Public
36  @InterfaceStability.Evolving
37  public class RegionLoad {
38  
39    protected ClusterStatusProtos.RegionLoad regionLoadPB;
40  
41    public RegionLoad(ClusterStatusProtos.RegionLoad regionLoadPB) {
42      this.regionLoadPB = regionLoadPB;
43    }
44  
45    /**
46     * @return the region name
47     */
48    public byte[] getName() {
49      return regionLoadPB.getRegionSpecifier().getValue().toByteArray();
50    }
51  
52    /**
53     * @return the region name as a string
54     */
55    public String getNameAsString() {
56      return Bytes.toStringBinary(getName());
57    }
58  
59    /**
60     * @return the number of stores
61     */
62    public int getStores() {
63      return regionLoadPB.getStores();
64    }
65  
66    /**
67     * @return the number of storefiles
68     */
69    public int getStorefiles() {
70      return regionLoadPB.getStorefiles();
71    }
72  
73    /**
74     * @return the total size of the storefiles, in MB
75     */
76    public int getStorefileSizeMB() {
77      return regionLoadPB.getStorefileSizeMB();
78    }
79  
80    /**
81     * @return the memstore size, in MB
82     */
83    public int getMemStoreSizeMB() {
84      return regionLoadPB.getMemstoreSizeMB();
85    }
86  
87    /**
88     * @return the approximate size of storefile indexes on the heap, in MB
89     */
90    public int getStorefileIndexSizeMB() {
91      return regionLoadPB.getStorefileIndexSizeMB();
92    }
93  
94    /**
95     * @return the number of requests made to region
96     */
97    public long getRequestsCount() {
98      return getReadRequestsCount() + getWriteRequestsCount();
99    }
100 
101   /**
102    * @return the number of read requests made to region
103    */
104   public long getReadRequestsCount() {
105     return regionLoadPB.getReadRequestsCount();
106   }
107 
108   /**
109    * @return the number of write requests made to region
110    */
111   public long getWriteRequestsCount() {
112     return regionLoadPB.getWriteRequestsCount();
113   }
114 
115   /**
116    * @return The current total size of root-level indexes for the region, in KB.
117    */
118   public int getRootIndexSizeKB() {
119     return regionLoadPB.getRootIndexSizeKB();
120   }
121 
122   /**
123    * @return The total size of all index blocks, not just the root level, in KB.
124    */
125   public int getTotalStaticIndexSizeKB() {
126     return regionLoadPB.getTotalStaticIndexSizeKB();
127   }
128 
129   /**
130    * @return The total size of all Bloom filter blocks, not just loaded into the
131    * block cache, in KB.
132    */
133   public int getTotalStaticBloomSizeKB() {
134     return regionLoadPB.getTotalStaticBloomSizeKB();
135   }
136 
137   /**
138    * @return the total number of kvs in current compaction
139    */
140   public long getTotalCompactingKVs() {
141     return regionLoadPB.getTotalCompactingKVs();
142   }
143 
144   /**
145    * @return the number of already compacted kvs in current compaction
146    */
147   public long getCurrentCompactedKVs() {
148     return regionLoadPB.getCurrentCompactedKVs();
149   }
150 
151   /**
152    * This does not really belong inside RegionLoad but its being done in the name of expediency.
153    * @return the completed sequence Id for the region
154    */
155   public long getCompleteSequenceId() {
156     return regionLoadPB.getCompleteSequenceId();
157   }
158 
159   /**
160    * @return completed sequence id per store.
161    */
162   public List<StoreSequenceId> getStoreCompleteSequenceId() {
163     return regionLoadPB.getStoreCompleteSequenceIdList();
164   }
165 
166   /**
167    * @return the uncompressed size of the storefiles in MB.
168    */
169   public int getStoreUncompressedSizeMB() {
170     return regionLoadPB.getStoreUncompressedSizeMB();
171   }
172 
173   /**
174    * @return the data locality of region in the regionserver.
175    */
176   public float getDataLocality() {
177     if (regionLoadPB.hasDataLocality()) {
178       return regionLoadPB.getDataLocality();
179     }
180     return 0.0f;
181   }
182 
183   /**
184    * @return the timestamp of the oldest hfile for any store of this region.
185    */
186   public long getLastMajorCompactionTs() {
187     return regionLoadPB.getLastMajorCompactionTs();
188   }
189 
190   /**
191    * @see java.lang.Object#toString()
192    */
193   @Override
194   public String toString() {
195     StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
196         this.getStores());
197     sb = Strings.appendKeyValue(sb, "numberOfStorefiles",
198         this.getStorefiles());
199     sb = Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
200       this.getStoreUncompressedSizeMB());
201     sb = Strings.appendKeyValue(sb, "lastMajorCompactionTimestamp",
202       this.getLastMajorCompactionTs());
203     sb = Strings.appendKeyValue(sb, "storefileSizeMB",
204         this.getStorefileSizeMB());
205     if (this.getStoreUncompressedSizeMB() != 0) {
206       sb = Strings.appendKeyValue(sb, "compressionRatio",
207           String.format("%.4f", (float) this.getStorefileSizeMB() /
208               (float) this.getStoreUncompressedSizeMB()));
209     }
210     sb = Strings.appendKeyValue(sb, "memstoreSizeMB",
211         this.getMemStoreSizeMB());
212     sb = Strings.appendKeyValue(sb, "storefileIndexSizeMB",
213         this.getStorefileIndexSizeMB());
214     sb = Strings.appendKeyValue(sb, "readRequestsCount",
215         this.getReadRequestsCount());
216     sb = Strings.appendKeyValue(sb, "writeRequestsCount",
217         this.getWriteRequestsCount());
218     sb = Strings.appendKeyValue(sb, "rootIndexSizeKB",
219         this.getRootIndexSizeKB());
220     sb = Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
221         this.getTotalStaticIndexSizeKB());
222     sb = Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
223         this.getTotalStaticBloomSizeKB());
224     sb = Strings.appendKeyValue(sb, "totalCompactingKVs",
225         this.getTotalCompactingKVs());
226     sb = Strings.appendKeyValue(sb, "currentCompactedKVs",
227         this.getCurrentCompactedKVs());
228     float compactionProgressPct = Float.NaN;
229     if (this.getTotalCompactingKVs() > 0) {
230       compactionProgressPct = ((float) this.getCurrentCompactedKVs() /
231           (float) this.getTotalCompactingKVs());
232     }
233     sb = Strings.appendKeyValue(sb, "compactionProgressPct",
234         compactionProgressPct);
235     sb = Strings.appendKeyValue(sb, "completeSequenceId",
236         this.getCompleteSequenceId());
237     sb = Strings.appendKeyValue(sb, "dataLocality",
238         this.getDataLocality());
239     return sb.toString();
240   }
241 }