Skip to content

Commit

Permalink
[Broker] Fix create the dynamic configuration resource if not exist
Browse files Browse the repository at this point in the history
### Motivation

When request the `DELETE: /admin/brokers/configuration/dispatcherMinReadBatchSize`, which return the`org.apache.pulsar.metadata.api.MetadataStoreException$NotFoundException`. The Pulsar does not create the dynamic configuration resource if it does not exist, this is incorrect behavior.

### Modifications

- Add check dynamic configuration resource on `updateDynamicServiceConfiguration()`

### Documentation

Need to update docs?

- [x] `no-need-doc`

Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
nodece committed Dec 21, 2021
1 parent cfa26b5 commit f18e814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CompletableFuture<Optional<Map<String, String>>> getDynamicConfigurationA
}

public Map<String, String> getDynamicConfiguration() throws MetadataStoreException {
return get(BROKER_SERVICE_CONFIGURATION_PATH).orElse(Collections.emptyMap());
return get(BROKER_SERVICE_CONFIGURATION_PATH).orElse(null);
}

public void setDynamicConfigurationWithCreate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2296,9 +2296,17 @@ private void validateConfigKey(String key) {
*/
private void updateDynamicServiceConfiguration() {
Optional<Map<String, String>> configCache = Optional.empty();

try {
configCache =
Optional.of(pulsar().getPulsarResources().getDynamicConfigResources().getDynamicConfiguration());
Map<String, String> dynamicConfiguration =
pulsar().getPulsarResources().getDynamicConfigResources().getDynamicConfiguration();
configCache = Optional.ofNullable(dynamicConfiguration);

// create dynamic-config if not exist.
if (dynamicConfiguration == null) {
pulsar().getPulsarResources().getDynamicConfigResources()
.setDynamicConfigurationWithCreate(n -> Maps.newHashMap());
}
} catch (Exception e) {
log.warn("Failed to read dynamic broker configuration", e);
}
Expand Down

0 comments on commit f18e814

Please sign in to comment.