From 978701183e91899baa7896167f4f638a72741293 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 30 Apr 2019 16:33:58 +0800 Subject: [PATCH] HBASE-22328 NPE in RegionReplicaReplicationEndpoint --- .../RegionReplicaReplicationEndpoint.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RegionReplicaReplicationEndpoint.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RegionReplicaReplicationEndpoint.java index 65cf9a887e5d..cc2650f803f2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RegionReplicaReplicationEndpoint.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/RegionReplicaReplicationEndpoint.java @@ -151,21 +151,23 @@ private boolean requiresReplication(Optional tableDesc, Entry e private void getRegionLocations(CompletableFuture future, TableDescriptor tableDesc, byte[] encodedRegionName, byte[] row, boolean reload) { FutureUtils.addListener(connection.getRegionLocations(tableDesc.getTableName(), row, reload), - (r, e) -> { + (locs, e) -> { if (e != null) { future.completeExceptionally(e); return; } // if we are not loading from cache, just return if (reload) { - future.complete(r); + future.complete(locs); return; } // check if the number of region replicas is correct, and also the primary region name - // matches - if (r.size() == tableDesc.getRegionReplication() && Bytes.equals( - r.getDefaultRegionLocation().getRegion().getEncodedNameAsBytes(), encodedRegionName)) { - future.complete(r); + // matches, and also there is no null elements in the returned RegionLocations + if (locs.size() == tableDesc.getRegionReplication() && + locs.size() == locs.numNonNullElements() && + Bytes.equals(locs.getDefaultRegionLocation().getRegion().getEncodedNameAsBytes(), + encodedRegionName)) { + future.complete(locs); } else { // reload again as the information in cache maybe stale getRegionLocations(future, tableDesc, encodedRegionName, row, true);