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

[#2341] Initialize slots with empty BitSet in RedisClusterNode's constructors #2852

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

zeze1004
Copy link

@zeze1004 zeze1004 commented May 12, 2024

Issue: #2341
This PR supersedes the previously closed PR #2798

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

@zeze1004
Copy link
Author

@mp911de

I kindly request your review of this pull request. Your feedback would be greatly appreciated. 🙇🏻

@zeze1004
Copy link
Author

I tested everything locally and it passed, but it failed on GitHub Actions. I'll make the necessary fixes and commit again soon.

@tishun
Copy link
Collaborator

tishun commented May 23, 2024

I tested everything locally and it passed, but it failed on GitHub Actions. I'll make the necessary fixes and commit again soon.

Please ignore the failure of the SslIntegrationTests.pubSubSsl:396 - it is unstable and if you pull the latest sources you will see it is disabled

Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Please check my comments and let me know if you need any clarifications or have some concerns.

@zeze1004 zeze1004 force-pushed the fix/RedisClusterNode.hasSameSlotsAs() branch from 25d74c3 to 4fe8d21 Compare June 1, 2024 06:36
@zeze1004 zeze1004 requested a review from tishun June 1, 2024 07:17
Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

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

Hey thanks for addressing the last comments.

There are still two things that I am worried about:

  1. We are still missing the same logic on line 90 (the first of the three constructors)
  2. The test is not really verifying the issue from RedisClusterNode.hasSameSlotsAs() is unreliable  #2341

}

@Test
public void testHasDifferentSlotsAs() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is OK, but it tests something different than what is explained in #2341

In #2341 the problems is that one part of the logic uses RedisClusterNode(RedisURI uri, String nodeId, boolean connected, String slaveOf, long pingSentTimestamp, long pongReceivedTimestamp, long configEpoch, BitSet slots, Set<NodeFlag> flags) to create a RedisClusterNode, while another uses the public RedisClusterNode(RedisClusterNode redisClusterNode) constructor. Both are provided an empty BitSet.

When later on both resulting objects are compared with .hasSameSlotsAs() it would return false, when it should return true, because the first object would have an empty slots BitSet, while the second would have a null slots BitSet.

I think the proper test scenario is :

