Skip to content

Commit 6914cba

Browse files
committed
Report deleted rows in rowIterator and fix columns
1 parent 41247e1 commit 6914cba

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

src/java/org/apache/cassandra/db/partitions/TrieBackedPartition.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,35 @@ public static TrieBackedPartition create(DecoratedKey partitionKey,
269269
: new WithEnsureOnHeap(partitionKey, columnMetadata, encodingStats, rowCountIncludingStatic, tombstoneCount, trie, metadata, ensureOnHeap);
270270
}
271271

272-
class RowIterator extends TrieEntriesIterator<Object, Row>
272+
class RowIterator extends TrieEntriesIterator.WithNullFiltering<Object, Row>
273273
{
274274
public RowIterator(DeletionAwareTrie<Object, TrieTombstoneMarker> trie, Direction direction)
275275
{
276-
super(trie.contentOnlyTrie(), direction, RowData.class::isInstance);
276+
super(trie.mergedTrie(TrieBackedPartition::combineDataAndDeletion), direction);
277277
}
278278

279279
@Override
280280
protected Row mapContent(Object content, byte[] bytes, int byteLength)
281281
{
282-
var rd = (RowData) content;
283-
return toRow(rd,
284-
metadata.comparator.clusteringFromByteComparable(
285-
ByteBufferAccessor.instance,
286-
ByteComparable.preencoded(BYTE_COMPARABLE_VERSION, bytes, 0, byteLength)));
282+
if (content instanceof RowData)
283+
return toRow((RowData) content,
284+
getClustering(bytes, byteLength));
285+
if (content instanceof Row)
286+
{
287+
BTreeRow row = (BTreeRow) content;
288+
return BTreeRow.create(getClustering(bytes, byteLength),
289+
row.primaryKeyLivenessInfo(),
290+
row.deletion(),
291+
row.getBTree(),
292+
row.getMinLocalDeletionTime());
293+
}
294+
295+
TrieTombstoneMarker marker = (TrieTombstoneMarker) content;
296+
if (marker.hasPointData())
297+
return BTreeRow.emptyDeletedRow(getClustering(bytes, byteLength),
298+
Row.Deletion.regular(marker.deletionTime()));
299+
else
300+
return null;
287301
}
288302
}
289303

@@ -513,6 +527,14 @@ public static Object combineDataAndDeletion(Object data, TrieTombstoneMarker del
513527
return rowData.toRow(Clustering.EMPTY, deletion.deletionTime());
514528
}
515529

530+
private Clustering<?> getClustering(byte[] bytes, int byteLength)
531+
{
532+
return metadata.comparator.clusteringFromByteComparable(ByteBufferAccessor.instance,
533+
ByteComparable.preencoded(BYTE_COMPARABLE_VERSION,
534+
bytes, 0, byteLength),
535+
BYTE_COMPARABLE_VERSION);
536+
}
537+
516538
/// Implementation of [UnfilteredRowIterator] for this partition.
517539
///
518540
/// Currently, this implementation is pretty involved because it has to revert the transformations done to row and
@@ -573,14 +595,6 @@ protected Unfiltered mapContent(Object content, byte[] bytes, int byteLength)
573595
partitionLevelDeletion);
574596
}
575597

576-
private Clustering<?> getClustering(byte[] bytes, int byteLength)
577-
{
578-
return metadata.comparator.clusteringFromByteComparable(ByteBufferAccessor.instance,
579-
ByteComparable.preencoded(BYTE_COMPARABLE_VERSION,
580-
bytes, 0, byteLength),
581-
BYTE_COMPARABLE_VERSION);
582-
}
583-
584598
@Override
585599
public DeletionTime partitionLevelDeletion()
586600
{
@@ -608,7 +622,7 @@ public boolean isReverseOrder()
608622
@Override
609623
public RegularAndStaticColumns columns()
610624
{
611-
return columns;
625+
return selection.fetchedColumns();
612626
}
613627

614628
@Override

test/unit/org/apache/cassandra/db/RowUpdateBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public RowUpdateBuilder(TableMetadata metadata, int localDeletionTime, long time
7272
this.updateBuilder.nowInSec(localDeletionTime);
7373
}
7474

75+
public RowUpdateBuilder(TableMetadata metadata, DeletionTime partitionDeletion, int nowInSec, long timestamp, Object partitionKey)
76+
{
77+
this(PartitionUpdate.simpleBuilder(metadata, partitionKey));
78+
79+
this.updateBuilder.timestamp(partitionDeletion.markedForDeleteAt());
80+
this.updateBuilder.nowInSec(partitionDeletion.localDeletionTime());
81+
this.updateBuilder.delete();
82+
this.updateBuilder.timestamp(timestamp);
83+
this.updateBuilder.nowInSec(nowInSec);
84+
}
85+
7586
public RowUpdateBuilder timestamp(long ts)
7687
{
7788
updateBuilder.timestamp(ts);

test/unit/org/apache/cassandra/service/reads/DataResolverTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,9 @@ public void testRepairRangeTombstoneWithPartitionDeletion2()
658658

659659
// 1st "stream": a partition deletion and a range tombstone
660660
RangeTombstone rt1 = tombstone("0", true , "9", true, 11, nowInSec);
661-
PartitionUpdate upd1 = new RowUpdateBuilder(cfm, nowInSec, 1L, dk)
661+
PartitionUpdate upd1 = new RowUpdateBuilder(cfm, new DeletionTime(10, nowInSec), nowInSec, 1L, dk)
662662
.addRangeTombstone(rt1)
663663
.buildUpdate();
664-
((MutableDeletionInfo)upd1.deletionInfo()).add(new DeletionTime(10, nowInSec));
665664
UnfilteredPartitionIterator iter1 = iter(upd1);
666665

667666
// 2nd "stream": a range tombstone that is covered by the other stream rt

0 commit comments

Comments
 (0)