-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Fix the broker registery cannot recover from the metadata node deletion #23359
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
Merged
BewareMyPower
merged 11 commits into
apache:master
from
BewareMyPower:bewaremypower/broker-registry-session-timeout
Sep 27, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8518e8
Add test framework
BewareMyPower c05ed36
Recreate the node if it's deleted
BewareMyPower 678ba31
Replace inmemory metadata store and mocked storage with ZK and BK
BewareMyPower 4e8078d
Move the test under the loadbalance package
BewareMyPower b562934
Add more test for register again
BewareMyPower b7fb4af
Move the registerAsync to handleBrokerRegistrationEvent
BewareMyPower 78448f5
Add comments for why to register again
BewareMyPower 34b7f7e
Move registerAsync into the BrokerRegistryImpl
BewareMyPower a220390
Fix flakiness of BrokerRegistryIntegrationTest
BewareMyPower ef0a8eb
Fix flakiness of BrokerRegistryIntegrationTest
BewareMyPower 5c720d8
Fix failed BrokerRegistryTest
BewareMyPower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...t/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.pulsar.broker.loadbalance.extensions; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.bookkeeper.util.PortManager; | ||
| import org.apache.pulsar.broker.PulsarService; | ||
| import org.apache.pulsar.broker.ServiceConfiguration; | ||
| import org.apache.pulsar.broker.loadbalance.LoadManager; | ||
| import org.apache.pulsar.common.policies.data.ClusterData; | ||
| import org.apache.pulsar.common.policies.data.TenantInfo; | ||
| import org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble; | ||
| import org.awaitility.Awaitility; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.AfterClass; | ||
| import org.testng.annotations.BeforeClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| @Slf4j | ||
| @Test(groups = "broker") | ||
| public class BrokerRegistryIntegrationTest { | ||
|
|
||
| private static final String clusterName = "test"; | ||
| private final int zkPort = PortManager.nextFreePort(); | ||
| private final LocalBookkeeperEnsemble bk = new LocalBookkeeperEnsemble(2, zkPort, PortManager::nextFreePort); | ||
| private PulsarService pulsar; | ||
| private BrokerRegistry brokerRegistry; | ||
| private String brokerMetadataPath; | ||
|
|
||
| @BeforeClass | ||
| protected void setup() throws Exception { | ||
| bk.start(); | ||
| pulsar = new PulsarService(brokerConfig()); | ||
| pulsar.start(); | ||
| final var admin = pulsar.getAdminClient(); | ||
| admin.clusters().createCluster(clusterName, ClusterData.builder().build()); | ||
| admin.tenants().createTenant("public", TenantInfo.builder() | ||
| .allowedClusters(Collections.singleton(clusterName)).build()); | ||
| admin.namespaces().createNamespace("public/default"); | ||
| brokerRegistry = ((ExtensibleLoadManagerWrapper) pulsar.getLoadManager().get()).get().getBrokerRegistry(); | ||
| brokerMetadataPath = LoadManager.LOADBALANCE_BROKERS_ROOT + "/" + pulsar.getBrokerId(); | ||
| } | ||
|
|
||
| @AfterClass(alwaysRun = true) | ||
| protected void cleanup() throws Exception { | ||
| if (pulsar != null) { | ||
| pulsar.close(); | ||
| } | ||
| bk.stop(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRecoverFromNodeDeletion() throws Exception { | ||
| // Simulate the case that the node was somehow deleted (e.g. by session timeout) | ||
| Awaitility.await().atMost(Duration.ofSeconds(3)).untilAsserted(() -> Assert.assertEquals( | ||
| brokerRegistry.getAvailableBrokersAsync().join(), List.of(pulsar.getBrokerId()))); | ||
| pulsar.getLocalMetadataStore().delete(brokerMetadataPath, Optional.empty()); | ||
| Awaitility.await().atMost(Duration.ofSeconds(3)).untilAsserted(() -> Assert.assertEquals( | ||
| brokerRegistry.getAvailableBrokersAsync().join(), List.of(pulsar.getBrokerId()))); | ||
|
|
||
| // If the node is deleted by unregister(), it should not recreate the path | ||
| brokerRegistry.unregister(); | ||
| Thread.sleep(3000); | ||
| Assert.assertTrue(brokerRegistry.getAvailableBrokersAsync().get().isEmpty()); | ||
|
|
||
| // Restore the normal state | ||
| brokerRegistry.registerAsync().get(); | ||
| Assert.assertEquals(brokerRegistry.getAvailableBrokersAsync().get(), List.of(pulsar.getBrokerId())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterAgain() throws Exception { | ||
| Awaitility.await().atMost(Duration.ofSeconds(3)).untilAsserted(() -> Assert.assertEquals( | ||
| brokerRegistry.getAvailableBrokersAsync().join(), List.of(pulsar.getBrokerId()))); | ||
| final var metadataStore = pulsar.getLocalMetadataStore(); | ||
| final var oldResult = metadataStore.get(brokerMetadataPath).get().orElseThrow(); | ||
| log.info("Old result: {} {}", new String(oldResult.getValue()), oldResult.getStat().getVersion()); | ||
| brokerRegistry.registerAsync().get(); | ||
|
|
||
| Awaitility.await().atMost(Duration.ofSeconds(3)).untilAsserted(() -> { | ||
| final var newResult = metadataStore.get(brokerMetadataPath).get().orElseThrow(); | ||
| log.info("New result: {} {}", new String(newResult.getValue()), newResult.getStat().getVersion()); | ||
| Assert.assertTrue(newResult.getStat().getVersion() > oldResult.getStat().getVersion()); | ||
| Assert.assertEquals(newResult.getValue(), oldResult.getValue()); | ||
| }); | ||
| } | ||
|
|
||
| private ServiceConfiguration brokerConfig() { | ||
| final var config = new ServiceConfiguration(); | ||
| config.setClusterName(clusterName); | ||
| config.setAdvertisedAddress("localhost"); | ||
| config.setBrokerServicePort(Optional.of(0)); | ||
| config.setWebServicePort(Optional.of(0)); | ||
| config.setMetadataStoreUrl("zk:127.0.0.1:" + bk.getZookeeperPort()); | ||
| config.setManagedLedgerDefaultWriteQuorum(1); | ||
| config.setManagedLedgerDefaultAckQuorum(1); | ||
| config.setManagedLedgerDefaultEnsembleSize(1); | ||
| config.setDefaultNumberOfNamespaceBundles(16); | ||
| config.setLoadManagerClassName(ExtensibleLoadManagerImpl.class.getName()); | ||
| config.setLoadBalancerDebugModeEnabled(true); | ||
| config.setBrokerShutdownTimeoutMs(100); | ||
| return config; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.