This is an automated email from the ASF dual-hosted git repository.
mkwhit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/crunch.git
The following commit(s) were added to refs/heads/master by this push:
new 807e0c8 CRUNCH-695: Fix NullPointerException in RegionLocationTable
(#32)
807e0c8 is described below
commit 807e0c809f2f206d2ce209b970d3c071c4d05183
Author: Andrew Olson <[email protected]>
AuthorDate: Wed Mar 25 11:14:37 2020 -0500
CRUNCH-695: Fix NullPointerException in RegionLocationTable (#32)
Co-authored-by: Andrew Olson <[email protected]>
---
.../crunch/io/hbase/RegionLocationTableTest.java | 32 ++++++++++++++++++++--
.../crunch/io/hbase/RegionLocationTable.java | 15 +++++++---
2 files changed, 40 insertions(+), 7 deletions(-)
diff --git
a/crunch-hbase/src/it/java/org/apache/crunch/io/hbase/RegionLocationTableTest.java
b/crunch-hbase/src/it/java/org/apache/crunch/io/hbase/RegionLocationTableTest.java
index 0b44994..e018e74 100644
---
a/crunch-hbase/src/it/java/org/apache/crunch/io/hbase/RegionLocationTableTest.java
+++
b/crunch-hbase/src/it/java/org/apache/crunch/io/hbase/RegionLocationTableTest.java
@@ -128,10 +128,36 @@ public class RegionLocationTableTest {
deserialized.getPreferredNodeForRow(new byte[] { 10 }));
}
+ @Test
+ public void testNullRegionInfo() {
+ RegionLocationTable table = RegionLocationTable.create(TABLE_NAME,
+ ImmutableList.of(location(null, serverName("serverA"))));
+ assertNull(
+ table.getPreferredNodeForRow(new byte[] { 15 }));
+ }
+
+ @Test
+ public void testNullServerName() {
+ RegionLocationTable table = RegionLocationTable.create(TABLE_NAME,
+ ImmutableList.of(location(regionInfo(new byte[] { 10 }, new byte[] {
20 }), null)));
+ assertNull(
+ table.getPreferredNodeForRow(new byte[] { 15 }));
+ }
+
private static HRegionLocation location(byte[] startKey, byte[] endKey,
String hostName) {
- return new HRegionLocation(
- new HRegionInfo(TableName.valueOf(TABLE_NAME), startKey, endKey),
- ServerName.valueOf(hostName, 60020, System.currentTimeMillis()));
+ return location(regionInfo(startKey, endKey), serverName(hostName));
+ }
+
+ private static HRegionLocation location(HRegionInfo regionInfo, ServerName
serverName) {
+ return new HRegionLocation(regionInfo, serverName);
+ }
+
+ private static HRegionInfo regionInfo(byte[] startKey, byte[] endKey) {
+ return new HRegionInfo(TableName.valueOf(TABLE_NAME), startKey, endKey);
+ }
+
+ private static ServerName serverName(String hostName) {
+ return ServerName.valueOf(hostName, 60020, System.currentTimeMillis());
}
}
\ No newline at end of file
diff --git
a/crunch-hbase/src/main/java/org/apache/crunch/io/hbase/RegionLocationTable.java
b/crunch-hbase/src/main/java/org/apache/crunch/io/hbase/RegionLocationTable.java
index fa012af..05724fa 100644
---
a/crunch-hbase/src/main/java/org/apache/crunch/io/hbase/RegionLocationTable.java
+++
b/crunch-hbase/src/main/java/org/apache/crunch/io/hbase/RegionLocationTable.java
@@ -29,7 +29,9 @@ import java.util.NavigableMap;
import com.google.common.collect.Maps;
import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.util.Bytes;
/**
@@ -54,13 +56,18 @@ class RegionLocationTable {
public static RegionLocationTable create(String tableName,
List<HRegionLocation> regionLocationList) {
NavigableMap<byte[], String> regionStartToServerHostName =
Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
for (HRegionLocation regionLocation : regionLocationList) {
- byte[] startKey = regionLocation.getRegionInfo().getStartKey();
+ HRegionInfo regionInfo = regionLocation.getRegionInfo();
+ if (regionInfo == null) {
+ continue;
+ }
+ byte[] startKey = regionInfo.getStartKey();
if (startKey == null) {
startKey = HConstants.EMPTY_START_ROW;
}
- regionStartToServerHostName.put(
- startKey,
- regionLocation.getServerName().getHostname());
+ ServerName serverName = regionLocation.getServerName();
+ if (serverName != null) {
+ regionStartToServerHostName.put(startKey, serverName.getHostname());
+ }
}
return new RegionLocationTable(tableName, regionStartToServerHostName);
}