2121import java .util .Collection ;
2222import java .util .HashSet ;
2323import java .util .Map ;
24+ import java .util .function .LongPredicate ;
2425
2526import com .google .common .annotations .VisibleForTesting ;
2627import org .apache .accumulo .core .client .IteratorSetting ;
4445 */
4546public class GarbageCollectionIterator implements SortedKeyValueIterator <Key , Value > {
4647
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-
5948 @ VisibleForTesting
6049 static final String GC_TIMESTAMP_OPT = "timestamp.gc" ;
6150
@@ -65,8 +54,8 @@ public KeyValue(Key key, byte[] value) {
6554 private Long gcTimestamp ;
6655 private SortedKeyValueIterator <Key , Value > source ;
6756
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 ();
7059 private HashSet <Long > completeTxs = new HashSet <>();
7160 private HashSet <Long > rolledback = new HashSet <>();
7261 private Key curCol = new Key ();
@@ -77,11 +66,11 @@ public KeyValue(Key key, byte[] value) {
7766 @ Override
7867 public void init (SortedKeyValueIterator <Key , Value > source , Map <String , String > options ,
7968 IteratorEnvironment env ) throws IOException {
69+
8070 if (env .getIteratorScope () == IteratorScope .scan ) {
8171 throw new IllegalArgumentException ();
8272 }
8373 this .source = source ;
84-
8574 isFullMajc = env .getIteratorScope () == IteratorScope .majc && env .isFullMajorCompaction ();
8675
8776 String oats = options .get (GC_TIMESTAMP_OPT );
@@ -96,6 +85,7 @@ public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String>
9685 }
9786 }
9887
88+
9989 @ Override
10090 public boolean hasTop () {
10191 return position < keysFiltered .size () || source .hasTop ();
@@ -191,7 +181,7 @@ private void readColMetadata() throws IOException {
191181 long ts = source .getTopKey ().getTimestamp () & ColumnConstants .TIMESTAMP_MASK ;
192182
193183 if (colType == ColumnConstants .TX_DONE_PREFIX ) {
194- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
184+ keys .add (source .getTopKey (), source .getTopValue ());
195185 completeTxs .add (ts );
196186 } else if (colType == ColumnConstants .WRITE_PREFIX ) {
197187 boolean keep = false ;
@@ -224,7 +214,7 @@ private void readColMetadata() throws IOException {
224214 }
225215
226216 if (keep ) {
227- keys .add (new KeyValue ( source .getTopKey (), val ) );
217+ keys .add (source .getTopKey (), val );
228218 } else if (complete ) {
229219 completeTxs .remove (ts );
230220 }
@@ -249,21 +239,21 @@ private void readColMetadata() throws IOException {
249239 }
250240
251241 if (keep ) {
252- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
242+ keys .add (source .getTopKey (), source .getTopValue ());
253243 } else if (complete ) {
254244 completeTxs .remove (txDoneTs );
255245 }
256246 } else if (colType == ColumnConstants .LOCK_PREFIX ) {
257247 if (ts > invalidationTime ) {
258- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
248+ keys .add (source .getTopKey (), source .getTopValue ());
259249 }
260250 } else if (colType == ColumnConstants .DATA_PREFIX ) {
261251 // can stop looking
262252 break ;
263253 } else if (colType == ColumnConstants .ACK_PREFIX ) {
264254 if (!sawAck ) {
265255 if (ts >= firstWrite ) {
266- keys .add (new KeyValue ( source .getTopKey (), source .getTopValue () ));
256+ keys .add (source .getTopKey (), source .getTopValue ());
267257 }
268258 sawAck = true ;
269259 }
@@ -274,22 +264,20 @@ private void readColMetadata() throws IOException {
274264 source .next ();
275265 }
276266
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 ;
279269 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 );
283271 } else {
284- keysFiltered . add ( kv ) ;
272+ return true ;
285273 }
286- }
274+ }));
287275 }
288276
289277 @ Override
290278 public Key getTopKey () {
291279 if (position < keysFiltered .size ()) {
292- return keysFiltered .get ( position ). getKey ();
280+ return keysFiltered .getKey (position );
293281 } else {
294282 return source .getTopKey ();
295283 }
@@ -298,7 +286,7 @@ public Key getTopKey() {
298286 @ Override
299287 public Value getTopValue () {
300288 if (position < keysFiltered .size ()) {
301- return keysFiltered .get ( position ). getValue ();
289+ return keysFiltered .getValue (position );
302290 } else {
303291 return source .getTopValue ();
304292 }
0 commit comments