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

feat:RedisMetadataReport implementation #13303

Merged
merged 10 commits into from
Nov 15, 2023
Merged

feat:RedisMetadataReport implementation #13303

merged 10 commits into from
Nov 15, 2023

Conversation

Nortyr
Copy link
Contributor

@Nortyr Nortyr commented Nov 3, 2023

What is the purpose of the change

Fixes#12627,Implement the other functionalities in RedisMetadataReport.
previous pr link: #13238

Brief changelog

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Could you pls add some comment near these changes about its design?

@Nortyr
Copy link
Contributor Author

Nortyr commented Nov 5, 2023

  1. function: registerServiceAppMapping
    Store class and application names using Redis hashes
image
  1. function: storeMappingStandalone
    In the first version, I used a Lua script to implement cas .
    use command watch advice from @Linchen-Xu
    image
    I also think that using the 'watch' command is good because it starts from version 2.2, Lua starts from version 2.6.

  2. function: storeMappingInCluster
    Inspired by the link: https://groups.google.com/g/jedis_redis/c/Z4-0065UFkg

  3. function: getServiceAppMapping(String serviceKey, MappingListener listener, URL url)
    start one thread to subscribe dubbo:mapping:queues Whenever any server changes occur, it will publish serviceKey,then RedisMetadataReport.NotifySub#onMessage will retrieve the application names again.

  4. function: removeServiceAppMappingListener
    if have no listener,thread will dead

  5. class: MappingDataListener
    subscribe application names change message

  6. class: NotifySub
    listen application names change message and notify listener

@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2023

Codecov Report

Merging #13303 (b66d6a7) into 3.3 (e155591) will increase coverage by 0.00%.
Report is 14 commits behind head on 3.3.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              3.3   #13303     +/-   ##
=========================================
  Coverage   40.67%   40.67%             
=========================================
  Files        1804     1805      +1     
  Lines       72861    75755   +2894     
  Branches    10428    10621    +193     
=========================================
+ Hits        29637    30815   +1178     
- Misses      38962    40625   +1663     
- Partials     4262     4315     +53     

see 1321 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@Nortyr Nortyr requested a review from AlbumenJ November 8, 2023 08:26
# Conflicts:
#	dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
#	dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
@@ -209,4 +228,266 @@ private String getMetadataStandalone(BaseMetadataIdentifier metadataIdentifier)
throw new RpcException(msg, e);
}
}

@Override
public boolean registerServiceAppMapping(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Store class and application names using Redis hashes
key: dubbo:mapping
field: class
value: application_names

return false;
}

private boolean storeMappingStandalone(String key, String field, String value, String ticket) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use 'watch' to implement cas

}
}

private boolean storeMappingInCluster(String key, String field, String value, String ticket) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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


@Override
public Set<String> getServiceAppMapping(String serviceKey, MappingListener listener, URL url) {
MappingDataListener mappingDataListener =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

start one thread to subscribe dubbo:mapping:queues Whenever any server changes occur, it will publish serviceKey,then RedisMetadataReport.NotifySub#onMessage will retrieve the application names again.

}
}

class MappingDataListener extends Thread {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

subscribe application names change message

return mappingDataListenerMap.get(buildPubSubKey());
}

class NotifySub extends JedisPubSub {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

listen application names change message and notify listener

@Nortyr
Copy link
Contributor Author

Nortyr commented Nov 12, 2023

@AlbumenJ PTAL

@AlbumenJ
Copy link
Member

@Nortyr Add them in the code :)

@Nortyr
Copy link
Contributor Author

Nortyr commented Nov 14, 2023

@AlbumenJ i have add notes ,PTAL

Copy link

sonarcloud bot commented Nov 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 8 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@AlbumenJ AlbumenJ merged commit 39611ea into apache:3.3 Nov 15, 2023
13 of 14 checks passed
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.

None yet

3 participants