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 private final boolean isPrimaryReplicaBlock;
34
35
36
37
38
39
40 public BlockCacheKey(String hfileName, long offset) {
41 this(hfileName, offset, true);
42 }
43
44 public BlockCacheKey(String hfileName, long offset, boolean isPrimaryReplica) {
45 this.isPrimaryReplicaBlock = isPrimaryReplica;
46 this.hfileName = hfileName;
47 this.offset = offset;
48 }
49
50 @Override
51 public int hashCode() {
52 return hfileName.hashCode() * 127 + (int) (offset ^ (offset >>> 32));
53 }
54
55 @Override
56 public boolean equals(Object o) {
57 if (o instanceof BlockCacheKey) {
58 BlockCacheKey k = (BlockCacheKey) o;
59 return offset == k.offset
60 && (hfileName == null ? k.hfileName == null : hfileName
61 .equals(k.hfileName));
62 } else {
63 return false;
64 }
65 }
66
67 @Override
68 public String toString() {
69 return this.hfileName + '_' + this.offset;
70 }
71
72 public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT +Bytes.SIZEOF_BOOLEAN +
73 ClassSize.REFERENCE +
74 Bytes.SIZEOF_LONG);
75
76
77
78
79
80 @Override
81 public long heapSize() {
82 return ClassSize.align(FIXED_OVERHEAD + ClassSize.STRING +
83 2 * hfileName.length());
84 }
85
86
87
88
89
90 public String getHfileName() {
91 return hfileName;
92 }
93
94 public boolean isPrimary() {
95 return isPrimaryReplicaBlock;
96 }
97
98 public long getOffset() {
99 return offset;
100 }
101 }