Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -127,7 +127,6 @@ public class ServiceUnitStateChannelImpl implements ServiceUnitStateChannel {
private final String brokerId;
private final Map<String, CompletableFuture<Void>> cleanupJobs;
private final StateChangeListeners stateChangeListeners;
private ExtensibleLoadManagerImpl loadManager;
private BrokerRegistry brokerRegistry;
private LeaderElectionService leaderElectionService;
private TableView<ServiceUnitStateData> tableview;
Expand Down Expand Up @@ -284,7 +283,6 @@ public synchronized void start() throws PulsarServerException {
log.warn("Failed to find the channel leader.");
}
this.channelState = LeaderElectionServiceStarted;
loadManager = getLoadManager();

if (producer != null) {
producer.close();
Expand Down Expand Up @@ -553,6 +551,9 @@ public CompletableFuture<Optional<String>> getOwnerAsync(String serviceUnit) {
}

private Optional<String> getOwner(String serviceUnit) {
if (!validateChannelState(Started, true)) {
throw new IllegalStateException("Invalid channel state:" + channelState.name());
}
ServiceUnitStateData data = tableview.get(serviceUnit);
ServiceUnitState state = state(data);
switch (state) {
Expand Down Expand Up @@ -1763,6 +1764,9 @@ public void listen(StateChangeListener listener) {

@Override
public Set<Map.Entry<String, ServiceUnitStateData>> getOwnershipEntrySet() {
if (!validateChannelState(Started, true)) {
throw new IllegalStateException("Invalid channel state:" + channelState.name());
}
return tableview.entrySet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,11 @@ public void addNamespaceBundleOwnershipListener(NamespaceBundleOwnershipListener
}
}
pulsar.runWhenReadyForIncomingRequests(() -> {
getOwnedServiceUnits().forEach(bundle -> notifyNamespaceBundleOwnershipListener(bundle, listeners));
try {
getOwnedServiceUnits().forEach(bundle -> notifyNamespaceBundleOwnershipListener(bundle, listeners));
Comment thread
lhotari marked this conversation as resolved.
} catch (Exception e) {
LOG.error("Failed to notify namespace bundle ownership listener", e);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.expectThrows;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
Expand Down Expand Up @@ -1762,6 +1763,18 @@ public void testActiveGetOwner() throws Exception {

}

@Test(priority = 20)
public void testGetOwnershipEntrySetBeforeChannelStart() {
var tmpChannel = new ServiceUnitStateChannelImpl(pulsar1);
try {
tmpChannel.getOwnershipEntrySet();
fail();
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
assertEquals("Invalid channel state:Constructed", e.getMessage());
}
}


private static ConcurrentHashMap<String, CompletableFuture<Optional<String>>> getOwnerRequests(
ServiceUnitStateChannel channel) throws IllegalAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import static org.testng.Assert.assertTrue;

@Test(groups = "broker")
Expand Down Expand Up @@ -102,6 +104,25 @@ public void unLoad(NamespaceBundle bundle) {
deleteNamespaceWithRetry(namespace, false);
}

@Test
public void testAddNamespaceBundleOwnershipListenerBeforeLBStart() {
NamespaceService namespaceService = spy(new NamespaceService(pulsar));
doThrow(new IllegalStateException("The LM is not initialized"))
.when(namespaceService).getOwnedServiceUnits();
namespaceService.addNamespaceBundleOwnershipListener(new NamespaceBundleOwnershipListener() {
@Override
public void onLoad(NamespaceBundle bundle) {}

@Override
public void unLoad(NamespaceBundle bundle) {}

@Override
public boolean test(NamespaceBundle namespaceBundle) {
return false;
}
});
}

@Test
public void testGetAllPartitions() throws Exception {
final String namespace = "prop/" + UUID.randomUUID().toString();
Expand Down