hangc0276 opened a new pull request #2980:
URL: https://github.com/apache/bookkeeper/pull/2980
### Motivation
When we set region or rack placement policy, but the region or rack name set
to `/` or empty string, it will throw the following exception on handling
bookies join.
```
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1841) ~[?:?]
at
org.apache.bookkeeper.net.NetworkTopologyImpl$InnerNode.getNextAncestorName(NetworkTopologyImpl.java:144)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.net.NetworkTopologyImpl$InnerNode.add(NetworkTopologyImpl.java:180)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.net.NetworkTopologyImpl.add(NetworkTopologyImpl.java:425)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy.handleBookiesThatJoined(TopologyAwareEnsemblePlacementPolicy.java:717)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl.handleBookiesThatJoined(RackawareEnsemblePlacementPolicyImpl.java:80)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy.handleBookiesThatJoined(RackawareEnsemblePlacementPolicy.java:249)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy.onClusterChanged(TopologyAwareEnsemblePlacementPolicy.java:663)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl.onClusterChanged(RackawareEnsemblePlacementPolicyImpl.java:80)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy.onClusterChanged(RackawareEnsemblePlacementPolicy.java:92)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.BookieWatcherImpl.processWritableBookiesChanged(BookieWatcherImpl.java:197)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.client.BookieWatcherImpl.lambda$initialBlockingBookieRead$1(BookieWatcherImpl.java:233)
~[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.discover.ZKRegistrationClient$WatchTask.accept(ZKRegistrationClient.java:147)
[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
org.apache.bookkeeper.discover.ZKRegistrationClient$WatchTask.accept(ZKRegistrationClient.java:70)
[io.streamnative-bookkeeper-server-4.14.3.1.jar:4.14.3.1]
at
java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
[?:?]
at
java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
[?:?]
at
java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
[?:?]
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
[?:?]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[?:?]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[?:?]
at
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[io.netty-netty-common-4.1.72.Final.jar:4.1.72.Final]
at java.lang.Thread.run(Thread.java:829) [?:?]
```
The root cause is that the node networkLocation is empty string and then use
`substring(1)` operation, which will lead to `StringIndexOutOfBoundsException`
### Modification
1. Add `n.getNetworkLocation()` is empty check on `isAncestor` method to
make the exception more clear.
--
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]