Skip to content

Conversation

@swamirishi
Copy link
Contributor

@swamirishi swamirishi commented Jan 1, 2026

What changes were proposed in this pull request?

MinHeapMergeIterator should use key comparator while popping out entries from the heap. Currently it uses Object.equals() which can fetch wrong results when comparing the key without the key comparator.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14330

How was this patch tested?

Updated unit tests to use byte array

…ing out entries from the heap

Change-Id: Ia196692c74237ae100180b27dc5c2b5b661ba783
@swamirishi swamirishi changed the title HDDS-14330. MinHeapMergeIterator should use key comparator while popp… HDDS-14330. MinHeapMergeIterator should use key comparator while popping out entries from the heap Jan 1, 2026
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a hypothetical problem or is there a case to reproduce?

class TestMinHeapMergeIterator {

private static final Comparator<String> STRING_COMPARATOR = String::compareTo;
private static final Comparator<byte[]> BYTE_COMPARATOR = UnsignedBytes.lexicographicalComparator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is updating String to byte array a necessary change to reproduce the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iterator need not be always an Itr it can be Itr<KeyValue<String, >> and KeyValue doesn't implement equals method

KeyValue<KEY, Object> defaultNullValue = newKeyValue(null, null);
Comparator<KeyValue<KEY, Object>> comparator = Comparator.comparing(KeyValue::getKey, keyComparator);
return new MinHeapMergeIterator<KeyValue<KEY, Object>, Table.KeyValueIterator<KEY, Object>,
KeyValue<KEY, Collection<Object>>>(table.length + 1, comparator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall why it was table.length + 1 before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a typo

@swamirishi swamirishi marked this pull request as ready for review January 2, 2026 11:24
@swamirishi swamirishi merged commit 90994bb into apache:master Jan 2, 2026
95 of 98 checks passed
@swamirishi
Copy link
Contributor Author

Thank you @jojochuang for reviewing the patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants