Skip to content

Commit

Permalink
[#1280] config-center firstpull config support retry 3 times (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling authored Jun 20, 2024
1 parent 57e60be commit 69f2713
Showing 1 changed file with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
ConfigCenterClient configCenterClient = new ConfigCenterClient(addressManager, httpTransport);

queryConfigurationsRequest = createQueryConfigurationsRequest(bootstrapProperties);
QueryConfigurationsResponse response = configCenterClient
.queryConfigurations(queryConfigurationsRequest, addressManager.address());
if (response.isChanged()) {
configConverter.updateData(response.getConfigurations());
}
queryConfigurationsRequest.setRevision(response.getRevision());
firstPull(bootstrapProperties.getConfigBootstrapProperties(), configCenterClient, queryConfigurationsRequest,
addressManager);
ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration(
bootstrapProperties.getConfigBootstrapProperties());
ConfigCenterManager configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(),
Expand All @@ -168,6 +164,43 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
configCenterManager.startConfigCenterManager();
}

public void firstPull(ConfigBootstrapProperties configProperties, ConfigCenterClient configCenterClient,
QueryConfigurationsRequest queryConfigurationsRequest, ConfigCenterAddressManager addressManager) {
try {
firstQueryConfigurations(configCenterClient, queryConfigurationsRequest, addressManager);
} catch (Exception e) {
if (configProperties.isFirstPullRequired()) {
throw e;
} else {
LOGGER.warn("first pull failed!");
}
}
}

private void firstQueryConfigurations(ConfigCenterClient configCenterClient, QueryConfigurationsRequest queryConfigurationsRequest,
ConfigCenterAddressManager addressManager) {
int index = 0;
while (index < 3) {
String address = addressManager.address();
try {
QueryConfigurationsResponse response = configCenterClient.queryConfigurations(queryConfigurationsRequest,
address);
if (response.isChanged()) {
configConverter.updateData(response.getConfigurations());
}
queryConfigurationsRequest.setRevision(response.getRevision());
break;
} catch (Exception e) {
if (index == 2) {
throw e;
}
LOGGER.warn("config-center firstQueryConfigurations failed, config address {} and ignore {}", address,
e.getMessage());
}
index++;
}
}

private ConfigCenterConfiguration createConfigCenterConfiguration(ConfigBootstrapProperties configProperties) {
ConfigCenterConfiguration configCenterConfiguration = new ConfigCenterConfiguration();
configCenterConfiguration.setRefreshIntervalInMillis(configProperties.getConfigCenter().getRefreshInterval());
Expand Down

0 comments on commit 69f2713

Please sign in to comment.