@Override public List<String> resolve(List<String> names) { // normalize all input names to be in the form of IP addresses names = NetUtils.normalizeHostNames(names);
List <String> result = new ArrayList<String>(names.size()); if (names.isEmpty()) { return result; } //这里就是关键所在 List<String> uncachedHosts = getUncachedHosts(names);
// Resolve the uncached hosts List<String> resolvedHosts = rawMapping.resolve(uncachedHosts); //cache them cacheResolvedHosts(uncachedHosts, resolvedHosts); //now look up the entire list in the cache return getCachedHosts(names);
@Override public void reloadCachedMappings() { cache.clear(); }
DatanodeManager类里面的reloadCachedMappings
1 2 3 4 5 6 7 8 9 10 11 12
catch (InvalidTopologyException e) { // If the network location is invalid, clear the cached mappings // so that we have a chance to re-add this DataNode with the // correct network location later. List<String> invalidNodeNames = new ArrayList<String>(3); // clear cache for nodes in IP or Hostname invalidNodeNames.add(nodeReg.getIpAddr()); invalidNodeNames.add(nodeReg.getHostName()); invalidNodeNames.add(nodeReg.getPeerHostName()); dnsToSwitchMapping.reloadCachedMappings(invalidNodeNames); throw e; }