ResourceGroupConfigListener and ResourceGroupNamespaceConfigListener has an cocurrent bug at startrup #15113
Description
Describe the bug
A clear and concise description of what the bug is.
public ResourceGroupConfigListener(ResourceGroupService rgService, PulsarService pulsarService) {
this.rgService = rgService;
this.pulsarService = pulsarService;
this.rgResources = pulsarService.getPulsarResources().getResourcegroupResources();
loadAllResourceGroups(); // THIS IS ASYNC 1
this.rgResources.getStore().registerListener(this);
rgNamespaceConfigListener = new ResourceGroupNamespaceConfigListener(
rgService, pulsarService, this);
}
loadAllResourceGroups(); // THIS IS ASYNC 1
add invoke
resourceGroupsMap.put(rgName, rg);
public ResourceGroupNamespaceConfigListener(ResourceGroupService rgService, PulsarService pulsarService,
ResourceGroupConfigListener rgConfigListener) {
this.rgService = rgService;
this.pulsarService = pulsarService;
this.namespaceResources = pulsarService.getPulsarResources().getNamespaceResources();
this.tenantResources = pulsarService.getPulsarResources().getTenantResources();
this.rgConfigListener = rgConfigListener;
loadAllNamespaceResourceGroups(); // THIS IS ASYNC 2
this.namespaceResources.getStore().registerListener(this);
}
loadAllNamespaceResourceGroups(); // THIS IS ASYNC 2
will invoke
rgService.registerNameSpace(policy.resource_group_name, ns);
then
private ResourceGroup checkResourceGroupExists(String rgName) throws PulsarAdminException {
ResourceGroup rg = this.getResourceGroupInternal(rgName);
if (rg == null) {
throw new PulsarAdminException("Resource group does not exist: " + rgName);
}
return rg;
}
inside
/**
* Get the RG with the given name. For internal operations only.
*/
private ResourceGroup getResourceGroupInternal(String resourceGroupName) {
if (resourceGroupName == null) {
throw new IllegalArgumentException("Invalid null resource group name: " + resourceGroupName);
}
return resourceGroupsMap.get(resourceGroupName);
}
if 2 run earlier than 1, it will occur error, if no namespace add/delete, it won't recover.
To Reproduce
review the code
Expected behavior
A clear and concise description of what you expected to happen.
maybe we need loadAllResourceGroups sync, or when it done, then loadAllNamespaceResourceGroups
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
Additional context
Add any other context about the problem here.
master branch