Skip to content

orders iterators by name when priority the same#6075

Merged
keith-turner merged 3 commits intoapache:2.1from
keith-turner:iter-prio
Jan 26, 2026
Merged

orders iterators by name when priority the same#6075
keith-turner merged 3 commits intoapache:2.1from
keith-turner:iter-prio

Conversation

@keith-turner
Copy link
Contributor

This is follow on work from #6040. It modifies the sorting of iterators to consider name when the priority is equals. This makes iterator order more deterministic for this case. Also adds scan and compaction test that ensure iterators are applied in the correct order.

@keith-turner keith-turner added this to the 2.1.5 milestone Jan 23, 2026
public static final Comparator<IterInfo> ITER_INFO_COMPARATOR =
Comparator.comparingInt(IterInfo::getPriority);
Comparator.comparingInt(IterInfo::getPriority)
.thenComparing(iterInfo -> iterInfo.getIterName() == null ? "" : iterInfo.getIterName());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do not expect the name to be null. Was being defensive w/ this null check since this a 2.1 change. Did not want something that used to work to start throwing a NPE.

// There are no compaction iterators, so this should not change value
c.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
assertEquals("base:bxmac", scanner.iterator().next().getValue().toString());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test that configures two iterators at the same priority and different names, or is that here and I missed it?

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 merged iterators will have that. The table has iterators with name append_x,50 and append_a,100. The scanner sets iterators with append_b,50 and append_c,100.

Trying to make the scanner have that will throw an exception and that may be covered by other test. For this test wanted to ensure the merged view had a consistent order. Also I am not sure there is any test for the iterator order, so this test also covers that basic case.

Copy link
Member

@kevinrr888 kevinrr888 left a comment

Choose a reason for hiding this comment

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

This looks good

Comment on lines +1029 to +1034
List<IteratorSetting> iters = List.of(AppendingIterator.configure(70, "m"),
AppendingIterator.configure(50, "b"), AppendingIterator.configure(100, "c"));
c.tableOperations().compact(names[1],
new CompactionConfig().setWait(true).setFlush(true).setIterators(iters));
assertEquals("base:xa", mincScanner.iterator().next().getValue().toString());
assertEquals("base:bxmac", majcScanner.iterator().next().getValue().toString());
Copy link
Member

Choose a reason for hiding this comment

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

A comment to note that (50, "b") and (100, "c") share the same priority as other iterators would be helpful

Comment on lines +1031 to +1032
c.tableOperations().compact(names[1],
new CompactionConfig().setWait(true).setFlush(true).setIterators(iters));
Copy link
Member

Choose a reason for hiding this comment

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

A few comments:

  1. This made me realize I did not consider CompactionConfig in Prevents iterator conflicts #6040, so even with 6040, this call will not log a warning (should log a warning in 2.1 since we are setting a majc iter with the same priority as a majc iter set on the table). To avoid adding more to that PR, should probably open a follow on issue to address this after 6040 is merged.
  2. I think all of the testing added in this PR will need to be removed in main when Prevents iterator conflicts #6040 is merged up to main. This is because adding an iterator of the same priority will cause an exception in main. As mentioned above, there's the CompactionConfig caveat for now, but this testing should still be removed with the merging of 6040 into main. The follow on issue will address making CompactionConfig throw in the case of attempting to add an iter of existing priority (or name) and should add testing to IteratorConflictsIT to confirm it does throw.
  3. I can keep the changes made to ITER_INFO_COMPARATOR in this PR in main for consistency

These are comments for dicussion/notes-to-self when I merge 6040, nothing to change in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think all of the testing added in this PR will need to be removed in main when #6040 is merged up to main.

Want to keep a subset of the testing. Still want to test that iterators are applied in the expected order, can drop testing of duplicate priorities.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that sounds good. I thought this was mostly for testing dup priorities and there was testing elsewhere for expected ordering, but maybe there is no such testing...

@keith-turner keith-turner merged commit bf50db7 into apache:2.1 Jan 26, 2026
8 checks passed
@keith-turner keith-turner deleted the iter-prio branch January 26, 2026 21:33
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.

3 participants