fix progress counting in wide row iterator patch by Piotr Koalczkowski; reviewed by jbellis for CASSANDRA-4803
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/8bab6feb Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/8bab6feb Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/8bab6feb Branch: refs/heads/trunk Commit: 8bab6febb5cb14f8c14c2850eb7fd9fc84ef7fb6 Parents: a28a2ba Author: Jonathan Ellis <[email protected]> Authored: Fri Oct 19 17:59:09 2012 -0500 Committer: Jonathan Ellis <[email protected]> Committed: Fri Oct 19 18:31:54 2012 -0500 ---------------------------------------------------------------------- .../cassandra/hadoop/ColumnFamilyRecordReader.java | 23 +++++++++++++- 1 files changed, 21 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bab6feb/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java index b41ca47..7c57a14 100644 --- a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java +++ b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java @@ -102,7 +102,9 @@ public class ColumnFamilyRecordReader extends RecordReader<ByteBuffer, SortedMap public float getProgress() { - // TODO this is totally broken for wide rows + if (!iter.hasNext()) + return 1.0F; + // the progress is likely to be reported slightly off the actual but close enough float progress = ((float) iter.rowsRead() / totalRowCount); return progress > 1.0F ? 1.0F : progress; @@ -414,6 +416,7 @@ public class ColumnFamilyRecordReader extends RecordReader<ByteBuffer, SortedMap { private PeekingIterator<Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>>> wideColumns; private ByteBuffer lastColumn = ByteBufferUtil.EMPTY_BYTE_BUFFER; + private ByteBuffer lastCountedKey = ByteBufferUtil.EMPTY_BYTE_BUFFER; private void maybeInit() { @@ -466,12 +469,28 @@ public class ColumnFamilyRecordReader extends RecordReader<ByteBuffer, SortedMap if (rows == null) return endOfData(); - totalRead++; Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> next = wideColumns.next(); lastColumn = next.right.values().iterator().next().name(); + + maybeCountRow(next); return next; } + + /** + * Increases the row counter only if we really moved to the next row. + * @param next just fetched row slice + */ + private void maybeCountRow(Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> next) + { + ByteBuffer currentKey = next.left; + if (!currentKey.equals(lastCountedKey)) + { + totalRead++; + lastCountedKey = currentKey; + } + } + private class WideColumnIterator extends AbstractIterator<Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>>> { private final Iterator<KeySlice> rows;
