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

avoid dup refresh for registry config #3135

Merged
merged 4 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ protected void checkMetadataReport() {
*/
protected List<URL> loadRegistries(boolean provider) {
// check && override if necessary
checkRegistry();
List<URL> registryList = new ArrayList<URL>();
if (registries != null && !registries.isEmpty()) {
for (RegistryConfig config : registries) {
Expand Down Expand Up @@ -469,7 +468,7 @@ private void convertRegistryIdsToRegistries() {
if (StringUtils.isEmpty(registryIds)) {
if (registries == null || registries.isEmpty()) {
registries = new ArrayList<>();
registries.add(new RegistryConfig());
registries.add(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
}
} else {
String[] arr = Constants.COMMA_SPLIT_PATTERN.split(registryIds);
Expand All @@ -478,7 +477,7 @@ private void convertRegistryIdsToRegistries() {
}
Arrays.stream(arr).forEach(id -> {
if (registries.stream().noneMatch(reg -> reg.getId().equals(id))) {
RegistryConfig registryConfig = new RegistryConfig();
RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can give RegistryConfig a default value RegistryConfig.NO_AVAILABLE, instead we should leave it empty. We will try to refresh this RegistryConfig later, if the user fails to set the right item for RegistryConfig, it will receive an Exception then when checking isValid. But if we give it this default value, it will always pass isValid and does register URL to Registry Center which can be unexpected behaviour.

registryConfig.setId(id);
registries.add(registryConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void checkAndUpdateSubConfigs() {
inheritIfAbsentFromApplication();
}
checkApplication();
checkRegistry();
checkMetadataReport();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public void checkApplication2() throws Exception {
public void testLoadRegistries() throws Exception {
System.setProperty("dubbo.registry.address", "addr1");
InterfaceConfig interfaceConfig = new InterfaceConfig();
// FIXME: now we need to check first, then load
interfaceConfig.checkRegistry();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should give loadRegistries another name that can better reflect what it does. It is misleading since it loads nothing except for converts RegistryConfigs to URLs.

List<URL> urls = interfaceConfig.loadRegistries(true);
TestCase.assertEquals(1, urls.size());
URL url = urls.get(0);
Expand Down