EventStore / EventStoreDB-Client-Java

Official Asynchronous Java 8+ Client Library for EventStoreDB 20.6+
https://eventstore.com
Apache License 2.0
63 stars 20 forks source link

Improve node selection algorithm #101

Closed dpasek-senacor closed 3 years ago

dpasek-senacor commented 3 years ago

This fixes https://github.com/EventStore/EventStoreDB-Client-Java/issues/83

Currently the node selection strategy always produces stable result always prefering a single node of the specified category. Always the same follower or read-only replica is selected based on the ClusterInfo retrieved from the seed node.

Even the NodePreference.RANDOM currently will always result in the same node to be returned to the client if the Member in the ClusterInfo will not change.

This PR properly performs random selection of nodes in each category. It also extracts the algorithm of the node selection into dedicated class for better testability.

dpasek-senacor commented 3 years ago

@YoEight I have added some more test cases on the NodeSelector

Theres is a miniscule chance that tests break if rolling the dice 100 times on node selection is not enough. 😉

ahjohannessen commented 3 years ago

we'll also need to tune it a bit to be aligned with the Reconnection RFC

@oskardudycz Where can I find this RFC? :)

oskardudycz commented 3 years ago

@ahjohannessen so far is internal, but I hope that we'll be able to show it publicly soon. If not through RFC, then maybe at least through docs 🙂

ahjohannessen commented 3 years ago

@oskardudycz ok, would be nice to have such that unofficial clients have some guide lines to follow :)

oskardudycz commented 3 years ago

@ahjohannessen, we want to be more open, not only in regards to the results and ask in advance for suggestions. To do that, we have to sort the RFC process internally (almost there 😉 ) then find a sustainable way to make that public. I'm sure that this will happen soon (no exact timeframe tho).

Regarding specs for unofficial clients, that's also on our TODO list. We won't be able to maintain all the languages, so for sure, we're taking that into account to work closely with the community 👍