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