org.apache.cassandra.db.compaction

## Class CompactionIterator

- java.lang.Object
- - org.apache.cassandra.db.compaction.CompactionInfo.Holder
  - - org.apache.cassandra.db.compaction.CompactionIterator

All Implemented Interfaces:
  java.lang.AutoCloseable, java.util.Iterator<UnfilteredRowIterator>, BasePartitionIterator<UnfilteredRowIterator>, UnfilteredPartitionIterator, CloseableIterator<UnfilteredRowIterator>

    public class CompactionIterator
    extends CompactionInfo.Holder
    implements UnfilteredPartitionIterator

Merge multiple iterators over the content of sstable into a "compacted" iterator.

On top of the actual merging the source iterators, this class:

- purge gc-able tombstones if possible (see PurgeIterator below).
- update 2ndary indexes if necessary (as we don't read-before-write on index updates, index entries are not deleted on deletion of the base table data, which is ok because we'll fix index inconsistency on reads. This however mean that potentially obsolete index entries could be kept a long time for data that is not read often, so compaction "pro-actively" fix such index entries. This is mainly an optimization).
- invalidate cached partitions that are empty post-compaction. This avoids keeping partitions with only purgable tombstones in the row cache.
- keep tracks of the compaction progress.

### Constructor Summary

Constructors
Constructor and Description
`CompactionIterator(OperationType type, java.util.List<ISSTableScanner> scanners, CompactionController controller, int nowInSec, java.util.UUID compactionId)`
`CompactionIterator(OperationType type, java.util.List<ISSTableScanner> scanners, CompactionController controller, int nowInSec, java.util.UUID compactionId, CompactionMetrics metrics)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()`
`CompactionInfo` `getCompactionInfo()`
`long[]` `getMergedRowCounts()`
`long` `getTotalSourceCQLRows()`
`boolean` `hasNext()`
`boolean` `isForThrift()` Whether that partition iterator is for a thrift queries.
`CFMetaData` `metadata()`
`UnfilteredRowIterator` `next()`
`void` `remove()`
`java.lang.String` `toString()`

### Methods inherited from class org.apache.cassandra.db.compaction.CompactionInfo.Holder

`isStopRequested, stop`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

### Constructor Detail

#### CompactionIterator

    public CompactionIterator(OperationType type,
                              java.util.List<ISSTableScanner> scanners,
                              CompactionController controller,
                              int nowInSec,
                              java.util.UUID compactionId)

#### CompactionIterator

    public CompactionIterator(OperationType type,
                              java.util.List<ISSTableScanner> scanners,
                              CompactionController controller,
                              int nowInSec,
                              java.util.UUID compactionId,
                              CompactionMetrics metrics)

### Method Detail

#### isForThrift

    public boolean isForThrift()

Description copied from interface: `UnfilteredPartitionIterator`
Whether that partition iterator is for a thrift queries.

If this is true, the partition iterator may return some empty UnfilteredRowIterator and those should be preserved as thrift include partitions that "exists" (have some cells even if this are actually deleted) but have nothing matching the query.

Specified by:
  `isForThrift` in interface `UnfilteredPartitionIterator`
Returns:
  whether the iterator is for a thrift query.

#### metadata

    public CFMetaData metadata()

Specified by:
  `metadata` in interface `UnfilteredPartitionIterator`

#### getCompactionInfo

    public CompactionInfo getCompactionInfo()

Specified by:
  `getCompactionInfo` in class `CompactionInfo.Holder`

#### getMergedRowCounts

    public long[] getMergedRowCounts()

#### getTotalSourceCQLRows

    public long getTotalSourceCQLRows()

#### hasNext

    public boolean hasNext()

Specified by:
  `hasNext` in interface `java.util.Iterator<UnfilteredRowIterator>`

#### next

    public UnfilteredRowIterator next()

Specified by:
  `next` in interface `java.util.Iterator<UnfilteredRowIterator>`

#### remove

    public void remove()

Specified by:
  `remove` in interface `java.util.Iterator<UnfilteredRowIterator>`

#### close

    public void close()

Specified by:
  `close` in interface `java.lang.AutoCloseable`
Specified by:
  `close` in interface `BasePartitionIterator<UnfilteredRowIterator>`
Specified by:
  `close` in interface `CloseableIterator<UnfilteredRowIterator>`

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`