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.regionserver;
21
22 import java.io.DataInput;
23 import java.io.DataOutput;
24 import java.io.IOException;
25
26 import org.apache.hadoop.hbase.KeyValue;
27 import org.apache.hadoop.hbase.KeyValue.Type;
28 import org.apache.hadoop.hbase.io.TimeRange;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.apache.hadoop.io.Writable;
31
32
33
34
35
36
37
38
39 public class TimeRangeTracker implements Writable {
40
41 long minimumTimestamp = -1;
42 long maximumTimestamp = -1;
43
44
45
46
47
48 public TimeRangeTracker() {
49
50 }
51
52
53
54
55
56 public TimeRangeTracker(final TimeRangeTracker trt) {
57 this.minimumTimestamp = trt.getMinimumTimestamp();
58 this.maximumTimestamp = trt.getMaximumTimestamp();
59 }
60
61 public TimeRangeTracker(long minimumTimestamp, long maximumTimestamp) {
62 this.minimumTimestamp = minimumTimestamp;
63 this.maximumTimestamp = maximumTimestamp;
64 }
65
66
67
68
69
70
71
72 public void includeTimestamp(final KeyValue kv) {
73 includeTimestamp(kv.getTimestamp());
74 if (kv.isDeleteColumnOrFamily()) {
75 includeTimestamp(0);
76 }
77 }
78
79
80
81
82
83
84
85 public void includeTimestamp(final byte[] key) {
86 includeTimestamp(Bytes.toLong(key,key.length-KeyValue.TIMESTAMP_TYPE_SIZE));
87 int type = key[key.length - 1];
88 if (type == Type.DeleteColumn.getCode() ||
89 type == Type.DeleteFamily.getCode()) {
90 includeTimestamp(0);
91 }
92 }
93
94
95
96
97
98 private void includeTimestamp(final long timestamp) {
99 if (maximumTimestamp == -1) {
100 minimumTimestamp = timestamp;
101 maximumTimestamp = timestamp;
102 }
103 else if (minimumTimestamp > timestamp) {
104 minimumTimestamp = timestamp;
105 }
106 else if (maximumTimestamp < timestamp) {
107 maximumTimestamp = timestamp;
108 }
109 return;
110 }
111
112
113
114
115
116
117 public boolean includesTimeRange(final TimeRange tr) {
118 return (this.minimumTimestamp < tr.getMax() &&
119 this.maximumTimestamp >= tr.getMin());
120 }
121
122
123
124
125 public long getMinimumTimestamp() {
126 return minimumTimestamp;
127 }
128
129
130
131
132 public long getMaximumTimestamp() {
133 return maximumTimestamp;
134 }
135
136 public void write(final DataOutput out) throws IOException {
137 out.writeLong(minimumTimestamp);
138 out.writeLong(maximumTimestamp);
139 }
140
141 public void readFields(final DataInput in) throws IOException {
142 this.minimumTimestamp = in.readLong();
143 this.maximumTimestamp = in.readLong();
144 }
145
146 }
147