1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.io.hfile;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.io.HeapSize;
22 import org.apache.hadoop.hbase.util.Bytes;
23 import org.apache.hadoop.hbase.util.ClassSize;
24
25
26
27
28 @InterfaceAudience.Private
29 public class BlockCacheKey implements HeapSize, java.io.Serializable {
30 private static final long serialVersionUID = -5199992013113130534L;
31 private final String hfileName;
32 private final long offset;
33
34
35
36
37
38
39 public BlockCacheKey(String hfileName, long offset) {
40 this.hfileName = hfileName;
41 this.offset = offset;
42 }
43
44 @Override
45 public int hashCode() {
46 return hfileName.hashCode() * 127 + (int) (offset ^ (offset >>> 32));
47 }
48
49 @Override
50 public boolean equals(Object o) {
51 if (o instanceof BlockCacheKey) {
52 BlockCacheKey k = (BlockCacheKey) o;
53 return offset == k.offset
54 && (hfileName == null ? k.hfileName == null : hfileName
55 .equals(k.hfileName));
56 } else {
57 return false;
58 }
59 }
60
61 @Override
62 public String toString() {
63 return String.format("%s_%d", hfileName, offset);
64 }
65
66 public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT +
67 ClassSize.REFERENCE +
68 Bytes.SIZEOF_LONG);
69
70
71
72
73
74 @Override
75 public long heapSize() {
76 return ClassSize.align(FIXED_OVERHEAD + ClassSize.STRING +
77 2 * hfileName.length());
78 }
79
80
81
82
83
84 public String getHfileName() {
85 return hfileName;
86 }
87
88 public long getOffset() {
89 return offset;
90 }
91 }