Skip to content

Conversation

@walles
Copy link
Contributor

@walles walles commented Jan 25, 2021

No behavior changes, just a refactoring.

Changes:

  • Replaces recursion with a for loop
  • Extract redirection handling into its own method
  • Extract connection-failed handling into its own method

I did try to keep the order of the new methods the same order as the previous catch blocks.

Note that tryWithRandomNode is gone, it was never true so it and its code didn't survive the refactoring.

I think redirection handling looks a bit strange, but it didn't change from before. If it is wrong then that should be fixed in another PR, this one is just a refactoring.

Reviewer notes

The git diff isn't great for this change.

If you want to see what changed it's probably easier to bring the old and the new code up side by side and compare that way instead.

Here's the old version for reference: https://github.com/redis/jedis/blob/master/src/main/java/redis/clients/jedis/JedisClusterCommand.java

Copy link
Contributor

@sazzad16 sazzad16 left a comment

Choose a reason for hiding this comment

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

This is more of a code suggestion. We'll almost always need a normal connection getter. Why not have one final defaultConnectionGetter created within constructor and use it everywhere else?

@walles walles marked this pull request as ready for review January 25, 2021 09:19
walles pushed a commit to walles/jedis that referenced this pull request Jan 25, 2021
Inspired by redis#1334 where this went real easy :).

Would have made redis#2355 shorter.

Free public updates for JDK 7 ended in 2015:
<https://en.wikipedia.org/wiki/Java_version_history>

For JDK 8, free public support is available from non-Orace vendors until
at least 2026 according to the same table.

And JDK 8 is what Jedis is being tested on anyway:
<https://github.com/redis/jedis/blob/ac0969315655180c09b8139c16bded09c068d498/.circleci/config.yml#L67-L74>
@walles walles mentioned this pull request Jan 25, 2021
@walles walles requested a review from sazzad16 January 25, 2021 10:24
jensgreen pushed a commit to walles/jedis that referenced this pull request Jan 25, 2021
Inspired by redis#1334 where this went real easy :).

Would have made redis#2355 shorter.

Free public updates for JDK 7 ended in 2015:
<https://en.wikipedia.org/wiki/Java_version_history>

For JDK 8, free public support is available from non-Orace vendors until
at least 2026 according to the same table.

And JDK 8 is what Jedis is being tested on anyway:
<https://github.com/redis/jedis/blob/ac0969315655180c09b8139c16bded09c068d498/.circleci/config.yml#L67-L74>
@walles
Copy link
Contributor Author

walles commented Jan 26, 2021

AFAWCT we have no outstanding tasks here and are awaiting review.

So for clarity, do you think this is ready for review / merge @sazzad16, or are you expecting any more changes from our side?

sazzad16
sazzad16 previously approved these changes Jan 26, 2021
@sazzad16
Copy link
Contributor

@walles According to community rule, we need approval of at least two collaborators. Let me see what I can do.
In the mean time, you can wait or continue to work on another PR based on this PR.

@walles
Copy link
Contributor Author

walles commented Feb 1, 2021

@sazzad16 is there anything we can do to get this reviewed?

Given that me and @jensgreen pair programmed this and you reviewed it, we are three people who approve of these changes so far.

@sazzad16
Copy link
Contributor

sazzad16 commented Feb 1, 2021

@walles I don't know anything else but asking the reviewers (which I've done). Please understand that they are doing it voluntarily, using their free time.

@walles
Copy link
Contributor Author

walles commented Feb 6, 2021

@yangbodong22011 / @sazzad16, with @yangbodong22011's suggested change applied (good catch Yang!), do you think this is ready for merge?

Johan Walles and others added 6 commits February 8, 2021 09:12
No behavior changes, just a refactoring.

Changes:
* Replaces recursion with a for loop
* Extract redirection handling into its own method
* Extract connection-failed handling into its own method

Note that `tryWithRandomNode` is gone, it was never `true` so it and its
code didn't survive the refactoring.
Inspired by redis#1334 where this went real easy :).

Would have made redis#2355 shorter.

