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

ResourceGroupConfigListener and ResourceGroupNamespaceConfigListener has an cocurrent bug at startrup #15113

Open
leizhiyuan opened this issue Apr 11, 2022 · 2 comments
Assignees
Labels
lifecycle/stale Stale type/bug The PR fixed a bug or issue reported a bug

Comments

@leizhiyuan
Copy link
Contributor

leizhiyuan commented Apr 11, 2022

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

@github-actions
Copy link

The issue had no activity for 30 days, mark with Stale label.

@github-actions
Copy link

The issue had no activity for 30 days, mark with Stale label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Stale type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant