Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smembers returns elements in non-deterministic order #823

Closed
alezandr opened this issue Jul 26, 2018 · 2 comments
Closed

smembers returns elements in non-deterministic order #823

alezandr opened this issue Jul 26, 2018 · 2 comments
Labels
type: bug A general bug type: regression A regression from a previous release
Milestone

Comments

@alezandr
Copy link

I'm using Repositories from spring-data-redis, and I noticed that some of my tests against data repositories is unstable, sometimes they all passes, sometimes one of them fails. I found that CrudRepository.findAll() returns entities in order which is different from run to run. The problem is caused by unpredictable results ordering from call to smembers. I know that redis's set store do not guarantee ordering, but it must be at least deterministic, i.e. no changes in data -> no changes in order.

The order is changed in lettuce code, where the results are transformed to the byte[] and then they are stored in HashSet<byte[]>. Since byte[] does not care about hashCode, this brings to random position in hashset. The code where this behavior can be observed during debugging: io.lettuce.core.output.ValueSetOutput.

Possible solution: Probably byte[] must be replaced to ByteBuffer, because ByteBuffer has overridden method hashCode (i.e. it will stay the same until there's no changes in the data)

@mp911de mp911de added the type: bug A general bug label Jul 27, 2018
@mp911de mp911de added this to the Lettuce 4.4.6 milestone Jul 27, 2018
@mp911de
Copy link
Collaborator

mp911de commented Jul 27, 2018

Good catch and thanks a lot for the bug report. The problem is indeed that ValueSetOutput uses a HashSet and not LinkedHashSet. LinkedHashSet has a predictable iteration order as it retains insertion order on unique elements.

@mp911de mp911de added the type: regression A regression from a previous release label Jul 27, 2018
mp911de added a commit that referenced this issue Jul 27, 2018
Lettuce now retains the response order for set results such as smembers. Previously, we used a plain HashSet that did not honor insertion order. Now we're using LinkedHashSet that retains the insertion order for unique elements.
mp911de added a commit that referenced this issue Jul 27, 2018
Lettuce now retains the response order for set results such as smembers. Previously, we used a plain HashSet that did not honor insertion order. Now we're using LinkedHashSet that retains the insertion order for unique elements.
mp911de added a commit that referenced this issue Jul 27, 2018
Lettuce now retains the response order for set results such as smembers. Previously, we used a plain HashSet that did not honor insertion order. Now we're using LinkedHashSet that retains the insertion order for unique elements.
mp911de added a commit that referenced this issue Jul 27, 2018
Lettuce now retains the response order for set results such as smembers. Previously, we used a plain HashSet that did not honor insertion order. Now we're using LinkedHashSet that retains the insertion order for unique elements.
@mp911de
Copy link
Collaborator

mp911de commented Jul 27, 2018

That's fixed now for all maintained branches (4.x, 4.4.x, 5.0.x, 5.x/master).

@mp911de mp911de closed this as completed Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

2 participants