Skip to content

Fix Reload topology only when changes occur (#2299) #3256

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

Closed
wants to merge 7 commits into from

Conversation

YoHanKi
Copy link

@YoHanKi YoHanKi commented Apr 11, 2025

Summary

This pull request addresses issue #2299. In the previous implementation, the reload() method was called even when no actual change occurred in the topology, which resulted in frequent invocations of updateCache() and unnecessary object allocations (such as new slotCache arrays). This fix ensures that reload() is executed only when a genuine topology change is detected via TopologyComparators.isChanged().

Changes

Conditional Reload:

Modified the logic in refreshPartitionsAsync() so that reload() (and consequently updateCache()) is only invoked when a change in the topology is observed.

Test Enhancements:

Added tests to compare scenarios:

  • When there is no topology change, the test verifies that reload is not triggered (i.e., updateCache is not called, and the update count remains 0).

  • When a simulated topology change occurs, the test confirms that reload is invoked at least once.

All cluster-related tests have been executed, and the results are as expected.

Testing

The tests leverage reflection to track the slotCache field changes in the Partitions class.

The objective is to ensure that:

  • In the absence of topology changes, no unnecessary reloads occur.

  • When a topology change is simulated, reload() correctly triggers a new allocation for the slotCache.

If additional tests or modifications are needed, I am happy to incorporate further refinements based on your feedback.

Final Notes

Thank you for reviewing this PR. I appreciate your consideration and any further suggestions for improvement.

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 applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

YoHanKi added 3 commits April 12, 2025 00:06
- reload() (and updateCache) was always called even if the topology was unchanged,
leading to unnecessary object allocations. Now, reload happens only when a genuine change is detected.
- Removed unnecessary Delay in tests.
- Added a reload condition so that explicit calls to refreshPartitions() always trigger a reload.
- Refactored refreshPartitionsAsync() to use method overloading to clearly separate explicit reload behavior from periodic refresh.
@YoHanKi
Copy link
Author

YoHanKi commented Apr 15, 2025

Hello, I have some questions regarding this change.

Previously, a reload was only triggered when isChanged() returned true, so explicit calls to refreshPartitions() did not perform a reload. To address this, I modified the code using method overloading so that when refreshPartitions() is called explicitly, a reload always occurs.

Could you please confirm whether this approach is acceptable? If there are any concerns with this implementation or if it doesn't align with the Lettuce team's direction, I'll be happy to re-evaluate the approach.

Thank you.

@YoHanKi YoHanKi closed this May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants