forked from apache/accumulo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ExactDeletingIterator.java
116 lines (97 loc) · 3.61 KB
/
ExactDeletingIterator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.accumulo.core.iterators.system;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.ServerWrappingIterator;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
public class ExactDeletingIterator extends ServerWrappingIterator {
private boolean propogateDeletes;
private Key workKey = new Key();
@Override
public ExactDeletingIterator deepCopy(IteratorEnvironment env) {
return new ExactDeletingIterator(this, env);
}
public ExactDeletingIterator(ExactDeletingIterator other, IteratorEnvironment env) {
super(other.source.deepCopy(env));
propogateDeletes = other.propogateDeletes;
}
public ExactDeletingIterator(SortedKeyValueIterator<Key,Value> iterator,
boolean propogateDeletes) {
super(iterator);
this.propogateDeletes = propogateDeletes;
}
@Override
public void next() throws IOException {
if (source.getTopKey().isDeleted())
skipRowColumnTime();
else
source.next();
findTop();
}
private static Range adjustRange(Range range) {
Range seekRange = range;
if (range.getStartKey() != null
&& (range.isStartKeyInclusive() ^ range.getStartKey().isDeleted())) {
Key seekKey = new Key(seekRange.getStartKey());
seekKey.setDeleted(true);
seekRange = new Range(seekKey, true, range.getEndKey(), range.isEndKeyInclusive());
}
return seekRange;
}
@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
throws IOException {
// do not want to seek to the middle of a row
Range seekRange = adjustRange(range);
source.seek(seekRange, columnFamilies, inclusive);
findTop();
if (propogateDeletes && range != seekRange) {
while (source.hasTop() && range.beforeStartKey(source.getTopKey())) {
next();
}
}
}
private void findTop() throws IOException {
if (!propogateDeletes) {
while (source.hasTop() && source.getTopKey().isDeleted()) {
skipRowColumnTime();
}
}
}
private void skipRowColumnTime() throws IOException {
workKey.set(source.getTopKey());
Key keyToSkip = workKey;
source.next();
while (source.hasTop()
&& source.getTopKey().equals(keyToSkip, PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME)) {
source.next();
}
}
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
IteratorEnvironment env) {
throw new UnsupportedOperationException();
}
}