diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java index 679aec36605..a4e3c8024ba 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java @@ -260,6 +260,7 @@ public RackawareEnsemblePlacementPolicyImpl initialize(ClientConfiguration conf, String dnsResolverName = conf.getString(REPP_DNS_RESOLVER_CLASS, ScriptBasedMapping.class.getName()); try { dnsResolver = ReflectionUtils.newInstance(dnsResolverName, DNSToSwitchMapping.class); + dnsResolver.setBookieAddressResolver(bookieAddressResolver); if (dnsResolver instanceof Configurable) { ((Configurable) dnsResolver).setConf(conf); } @@ -269,9 +270,10 @@ public RackawareEnsemblePlacementPolicyImpl initialize(ClientConfiguration conf, } } catch (RuntimeException re) { if (!conf.getEnforceMinNumRacksPerWriteQuorum()) { - LOG.error("Failed to initialize DNS Resolver {}, used default subnet resolver : {} {}", - dnsResolverName, re, re.getMessage()); + LOG.error("Failed to initialize DNS Resolver {}, used default subnet resolver ", + dnsResolverName, re); dnsResolver = new DefaultResolver(this::getDefaultRack); + dnsResolver.setBookieAddressResolver(bookieAddressResolver); } else { /* * if minNumRacksPerWriteQuorum is enforced, then it @@ -282,9 +284,6 @@ public RackawareEnsemblePlacementPolicyImpl initialize(ClientConfiguration conf, } } } - if (dnsResolver != null) { - dnsResolver.setBookieAddressResolver(bookieAddressResolver); - } slowBookies = CacheBuilder.newBuilder() .expireAfterWrite(conf.getBookieFailureHistoryExpirationMSec(), TimeUnit.MILLISECONDS) .build(new CacheLoader() { diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ZoneawareEnsemblePlacementPolicyImpl.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ZoneawareEnsemblePlacementPolicyImpl.java index 990d60f3aaf..61b81ed303e 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ZoneawareEnsemblePlacementPolicyImpl.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ZoneawareEnsemblePlacementPolicyImpl.java @@ -233,6 +233,7 @@ public Integer getSample() { } else { String dnsResolverName = conf.getString(REPP_DNS_RESOLVER_CLASS, ScriptBasedMapping.class.getName()); actualDNSResolver = ReflectionUtils.newInstance(dnsResolverName, DNSToSwitchMapping.class); + actualDNSResolver.setBookieAddressResolver(bookieAddressResolver); if (actualDNSResolver instanceof Configurable) { ((Configurable) actualDNSResolver).setConf(conf); } diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestRackawareEnsemblePlacementPolicy.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestRackawareEnsemblePlacementPolicy.java index f0520d45e24..28a27ee611b 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestRackawareEnsemblePlacementPolicy.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestRackawareEnsemblePlacementPolicy.java @@ -43,13 +43,16 @@ import org.apache.bookkeeper.client.ITopologyAwareEnsemblePlacementPolicy.Ensemble; import org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy.EnsembleForReplacementWithNoConstraints; import org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy.TruePredicate; +import org.apache.bookkeeper.common.util.ReflectionUtils; import org.apache.bookkeeper.conf.ClientConfiguration; +import org.apache.bookkeeper.net.AbstractDNSToSwitchMapping; import org.apache.bookkeeper.net.BookieId; import org.apache.bookkeeper.net.BookieNode; import org.apache.bookkeeper.net.BookieSocketAddress; import org.apache.bookkeeper.net.DNSToSwitchMapping; import org.apache.bookkeeper.net.NetworkTopology; import org.apache.bookkeeper.net.Node; +import org.apache.bookkeeper.net.ScriptBasedMapping; import org.apache.bookkeeper.proto.BookieAddressResolver; import org.apache.bookkeeper.stats.Gauge; import org.apache.bookkeeper.stats.NullStatsLogger; @@ -146,6 +149,17 @@ static void updateMyRack(String rack) throws Exception { StaticDNSResolver.addNodeToRack("localhost", rack); } + @Test + public void testInitalize() throws Exception{ + String dnsResolverName = conf.getString(REPP_DNS_RESOLVER_CLASS, ScriptBasedMapping.class.getName()); + DNSToSwitchMapping dnsResolver = ReflectionUtils.newInstance(dnsResolverName, DNSToSwitchMapping.class); + AbstractDNSToSwitchMapping tmp = (AbstractDNSToSwitchMapping) dnsResolver; + assertNull(tmp.getBookieAddressResolver()); + + dnsResolver.setBookieAddressResolver(repp.bookieAddressResolver); + assertNotNull(tmp.getBookieAddressResolver()); + } + @Test public void testNodeDown() throws Exception { repp.uninitalize();