21
21
import java .util .Collection ;
22
22
import java .util .HashSet ;
23
23
import java .util .Map ;
24
+ import java .util .function .LongPredicate ;
24
25
25
26
import com .google .common .annotations .VisibleForTesting ;
26
27
import org .apache .accumulo .core .client .IteratorSetting ;
44
45
*/
45
46
public class GarbageCollectionIterator implements SortedKeyValueIterator <Key , Value > {
46
47
47
- private static class KeyValue extends SimpleImmutableEntry <Key , Value > {
48
- private static final long serialVersionUID = 1L ;
49
-
50
- public KeyValue (Key key , Value value ) {
51
- super (new Key (key ), new Value (value ));
52
- }
53
-
54
- public KeyValue (Key key , byte [] value ) {
55
- super (new Key (key ), new Value (value ));
56
- }
57
- }
58
-
59
48
@ VisibleForTesting
60
49
static final String GC_TIMESTAMP_OPT = "timestamp.gc" ;
61
50
@@ -65,8 +54,8 @@ public KeyValue(Key key, byte[] value) {
65
54
private Long gcTimestamp ;
66
55
private SortedKeyValueIterator <Key , Value > source ;
67
56
68
- private ArrayList < KeyValue > keys = new ArrayList <> ();
69
- private ArrayList < KeyValue > keysFiltered = new ArrayList <> ();
57
+ private ColumnBuffer keys = new ColumnBuffer ();
58
+ private ColumnBuffer keysFiltered = new ColumnBuffer ();
70
59
private HashSet <Long > completeTxs = new HashSet <>();
71
60
private HashSet <Long > rolledback = new HashSet <>();
72
61
private Key curCol = new Key ();
@@ -77,11 +66,11 @@ public KeyValue(Key key, byte[] value) {
77
66
@ Override
78
67
public void init (SortedKeyValueIterator <Key , Value > source , Map <String , String > options ,
79
68
IteratorEnvironment env ) throws IOException {
69
+
80
70
if (env .getIteratorScope () == IteratorScope .scan ) {
81
71
throw new IllegalArgumentException ();
82
72
}
83
73
this .source = source ;
84
-
85
74
isFullMajc = env .getIteratorScope () == IteratorScope .majc && env .isFullMajorCompaction ();
86
75
87
76
String oats = options .get (GC_TIMESTAMP_OPT );
@@ -96,6 +85,7 @@ public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String>
96
85
}
97
86
}
98
87
88
+
99
89
@ Override
100
90
public boolean hasTop () {
101
91
return position < keysFiltered .size () || source .hasTop ();
@@ -191,7 +181,7 @@ private void readColMetadata() throws IOException {
191
181
long ts = source .getTopKey ().getTimestamp () & ColumnConstants .TIMESTAMP_MASK ;
192
182
193
183
if (colType == ColumnConstants .TX_DONE_PREFIX ) {
194
- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
184
+ keys .add (source .getTopKey (), source .getTopValue ());
195
185
completeTxs .add (ts );
196
186
} else if (colType == ColumnConstants .WRITE_PREFIX ) {
197
187
boolean keep = false ;
@@ -224,7 +214,7 @@ private void readColMetadata() throws IOException {
224
214
}
225
215
226
216
if (keep ) {
227
- keys .add (new KeyValue ( source .getTopKey (), val ) );
217
+ keys .add (source .getTopKey (), val );
228
218
} else if (complete ) {
229
219
completeTxs .remove (ts );
230
220
}
@@ -249,21 +239,21 @@ private void readColMetadata() throws IOException {
249
239
}
250
240
251
241
if (keep ) {
252
- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
242
+ keys .add (source .getTopKey (), source .getTopValue ());
253
243
} else if (complete ) {
254
244
completeTxs .remove (txDoneTs );
255
245
}
256
246
} else if (colType == ColumnConstants .LOCK_PREFIX ) {
257
247
if (ts > invalidationTime ) {
258
- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
248
+ keys .add (source .getTopKey (), source .getTopValue ());
259
249
}
260
250
} else if (colType == ColumnConstants .DATA_PREFIX ) {
261
251
// can stop looking
262
252
break ;
263
253
} else if (colType == ColumnConstants .ACK_PREFIX ) {
264
254
if (!sawAck ) {
265
255
if (ts >= firstWrite ) {
266
- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
256
+ keys .add (source .getTopKey (), source .getTopValue ());
267
257
}
268
258
sawAck = true ;
269
259
}
@@ -274,22 +264,20 @@ private void readColMetadata() throws IOException {
274
264
source .next ();
275
265
}
276
266
277
- for ( KeyValue kv : keys ) {
278
- long colType = kv . getKey (). getTimestamp () & ColumnConstants .PREFIX_MASK ;
267
+ keys . copyTo ( keysFiltered , ( timestamp -> {
268
+ long colType = timestamp & ColumnConstants .PREFIX_MASK ;
279
269
if (colType == ColumnConstants .TX_DONE_PREFIX ) {
280
- if (completeTxs .contains (kv .getKey ().getTimestamp () & ColumnConstants .TIMESTAMP_MASK )) {
281
- keysFiltered .add (kv );
282
- }
270
+ return completeTxs .contains (timestamp & ColumnConstants .TIMESTAMP_MASK );
283
271
} else {
284
- keysFiltered . add ( kv ) ;
272
+ return true ;
285
273
}
286
- }
274
+ }));
287
275
}
288
276
289
277
@ Override
290
278
public Key getTopKey () {
291
279
if (position < keysFiltered .size ()) {
292
- return keysFiltered .get ( position ). getKey ();
280
+ return keysFiltered .getKey (position );
293
281
} else {
294
282
return source .getTopKey ();
295
283
}
@@ -298,7 +286,7 @@ public Key getTopKey() {
298
286
@ Override
299
287
public Value getTopValue () {
300
288
if (position < keysFiltered .size ()) {
301
- return keysFiltered .get ( position ). getValue ();
289
+ return keysFiltered .getValue (position );
302
290
} else {
303
291
return source .getTopValue ();
304
292
}
0 commit comments