[fix][broker] Ensure that PulsarService is ready for serving incoming requests - #22977
Conversation
|
Is this possible for us to start WebService/WebSocketService/BrokerService/ProtocolHander after the other Pulsar Services start? |
Yes, it makes sense to cover all cases in a way so that requests aren't handled before PulsarService has been started. |
49ae27c to
1238a4f
Compare
I renamed the concept to mean that the broker is ready to serve request instead of being fully started. I believe that this covers what is really needed and the original intention of this PR. I checked the current solution and this is sufficiently covered already for the Pulsar broker with various configurations. There's no need to separately handle websockets since websocket servlets get added to the same Jetty server which already contains the filter to wait until PulsarService is ready for incoming requests. ProtocolHandlers don't need any special handling since they get started as the last step in PulsarService. |
1238a4f to
16c69f1
Compare
16c69f1 to
09a46e4
Compare
14c17a0 to
3ab5526
Compare
3ab5526 to
fc593e7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22977 +/- ##
============================================
- Coverage 73.57% 73.39% -0.18%
- Complexity 32624 32915 +291
============================================
Files 1877 1903 +26
Lines 139502 142711 +3209
Branches 15299 15571 +272
============================================
+ Hits 102638 104749 +2111
- Misses 28908 29941 +1033
- Partials 7956 8021 +65
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… requests (apache#22977) (cherry picked from commit 53df683)
… requests (apache#22977) (cherry picked from commit 53df683)
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420)
… requests (apache#22977) (cherry picked from commit 53df683)
… requests (apache#22977) (cherry picked from commit 53df683)
… requests (apache#22977) (cherry picked from commit 53df683)
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420)
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420)
… requests (apache#22977) (cherry picked from commit 53df683)
…incoming requests (apache#22977)" This reverts commit 598e073.
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420)
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420) (cherry picked from commit 1a7eb54)
… requests (apache#22977) (cherry picked from commit 53df683) (cherry picked from commit ec51420) (cherry picked from commit 1a7eb54)
…ative#659) ### Motivation The follow-up PR for the new LB: apache/pulsar#23119 The `getOwnedServiceUnits` may throw an exception after apache/pulsar#22977 , we can ignore this exception since the LB is not started yet. ``` pulsar-broker org.apache.pulsar.broker.PulsarServerException: java.lang.RuntimeException: java.lang.IllegalStateException: Invalid channel state:LeaderElectionServiceStarted pulsar-broker at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:997) pulsar-broker at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.call(PulsarBrokerStarter.java:294) pulsar-broker at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.call(PulsarBrokerStarter.java:131) pulsar-broker at picocli.CommandLine.executeUserObject(CommandLine.java:2041) pulsar-broker at picocli.CommandLine.access$1500(CommandLine.java:148) pulsar-broker at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461) pulsar-broker at picocli.CommandLine$RunLast.handle(CommandLine.java:2453) pulsar-broker at picocli.CommandLine$RunLast.handle(CommandLine.java:2415) pulsar-broker at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273) pulsar-broker at picocli.CommandLine$RunLast.execute(CommandLine.java:2417) pulsar-broker at picocli.CommandLine.execute(CommandLine.java:2170) pulsar-broker at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.start(PulsarBrokerStarter.java:152) pulsar-broker at org.apache.pulsar.PulsarBrokerStarter.main(PulsarBrokerStarter.java:386) pulsar-broker Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Invalid channel state:LeaderElectionServiceStarted pulsar-broker at org.apache.pulsar.broker.namespace.NamespaceService.getOwnedServiceUnits(NamespaceService.java:1203) pulsar-broker at io.streamnative.pulsar.handlers.kop.NamespaceBundleOwnershipListenerImpl.addTopicOwnershipListener(NamespaceBundleOwnershipListenerImpl.java:72) pulsar-broker at io.streamnative.pulsar.handlers.kop.KafkaProtocolHandler.start(KafkaProtocolHandler.java:259) pulsar-broker at org.apache.pulsar.broker.protocol.ProtocolHandlerWithClassLoader.start(ProtocolHandlerWithClassLoader.java:93) pulsar-broker at org.apache.pulsar.broker.protocol.ProtocolHandlers.lambda$start$4(ProtocolHandlers.java:153) pulsar-broker at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:422) pulsar-broker at org.apache.pulsar.broker.protocol.ProtocolHandlers.start(ProtocolHandlers.java:153) pulsar-broker at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:952) pulsar-broker ... 12 more pulsar-broker Caused by: java.lang.IllegalStateException: Invalid channel state:LeaderElectionServiceStarted pulsar-broker at org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateChannelImpl.getOwnershipEntrySet(ServiceUnitStateChannelImpl.java:1767) pulsar-broker at org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl.getOwnedServiceUnitsAsync(ExtensibleLoadManagerImpl.java:217) pulsar-broker at org.apache.pulsar.broker.namespace.NamespaceService.getOwnedServiceUnits(NamespaceService.java:1200) pulsar-broker ... 19 more pulsar-broker 2024-08-12T04:00:38,065+0000 [pulsar-service-shutdown] INFO org.apache.pulsar.PulsarBrokerStarter - Shut down functions worker service successfully. pulsar-broker 2024-08-12T04:00:38,074+0000 [pulsar-service-shutdown] ERROR org.apache.pulsar.PulsarBrokerStarter - Error while shutting down Pulsar service ``` ### Modifications * Handle `getOwnedServiceUnits` fails gracefully
Fixes #22975
Motivation
Pulsar broker will start serving requests while the broker is starting. This can cause issues and bugs which are hard to reproduce. Serving requests should be delayed until the broker is ready.
The
brokerIdbug #22975 is just one example of problems that this PR will address.Modifications
Documentation
docdoc-requireddoc-not-neededdoc-complete