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

[fix][broker] Fix Replicated Topic unload bug when ExtensibleLoadManager is enabled #22496

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,11 @@ public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle,
}

public CompletableFuture<Boolean> isNamespaceBundleOwned(NamespaceBundle bundle) {
if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(pulsar)) {
ExtensibleLoadManagerImpl extensibleLoadManager = ExtensibleLoadManagerImpl.get(loadManager.get());
return extensibleLoadManager.getOwnershipAsync(Optional.empty(), bundle)
.thenApply(Optional::isPresent);
}
return pulsar.getLocalMetadataStore().exists(ServiceUnitUtils.path(bundle));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ public CompletableFuture<Void> stopReplProducers() {
@Override
public CompletableFuture<Void> checkReplication() {
TopicName name = TopicName.get(topic);
if (!name.isGlobal() || NamespaceService.isHeartbeatNamespace(name)) {
if (!name.isGlobal() || NamespaceService.isHeartbeatNamespace(name)
|| ExtensibleLoadManagerImpl.isInternalTopic(topic)) {
return CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,8 @@ CompletableFuture<Void> checkPersistencePolicies() {
@Override
public CompletableFuture<Void> checkReplication() {
TopicName name = TopicName.get(topic);
if (!name.isGlobal() || NamespaceService.isHeartbeatNamespace(name)) {
if (!name.isGlobal() || NamespaceService.isHeartbeatNamespace(name)
|| ExtensibleLoadManagerImpl.isInternalTopic(topic)) {
return CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.common.collect.Sets;
import lombok.Cleanup;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl;
import org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl;
import org.apache.pulsar.client.api.MessageRoutingMode;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.impl.ConsumerImpl;
Expand All @@ -32,6 +34,8 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;

import java.lang.reflect.Method;
Expand All @@ -41,6 +45,18 @@
public class ReplicatorGlobalNSTest extends ReplicatorTestBase {

protected String methodName;
@DataProvider(name = "loadManagerClassName")
public static Object[][] loadManagerClassName() {
return new Object[][]{
{ModularLoadManagerImpl.class.getName()},
{ExtensibleLoadManagerImpl.class.getName()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heesung-sn I think that this is triggering a problem in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. We can comment out this line if this is problematic.

};
}

@Factory(dataProvider = "loadManagerClassName")
public ReplicatorGlobalNSTest(String loadManagerClassName) {
this.loadManagerClassName = loadManagerClassName;
}

@BeforeMethod
public void beforeMethod(Method m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public abstract class ReplicatorTestBase extends TestRetrySupport {
protected final String cluster2 = "r2";
protected final String cluster3 = "r3";
protected final String cluster4 = "r4";
protected String loadManagerClassName;

protected String getLoadManagerClassName() {
return loadManagerClassName;
}

// Default frequency
public int getBrokerServicePurgeInactiveFrequency() {
Expand Down Expand Up @@ -271,8 +276,9 @@ protected void setup() throws Exception {
.brokerClientTlsTrustStoreType(keyStoreType)
.build());

admin1.tenants().createTenant("pulsar",
new TenantInfoImpl(Sets.newHashSet("appid1", "appid2", "appid3"), Sets.newHashSet("r1", "r2", "r3")));
updateTenantInfo("pulsar",
new TenantInfoImpl(Sets.newHashSet("appid1", "appid2", "appid3"),
Sets.newHashSet("r1", "r2", "r3")));
admin1.namespaces().createNamespace("pulsar/ns", Sets.newHashSet("r1", "r2", "r3"));
admin1.namespaces().createNamespace("pulsar/ns1", Sets.newHashSet("r1", "r2"));

Expand Down Expand Up @@ -344,6 +350,7 @@ private void setConfigDefaults(ServiceConfiguration config, String clusterName,
config.setAllowAutoTopicCreationType(TopicType.NON_PARTITIONED);
config.setEnableReplicatedSubscriptions(true);
config.setReplicatedSubscriptionsSnapshotFrequencyMillis(1000);
config.setLoadManagerClassName(getLoadManagerClassName());
}

public void resetConfig1() {
Expand Down Expand Up @@ -409,6 +416,14 @@ protected void cleanup() throws Exception {
resetConfig4();
}

protected void updateTenantInfo(String tenant, TenantInfoImpl tenantInfo) throws Exception {
if (!admin1.tenants().getTenants().contains(tenant)) {
admin1.tenants().createTenant(tenant, tenantInfo);
} else {
admin1.tenants().updateTenant(tenant, tenantInfo);
}
}

static class MessageProducer implements AutoCloseable {
URL url;
String namespace;
Expand Down
Loading