Free public updates for JDK 7 ended in 2015:
<https://en.wikipedia.org/wiki/Java_version_history>

For JDK 8, free public support is available from non-Orace vendors until
at least 2026 according to the same table.

And JDK 8 is what Jedis is being tested on anyway:
<https://github.com/redis/jedis/blob/ac0969315655180c09b8139c16bded09c068d498/.circleci/config.yml#L67-L74>
@walles walles force-pushed the walles/retries-split branch from 0ad0b4f to 4f138e4 Compare February 8, 2021 08:12
mina-asham
mina-asham previously approved these changes Feb 17, 2021
Copy link
Contributor

@mina-asham mina-asham left a comment

Choose a reason for hiding this comment

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

Looks good, just suggesting a minor enhancement there but not a blocker for me.

@walles walles force-pushed the walles/retries-split branch from 31df601 to 4f80d73 Compare February 17, 2021 14:19
@walles walles requested a review from mina-asham February 17, 2021 14:20
walles pushed a commit to walles/jedis that referenced this pull request Feb 25, 2021
Source (all of these point to the same place):
* walles/retries-split
* 4f80d73
* redis#2355
@sazzad16 sazzad16 merged commit 9006788 into redis:master Feb 26, 2021
@walles walles deleted the walles/retries-split branch February 26, 2021 12:35
sazzad16 added a commit that referenced this pull request Mar 31, 2021
* Split JedisClusterCommand into multiple methods

No behavior changes, just a refactoring.

Changes:
* Replaces recursion with a for loop
* Extract redirection handling into its own method
* Extract connection-failed handling into its own method

Note that `tryWithRandomNode` is gone, it was never `true` so it and its
code didn't survive the refactoring.

* Drop redundant null check

* Bump JDK version to 1.8

Inspired by #1334 where this went real easy :).

Would have made #2355 shorter.

Free public updates for JDK 7 ended in 2015:
<https://en.wikipedia.org/wiki/Java_version_history>

For JDK 8, free public support is available from non-Orace vendors until
at least 2026 according to the same table.

And JDK 8 is what Jedis is being tested on anyway:
<https://github.com/redis/jedis/blob/ac0969315655180c09b8139c16bded09c068d498/.circleci/config.yml#L67-L74>

* Replace ConnectionGetters with lambdas

* Retrigger CI

* Add backoff to Redis connections

* Add unit tests for backoff logic

* Add retries logging

* Always use the user requested timeout

* Remedy review feedback

* Consider connection exceptions and disregard random nodes

* consider connection exceptions and disregard random nodes

* reset redirection

* Revert "Consider connection exceptions and disregard random nodes"

This reverts commit 67a062a.

Lots of tests in JedisClusterCommandTests started failing, need to be
fixed before trying again.

* Add another backoff test case

1. We try to contact master => JedisConnectionException
2. We try to contact replica => It refers us to master, hasn't failed over yet
3. We try to contact master => JedisConnectionException
4. We try to contact replica => Success, because it has now failed over

* consider connection exceptions and disregard random nodes

* reset redirection

* Fix test failure

* Apply suggestions from code review

Co-authored-by: Jens Green Olander <[email protected]>

* update documentation

* Improve a comment

* Update src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java

* Add change from another branch

Source (all of these point to the same place):
* walles/retries-split
* 4f80d73
* #2355

* Move JedisClusterCommandTest out of commands package

* Use JedisClusterOperationException

* Reduce sleep time, especially when few attempts left

* Update src/main/java/redis/clients/jedis/JedisClusterCommand.java

* merge fix

* merge fix

* Use maxAttempts

* format import

* Re-add missing codes due to merge

* avoid NPE while zero max attempts

* Remove zero attempts test

* More cluster constructors and customizability

* Use maxTotalRetriesDuration everywhere

* more missing maxTotalRetriesDuration after merge

Co-authored-by: M Sazzadul Hoque <[email protected]>
Co-authored-by: Jens Green Olander <[email protected]>
Co-authored-by: Jens Green Olander <[email protected]>
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.

5 participants