HBASE-24569 Get hostAndWeights in addition using localhost if it is null in local mode
Closes #1909 Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
parent
979edfe720
commit
ee450ae943
|
@ -26,9 +26,9 @@ import java.util.NavigableSet;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import org.apache.hadoop.fs.StorageType;
|
import org.apache.hadoop.fs.StorageType;
|
||||||
|
import org.apache.hadoop.hbase.util.DNS;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data structure to describe the distribution of HDFS blocks among hosts.
|
* Data structure to describe the distribution of HDFS blocks among hosts.
|
||||||
*
|
*
|
||||||
|
@ -280,6 +280,18 @@ public class HDFSBlocksDistribution {
|
||||||
private long getBlocksLocalityWeightInternal(String host, Visitor visitor) {
|
private long getBlocksLocalityWeightInternal(String host, Visitor visitor) {
|
||||||
long localityIndex = 0;
|
long localityIndex = 0;
|
||||||
HostAndWeight hostAndWeight = this.hostAndWeights.get(host);
|
HostAndWeight hostAndWeight = this.hostAndWeights.get(host);
|
||||||
|
// Compatible with local mode, see HBASE-24569
|
||||||
|
if (hostAndWeight == null) {
|
||||||
|
String currentHost = "";
|
||||||
|
try {
|
||||||
|
currentHost = DNS.getDefaultHost("default", "default");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Just ignore, it's ok, avoid too many log info
|
||||||
|
}
|
||||||
|
if (host.equals(currentHost)) {
|
||||||
|
hostAndWeight = this.hostAndWeights.get(HConstants.LOCALHOST);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hostAndWeight != null && uniqueBlocksTotalWeight != 0) {
|
if (hostAndWeight != null && uniqueBlocksTotalWeight != 0) {
|
||||||
localityIndex = visitor.visit(hostAndWeight);
|
localityIndex = visitor.visit(hostAndWeight);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -25,6 +26,7 @@ import java.util.Map;
|
||||||
import org.apache.hadoop.fs.StorageType;
|
import org.apache.hadoop.fs.StorageType;
|
||||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
|
import org.apache.hadoop.hbase.util.DNS;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
@ -81,4 +83,19 @@ public class TestHDFSBlocksDistribution {
|
||||||
assertEquals("Should be one host", 1, distribution.getHostAndWeights().size());
|
assertEquals("Should be one host", 1, distribution.getHostAndWeights().size());
|
||||||
assertEquals("Total weight should be 10", 10, distribution.getUniqueBlocksTotalWeight());
|
assertEquals("Total weight should be 10", 10, distribution.getUniqueBlocksTotalWeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLocalHostCompatibility() throws Exception {
|
||||||
|
String currentHost = DNS.getDefaultHost("default", "default");
|
||||||
|
HDFSBlocksDistribution distribution = new HDFSBlocksDistribution();
|
||||||
|
assertEquals("Locality should be 0.0", 0.0,
|
||||||
|
distribution.getBlockLocalityIndex(currentHost), 0.01);
|
||||||
|
distribution.addHostsAndBlockWeight(new String[] { "localhost" }, 10);
|
||||||
|
assertEquals("Should be one host", 1, distribution.getHostAndWeights().size());
|
||||||
|
assertEquals("Locality should be 0.0", 0.0,
|
||||||
|
distribution.getBlockLocalityIndex("test"), 0.01);
|
||||||
|
assertNotEquals("Locality should be 0.0", 0.0,
|
||||||
|
distribution.getBlockLocalityIndex(currentHost), 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue