RaigorJiang opened a new issue #12513:
URL: https://github.com/apache/shardingsphere/issues/12513
## Bug Report
### Which version of ShardingSphere did you use?
master branch
### Steps to reproduce the behavior
When Start with cluster mode, and there is `no existed data on ZooKeeper,`
`NPE` will thrown from the method below:
```java
@Subscribe
public synchronized void renew(final PrimaryStateChangedEvent event) {
ClusterSchema clusterSchema = event.getClusterSchema();
Collection<ShardingSphereRule> rules =
contextManager.getMetaDataContexts().getMetaDataMap().get(clusterSchema.getSchemaName()).getRuleMetaData().getRules();
for (ShardingSphereRule each : rules) {
if (each instanceof StatusContainedRule) {
((StatusContainedRule) each).updateStatus(new
PrimaryDataSourceChangedEvent(clusterSchema.getSchemaName(),
clusterSchema.getDataSourceName(), event.getPrimaryDataSourceName()));
}
}
}
```
Error log:
```
Exception thrown by subscriber method
renew(org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.event.PrimaryStateChangedEvent)
on subscriber
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator@467045c4
when dispatching event:
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.event.PrimaryStateChangedEvent@7b691567
java.lang.NullPointerException
at
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator.renew(ClusterContextManagerCoordinator.java:229)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:87)
at
com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:144)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:72)
at
com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
at
com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:67)
at
com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:108)
at com.google.common.eventbus.EventBus.post(EventBus.java:212)
at java.util.Optional.ifPresent(Optional.java:159)
at
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory.lambda$watch$0(GovernanceWatcherFactory.java:55)
at
org.apache.shardingsphere.mode.repository.cluster.zookeeper.CuratorZookeeperRepository.lambda$watch$1(CuratorZookeeperRepository.java:247)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]