Skip to content

Conversation

@Claudenw
Copy link
Contributor

Fixed issue where sstables were not updated in order by sorting on SSTableId

patch by Claude Warren; reviewed by for CASSANDRA-18143

Fixed issue where sstables were not updated in order by sorting on SSTableId

patch by Claude Warren; reviewed by <Reviewers> for CASSANDRA--18143
Descriptor descriptor = new Descriptor( version, directory, ksname, cfname, id, formatType);
HashSet<Descriptor> set = new HashSet<>();
set.add( descriptor );
Object[] arry = set.toArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose it should be a generic method somewhere in the utility class. Something which take a function, for example <T> T generateUntilUnordered(Collection<T> collection, Function<T, T> generator) where generator accepts previously generated value, and initially null.

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 don't think this will work here. The issue is that the HashSet wraps the values of the hash long before Hash collides. The method literally has to insert into the Hash table and then verify that the last item in the Hash table was the one inserted. I have simplified the code so that it only retains two Descriptors at a time.

Copy link
Contributor

@jacek-lewandowski jacek-lewandowski Jan 13, 2023

Choose a reason for hiding this comment

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

I was thinking about something like this:

    static <T> T findFirstUnordered(java.util.function.Function<T, T> provider)
    {
        HashSet<T> set = new HashSet<>(2);
        T first = null;
        while (true)
        {
            set.clear();
            T second = provider.apply(first);
            if (first != null)
            {
                set.add(first);
                set.add(second);
                if (set.iterator().next() != first)
                    return second;
            }
            first = second;
        }
    }

@belliottsmith belliottsmith force-pushed the trunk branch 2 times, most recently from df3eb40 to 54e39a9 Compare July 23, 2025 11:19
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