1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.io.hfile;
20
21 import java.io.DataInput;
22 import java.io.DataOutput;
23 import java.io.IOException;
24
25 import org.apache.hadoop.classification.InterfaceAudience;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.io.Writable;
28
29
30
31
32
33
34
35
36
37 @InterfaceAudience.Private
38 public class BlockCacheColumnFamilySummary implements Writable, Comparable<BlockCacheColumnFamilySummary> {
39
40 private String table = "";
41 private String columnFamily = "";
42 private int blocks;
43 private long heapSize;
44
45
46
47
48 public BlockCacheColumnFamilySummary() {
49
50 }
51
52
53
54
55
56
57 public BlockCacheColumnFamilySummary(String table, String columnFamily) {
58 this.table = table;
59 this.columnFamily = columnFamily;
60 }
61
62
63
64
65
66 public String getTable() {
67 return table;
68 }
69
70
71
72
73 public void setTable(String table) {
74 this.table = table;
75 }
76
77
78
79
80 public String getColumnFamily() {
81 return columnFamily;
82 }
83
84
85
86
87 public void setColumnFamily(String columnFamily) {
88 this.columnFamily = columnFamily;
89 }
90
91
92
93
94
95 public int getBlocks() {
96 return blocks;
97 }
98
99
100
101
102 public void setBlocks(int blocks) {
103 this.blocks = blocks;
104 }
105
106
107
108
109
110 public long getHeapSize() {
111 return heapSize;
112 }
113
114
115
116
117 public void incrementBlocks() {
118 this.blocks++;
119 }
120
121
122
123
124
125 public void incrementHeapSize(long heapSize) {
126 this.heapSize = this.heapSize + heapSize;
127 }
128
129
130
131
132
133 public void setHeapSize(long heapSize) {
134 this.heapSize = heapSize;
135 }
136
137 @Override
138 public void readFields(DataInput in) throws IOException {
139 table = in.readUTF();
140 columnFamily = in.readUTF();
141 blocks = in.readInt();
142 heapSize = in.readLong();
143 }
144
145 @Override
146 public void write(DataOutput out) throws IOException {
147 out.writeUTF(table);
148 out.writeUTF(columnFamily);
149 out.writeInt(blocks);
150 out.writeLong(heapSize);
151 }
152
153 @Override
154 public int hashCode() {
155 final int prime = 31;
156 int result = 1;
157 result = prime * result
158 + ((columnFamily == null) ? 0 : columnFamily.hashCode());
159 result = prime * result + ((table == null) ? 0 : table.hashCode());
160 return result;
161 }
162 @Override
163 public boolean equals(Object obj) {
164 if (this == obj)
165 return true;
166 if (obj == null)
167 return false;
168 if (getClass() != obj.getClass())
169 return false;
170 BlockCacheColumnFamilySummary other = (BlockCacheColumnFamilySummary) obj;
171 if (columnFamily == null) {
172 if (other.columnFamily != null)
173 return false;
174 } else if (!columnFamily.equals(other.columnFamily))
175 return false;
176 if (table == null) {
177 if (other.table != null)
178 return false;
179 } else if (!table.equals(other.table))
180 return false;
181 return true;
182 }
183
184
185
186 @Override
187 public String toString() {
188 return "BlockCacheSummaryEntry [table=" + table + ", columnFamily="
189 + columnFamily + ", blocks=" + blocks + ", heapSize=" + heapSize + "]";
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 public static BlockCacheColumnFamilySummary createFromStoreFilePath(Path path) {
209
210
211
212
213 String sp = path.toString();
214 String s[] = sp.split("\\/");
215
216 BlockCacheColumnFamilySummary bcse = null;
217 if (s.length >= 4) {
218
219 String table = s[s.length - 4];
220 String cf = s[s.length - 2];
221 bcse = new BlockCacheColumnFamilySummary(table, cf);
222 }
223 return bcse;
224 }
225
226 @Override
227 public int compareTo(BlockCacheColumnFamilySummary o) {
228 int i = table.compareTo(o.getTable());
229 if (i != 0) {
230 return i;
231 }
232 return columnFamily.compareTo(o.getColumnFamily());
233 }
234
235
236
237
238
239
240
241 public static BlockCacheColumnFamilySummary create(BlockCacheColumnFamilySummary e) {
242 BlockCacheColumnFamilySummary e2 = new BlockCacheColumnFamilySummary();
243 e2.setTable(e.getTable());
244 e2.setColumnFamily(e.getColumnFamily());
245 return e2;
246 }
247 }