You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2019/05/22 02:50:52 UTC

[hbase] 24/26: HBASE-22328 NPE in RegionReplicaReplicationEndpoint

This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch HBASE-21512
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit cc7c1b981db0ebc33e3580fb728a9ffa981b6cb4
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Tue Apr 30 16:33:58 2019 +0800

    HBASE-22328 NPE in RegionReplicaReplicationEndpoint
---
 .../regionserver/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 65cf9a8..cc2650f 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 @@ public class RegionReplicaReplicationEndpoint extends HBaseReplicationEndpoint {
   private void getRegionLocations(CompletableFuture<RegionLocations> 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);