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