public void testHasDifferentSlotsAs() {
        BitSet emptySlots = new BitSet(SlotHash.SLOT_COUNT);

        RedisClusterNode node1 = new RedisClusterNode(RedisURI.create("localhost", 6379), "nodeId1", true, "slaveOf", 0L, 0L,
                0L, emptySlots, new HashSet<>());
        RedisClusterNode node2 = new RedisClusterNode(node1);

        assertThat(node1.hasSameSlotsAs(node2)).isTrue();

You can test if this case fails when you remove your changes to RedisClusterNode.java

Copy link
Author

Choose a reason for hiding this comment

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

I missed the part where we need to compare the original cluster node with the cloned object. Thanks for the feedback!

Copy link
Author

@zeze1004 zeze1004 Jun 14, 2024

Choose a reason for hiding this comment

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

I made the changes based on your feedback. Can you please take a look? 🙏🏻

@mp911de
Copy link
Collaborator

mp911de commented Jun 6, 2024

Generally, we attempt to be as light-weight as possible. RedisClusterNode.slots is designed to be null so it would make sense to update both, the constructor of RedisClusterNode to expect a null slots argument and update ClusterPartitionParser to return a null slots bitset if the slotStrings would result in an empty slot specification (by also considering TOKEN_SLOT_IN_TRANSITION filtering, slotStrings.isEmpty() isn't sufficient).

Going forward, the parser for CLUSTER SHARDS in ClusterPartitionParser should be revisited as well to mimic the same behavior.

@tishun tishun added the type: bug A general bug label Jun 6, 2024
@tishun tishun added this to the 7.x milestone Jun 6, 2024
@tishun
Copy link
Collaborator

tishun commented Jun 7, 2024

Generally, we attempt to be as light-weight as possible. RedisClusterNode.slots is designed to be null so it would make sense to update both, the constructor of RedisClusterNode to expect a null slots argument and update ClusterPartitionParser to return a null slots bitset if the slotStrings would result in an empty slot specification (by also considering TOKEN_SLOT_IN_TRANSITION filtering, slotStrings.isEmpty() isn't sufficient).

Going forward, the parser for CLUSTER SHARDS in ClusterPartitionParser should be revisited as well to mimic the same behavior.

Not a huge fan of using null myself as I tend to agree that this is the billion dollar mistake.

Perhaps a compromise solution would be a new BitSet(0) (Null object pattern)?
We could also make this object a singleton for improved memory consumption.

It would still be more than what null would take, but it would be insignificantly more. In the same time it would have the benefit of avoiding NPEs and not having to deal with null checks.

What's your take on that approach?

@mp911de
Copy link
Collaborator

mp911de commented Jun 7, 2024

Allocation of BitSet uses up a bit of memory and CPU, hence we resorted to null. If you want to follow the null object pattern, then introducing a Slots object (backed by BitSet in the implemented variant) would rather make sense.

@zeze1004
Copy link
Author

zeze1004 commented Jun 7, 2024

Hey everyone,

Creating a new Slots object to handle null slots sounds like a good idea.
However, I think using BitSet(0) when slots is null can also safely avoid NPEs.
Additionally, this approach would have less impact on the existing codebase compared to introducing a new Slots object.

That said, if most contributors, including @tishun, prefer creating the Slots object, I’m ready to make the changes accordingly.

Thanks for all the reviews and feedback!

@tishun
Copy link
Collaborator

tishun commented Jun 7, 2024

Allocation of BitSet uses up a bit of memory and CPU, hence we resorted to null. If you want to follow the null object pattern, then introducing a Slots object (backed by BitSet in the implemented variant) would rather make sense.

The memory allocated (retained size) for a singleton BitSet with size 0 is 40B total (24B of which is shallow size). For a singleton BitSet the CPU overhead would be only once per creation. IMO these are negligible and indistinguishable from using null for any modern hardware and JVM.

I was going to propose to create a dedicated object myself, but would that affect the public API?

My recommendation would be to go with the null object, but I will approve any solution that resolves the problem without introducing new problems itself.

@zeze1004
Copy link
Author

zeze1004 commented Jun 14, 2024

I acknowledge the necessity of creating a separate Slots object. However, modifying the constructor of RedisClusterNode to include this new Slots class would require changes to all existing code that uses this constructor. This makes the scope of such a change too broad for this PR.

For this PR, I suggest we focus on the current approach of using BitSet with null checks. Implementing the Slots class could be considered in future updates through a gradual approach.
I will make the changes as reviewed by @tishun as soon as possible.

Hey thanks for addressing the last comments.
There are still two things that I am worried about:
We are still missing the same logic on line 90 (the first of the three constructors)
The test is not really verifying the issue from RedisClusterNode.hasSameSlotsAs() is unreliable #2341

As English is not my first language, I would appreciate it if you could confirm whether I have correctly understood your opinions. Thank you.

…nstructor and compare the two clusters with hasSameSlotsAs()
@zeze1004
Copy link
Author

I confirmed that my pull request failed during the integration tests. It seems like the failure is related to HashCommandIntegrationTests, which doesn’t seem to be directly connected to the changes I made. However, if there is an issue with my code, please let me know and I’ll fix it right away. cc. @tishun 🙇🏻

@tishun
Copy link
Collaborator

tishun commented Jun 20, 2024

I confirmed that my pull request failed during the integration tests. It seems like the failure is related to HashCommandIntegrationTests, which doesn’t seem to be directly connected to the changes I made. However, if there is an issue with my code, please let me know and I’ll fix it right away. cc. @tishun 🙇🏻

There was a change in the redis/redis codebase that broke the tests, it has been since fixed.
I've started the pipeline again.

@tishun
Copy link
Collaborator

tishun commented Jun 23, 2024

There was a change in the redis/redis codebase that broke the tests, it has been since fixed. I've started the pipeline again.

Actually - my bad - you will have to rebase your change to include the fix. Sorry about that.

See #2871

dengliming and others added 5 commits June 23, 2024 22:46
* Add support CLIENT KILL [MAXAGE]

* polish

* address review changes

* format code
* Add support for `SUNSUBSCRIBE` redis#2759

* replace junit.Assert with assertj
)

* Fixes to the hash field expiration functions

* Implemented HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL, HPTTL

* Format the files

* FIELDS keyword was introduced as per the PRD

* Extend tests to include HTTL

* Repair unit tests, add new ones for the new commands

* Disable failing test, becasue it is very unstable

* Modify return value to list of long values, fix cluster logic

* Polishing

* Polishing - addressed Ali's comments

* Polishing: Modified by mistake

* Polishing : Addressed Marks' comments
* Add last() utility method to the XArgs.StreamOffset

* Submitted one more file by mistake
BalmungSan and others added 12 commits June 23, 2024 22:46
…edis#2868)

* Add a evalReadOnly overload that accepts the script as a String

* Fix @SInCE annotation for 7.0
* Release-drafter, dependabot, OCD polishing

* Commitish not needed and pointing to the wrong branch anyway, also wrong version chosen

* Pipeline is also very confusing as there are many pipelines, this is the INTEGRATION pipeline

* Adding commitish, as it is required for filter-by-commitish

* Autolabeling hits issues when using pull_request, using pull_request_target instead

* pull_request_target does nothing, trying the other suggestion from release-drafter/release-drafter#1125
redis#2873)

Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…s#2874)

Bumps [org.codehaus.mojo:flatten-maven-plugin](https://github.com/mojohaus/flatten-maven-plugin) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/mojohaus/flatten-maven-plugin/releases)
- [Commits](mojohaus/flatten-maven-plugin@1.5.0...1.6.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:flatten-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…edis#2875)

Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.3.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-jar-plugin/releases)
- [Commits](apache/maven-jar-plugin@maven-jar-plugin-3.3.0...maven-jar-plugin-3.4.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-jar-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…s#2876)

Bumps [org.openjdk.jmh:jmh-generator-annprocess](https://github.com/openjdk/jmh) from 1.21 to 1.37.
- [Commits](openjdk/jmh@1.21...1.37)

---
updated-dependencies:
- dependency-name: org.openjdk.jmh:jmh-generator-annprocess
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps org.apache.commons:commons-pool2 from 2.11.1 to 2.12.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-pool2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Bump version of lettuce-core to 6.4.0

* Change all @SInCE notations to match the next release 6.4.x and also fixed two typos in the API JavaDoc

* Fixed formatting issues
…edis#2899)

* Server addressed the issues of empty list returned for missing keys

* Refresh the template to include isntrustion how to format the code
* Remove not readonly commands redis#2832

* Fix comment

Add test

* Update test

* Update cicd.yaml

workaround for apt update issue related to Clearsigned file

* GitHub issue template polishing and stale issues action (redis#2833)

* GitHub issue template polishing and stale issues action

* Addressing feedback on message test and a better label for the stale issues

* Implement HEXPIRE, HEXPIREAT, HEXPIRETIME and HPERSIST (redis#2836)

* HEXPIRE implemented with integration tests

* Polishing to integration test, added unit test

* Move new commands to RedisHashCommands, added HEXPIREAT, HEXPIRETIME and HPERSIST

* Make sure we reset the configuration setting after the new hash commands were tested

* Broke one test because of wrong configuration setting; the other is unstable, trying to fix it

* Polishing imports

* Polishin : Copyright change not needed

* MAke sure we wait for the check so it does not fail on the slower pipeline (redis#2844)

* Add support for `SPUBLISH` (redis#2838)

* implementation of SPUBLISH

* sort methods by name

* test cluster spublish with no redirects

* use injected cluster client in RedisClusterPubSubConnectionIntegrationTests

* Applying code formatter each time we run a Maven build (redis#2841)

* Let's try this again

* Add tests and templates

* Merge formatting issues + formatter using wrong configuration

* Update cicd.yaml

the issue related apt repo has been fixed 
https://github.com/orgs/community/discussions/120966#discussioncomment-9211925

* Add support CLIENT KILL [MAXAGE] (redis#2782)

* Add support CLIENT KILL [MAXAGE]

* polish

* address review changes

* format code

* Add support for `SUNSUBSCRIBE` redis#2759 (redis#2851)

* Add support for `SUNSUBSCRIBE` redis#2759

* replace junit.Assert with assertj

* Mark dnsResolver(DnsResolver) as deprecated. (redis#2855)

* Implement HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL and HPTTL (redis#2857)

* Fixes to the hash field expiration functions

* Implemented HPEXPIRE, HPEXPIREAT, HPEXPIRETIME, HTTL, HPTTL

* Format the files

* FIELDS keyword was introduced as per the PRD

* Extend tests to include HTTL

* Repair unit tests, add new ones for the new commands

* Disable failing test, becasue it is very unstable

* Modify return value to list of long values, fix cluster logic

* Polishing

* Polishing - addressed Ali's comments

* Polishing: Modified by mistake

* Polishing : Addressed Marks' comments

* XREAD support for reading last message from stream (redis#2863)

* Add last() utility method to the XArgs.StreamOffset

* Submitted one more file by mistake

* Add a `evalReadOnly` overload that accepts the script as a `String` (redis#2868)

* Add a evalReadOnly overload that accepts the script as a String

* Fix @SInCE annotation for 7.0

* Add release drafter workflow (redis#2820)

* Release-drafter, dependabot, OCD polishing

* Commitish not needed and pointing to the wrong branch anyway, also wrong version chosen

* Pipeline is also very confusing as there are many pipelines, this is the INTEGRATION pipeline

* Adding commitish, as it is required for filter-by-commitish

* Autolabeling hits issues when using pull_request, using pull_request_target instead

* pull_request_target does nothing, trying the other suggestion from release-drafter/release-drafter#1125

* Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0 (redis#2873)

Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.codehaus.mojo:flatten-maven-plugin from 1.5.0 to 1.6.0 (redis#2874)

Bumps [org.codehaus.mojo:flatten-maven-plugin](https://github.com/mojohaus/flatten-maven-plugin) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/mojohaus/flatten-maven-plugin/releases)
- [Commits](mojohaus/flatten-maven-plugin@1.5.0...1.6.0)

---
updated-dependencies:
- dependency-name: org.codehaus.mojo:flatten-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.apache.maven.plugins:maven-jar-plugin from 3.3.0 to 3.4.1 (redis#2875)

Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.3.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-jar-plugin/releases)
- [Commits](apache/maven-jar-plugin@maven-jar-plugin-3.3.0...maven-jar-plugin-3.4.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-jar-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.openjdk.jmh:jmh-generator-annprocess from 1.21 to 1.37 (redis#2876)

Bumps [org.openjdk.jmh:jmh-generator-annprocess](https://github.com/openjdk/jmh) from 1.21 to 1.37.
- [Commits](openjdk/jmh@1.21...1.37)

---
updated-dependencies:
- dependency-name: org.openjdk.jmh:jmh-generator-annprocess
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump org.apache.commons:commons-pool2 from 2.11.1 to 2.12.0 (redis#2877)

Bumps org.apache.commons:commons-pool2 from 2.11.1 to 2.12.0.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-pool2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Setting the next release to be 6.4.x as part of redis#2880 (redis#2881)

* Bump version of lettuce-core to 6.4.0

* Change all @SInCE notations to match the next release 6.4.x and also fixed two typos in the API JavaDoc

* Fixed formatting issues

* Modify the release acrtion to call the proper maven target for release, make releasing manually available too (redis#2885)

* Format file

* Using interface method from java 8 instead of java 9

* Fix test

* Revert readwrite command to the list

COMMAND INFO READWRITE
1) 1) "readwrite"
   2) "1"
   3) 1) "loading"
      2) "stale"
      3) "fast"

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: atakavci <[email protected]>
Co-authored-by: Tihomir Krasimirov Mateev <[email protected]>
Co-authored-by: Liming Deng <[email protected]>
Co-authored-by: Wang Zhi <[email protected]>
Co-authored-by: Luis Miguel Mejía Suárez <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Updated release notes (redis#2882)

* Updated release notes

* Polishing

* Spellsheck fixes

* Modify the release acrtion to call the proper maven target for release, make releasing manually available too (redis#2885) (redis#2893)

* Added the nexus staging plugin

* Make version step conditional on the availability of a tag name in the event

* Missed the GPG configuration
@zeze1004
Copy link
Author

There was a change in the redis/redis codebase that broke the tests, it has been since fixed. I've started the pipeline again.

Actually - my bad - you will have to rebase your change to include the fix. Sorry about that.
See #2871

Thanks @tishun, I completed the rebase based on the PR you mentioned.

@zeze1004 zeze1004 requested a review from tishun June 23, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants