sijie commented on a change in pull request #425: BOOKKEEPER-1105: 
RackAwarePolicy: Failure to map node into rack may result in failure to add 
other nodes.
URL: https://github.com/apache/bookkeeper/pull/425#discussion_r132529923
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/net/DNSToSwitchMapping.java
 ##########
 @@ -41,14 +41,14 @@
      * <p/>
      *
      * If a name cannot be resolved to a rack, the implementation
-     * should return {@link NetworkTopology#DEFAULT_RACK}. This
+     * should return {@link NetworkTopology#DEFAULT_REGION_AND_RACK}. This
      * is what the bundled implementations do, though it is not a formal 
requirement
      *
      * @param names the list of hosts to resolve (can be empty)
      * @return list of resolved network paths.
      * If <i>names</i> is empty, the returned list is also empty
      */
-    public List<String> resolve(List<String> names);
+    public List<String> resolve(List<String> names, String defaultRack);
 
 Review comment:
   This would break the binary compatibility for any people who implemented 
DNSToSwitchMapping.
   
   The main problem is 
   
   ```java
       public static String resolveNetworkLocation(DNSToSwitchMapping 
dnsResolver, InetSocketAddress addr) {
           List<String> names = new ArrayList<String>(1);
           if (dnsResolver instanceof CachedDNSToSwitchMapping) {
               names.add(addr.getAddress().getHostAddress());
           } else {
               names.add(addr.getHostName());
           }
           // resolve network addresses
           List<String> rNames = dnsResolver.resolve(names);
           String netLoc;
           if (null == rNames) {
               logger.warn("Failed to resolve network location for {}, using 
default rack for them : {}.", names,
                   NetworkTopology.DEFAULT_RACK);
               netLoc = NetworkTopology.DEFAULT_RACK;
           } else {
               netLoc = rNames.get(0);
           }
           return netLoc;
       }
   ```
   
   I think a clean solution without breaking the binary compatibility is
   
   - Fix the DefaultResolver to allow passing in a `defaultRack` 
   
   ```java
   class DefaultResolver {
   
       final String defaultRack = ...;
   
      DefaultResolver() {
          this(...);
      }
   
      DefaultResolver(String defaultRack) {
          this.defaultRack = defaultRack;
      }
   
   }
   ```
   
   the rackware can use new DefaultResolver(`/default-rack`) and regionaware 
can use new DefaultResolver(`/default-region/default-rack`)
   
   - create a DNSResolverDelegator with default-rack and remove the logic 
`NetUtils#resolveNetworkLocation` to this delegator.
   
   ```java
   class DNSResolverDelegator extends DefaultResolver {
   
       DNSToSwitchMapping resolver;
   
        DNSResolverDelegator(DNSToSwitchMapping resolver, String defaultRack) {
             super(defaultRack);
             this.resolver= resolver;
        }
   
        List<String> resolve(List<String> names) {
           List<String> resolvedNames = resolver.resolve(names);
           if (null == resolvedNames) {
               // return default rack
           }
        }
   
   }
   ```
   
   - on initialization
   
   ```java
           if (optionalDnsResolver.isPresent()) {
               dnsResolver = optionalDnsResolver.get();
           } else {
               String dnsResolverName = conf.getString(REPP_DNS_RESOLVER_CLASS, 
ScriptBasedMapping.class.getName());
               try {
                   dnsResolver = ReflectionUtils.newInstance(dnsResolverName, 
DNSToSwitchMapping.class);
                   if (dnsResolver instanceof Configurable) {
                       ((Configurable) dnsResolver).setConf(conf);
                   }
               } catch (RuntimeException re) {
                   LOG.info("Failed to initialize DNS Resolver {}, used default 
subnet resolver.", dnsResolverName, re);
                   dnsResolver = new DefaultResolver(`default-rack`); // <= add 
default rack
               }
           }
           this.dnsResolver = new DNSResolverDelegator(dnsResolver, 
defaultRack);
   ```
   
   In this way you don't need to change the signature of the methods. How does 
that sound?
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to