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

[improve][broker] Should notify bundle ownership listener onLoad event when ServiceUnitState start (ExtensibleLoadManagerImpl only) #23152

Merged
Show file tree
Hide file tree
Changes from 4 commits
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 @@ -325,6 +325,16 @@ public synchronized void start() throws PulsarServerException {
ServiceUnitStateCompactionStrategy.class.getName()))
.create();
tableview.listen((key, value) -> handle(key, value));
tableview.forEach((serviceUnit, data) -> {
if (debug) {
log.info("Loaded the service unit state data. serviceUnit: {}, data: {}", serviceUnit, data);
}
ServiceUnitState state = state(data);
if (state.equals(Owned) && isTargetBroker(data.dstBroker())) {
pulsar.getNamespaceService()
.onNamespaceBundleOwned(LoadManagerShared.getNamespaceBundle(pulsar, serviceUnit));
}
});
heesung-sn marked this conversation as resolved.
Show resolved Hide resolved
var strategy = (ServiceUnitStateCompactionStrategy) TopicCompactionStrategy.getInstance(TABLE_VIEW_TAG);
if (strategy == null) {
String err = TABLE_VIEW_TAG + "tag TopicCompactionStrategy is null.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,56 @@ public boolean test(NamespaceBundle namespaceBundle) {
}
}

@Test(timeOut = 30 * 1000)
public void testNamespaceOwnershipListener() throws Exception {
Pair<TopicName, NamespaceBundle> topicAndBundle =
getBundleIsNotOwnByChangeEventTopic("test-namespace-ownership-listener");
TopicName topicName = topicAndBundle.getLeft();
NamespaceBundle bundle = topicAndBundle.getRight();

String broker = admin.lookups().lookupTopic(topicName.toString());
log.info("Assign the bundle {} to {}", bundle, broker);

checkOwnershipState(broker, bundle);

AtomicInteger onloadCount = new AtomicInteger(0);
AtomicInteger unloadCount = new AtomicInteger(0);

NamespaceBundleOwnershipListener listener = new NamespaceBundleOwnershipListener() {
@Override
public void onLoad(NamespaceBundle bundle) {
onloadCount.incrementAndGet();
}

@Override
public void unLoad(NamespaceBundle bundle) {
unloadCount.incrementAndGet();
}

@Override
public boolean test(NamespaceBundle namespaceBundle) {
return namespaceBundle.equals(bundle);
}
};
pulsar1.getNamespaceService().addNamespaceBundleOwnershipListener(listener);
pulsar2.getNamespaceService().addNamespaceBundleOwnershipListener(listener);

// There are a service unit state channel already started, when add listener, it will trigger the onload event.
Awaitility.await().untilAsserted(() -> {
assertEquals(onloadCount.get(), 1);
assertEquals(unloadCount.get(), 0);
});

ServiceUnitStateChannelImpl channel = new ServiceUnitStateChannelImpl(pulsar1);
channel.start();
Awaitility.await().untilAsserted(() -> {
assertEquals(onloadCount.get(), 2);
assertEquals(unloadCount.get(), 0);
});

channel.close();
}

@DataProvider(name = "isPersistentTopicSubscriptionTypeTest")
public Object[][] isPersistentTopicSubscriptionTypeTest() {
return new Object[][]{
Expand Down
Loading