You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by rm...@apache.org on 2025/03/19 22:15:48 UTC

(hbase) branch branch-2 updated: HBASE-29186 RegionPlanConditionals can produce a null pointer (#6796) (#6812)

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

rmattingly pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 0aa67115a52 HBASE-29186 RegionPlanConditionals can produce a null pointer (#6796) (#6812)
0aa67115a52 is described below

commit 0aa67115a521ab0f59c77fbb0fd7d45f107ee7bd
Author: Ray Mattingly <rm...@apache.org>
AuthorDate: Wed Mar 19 18:15:42 2025 -0400

    HBASE-29186 RegionPlanConditionals can produce a null pointer (#6796) (#6812)
    
    Signed-off-by: Nick Dimiduk <nd...@apache.org>
    Co-authored-by: Ray Mattingly <rm...@hubspot.com>
---
 .../hbase/master/balancer/RegionPlanConditional.java | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
index 8de371d341c..063f3ba5f72 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.hbase.master.balancer;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -85,8 +86,8 @@ public abstract class RegionPlanConditional {
 
     // Check Server
     int[] destinationRegionIndices = cluster.regionsPerServer[destinationServerIdx];
-    Set<RegionInfo> serverRegions = Arrays.stream(cluster.regionsPerServer[destinationServerIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> serverRegions =
+      getRegionsFromIndex(destinationServerIdx, cluster.regionsPerServer);
     for (int regionIdx : destinationRegionIndices) {
       serverRegions.add(cluster.regions[regionIdx]);
     }
@@ -100,8 +101,7 @@ public abstract class RegionPlanConditional {
 
     // Check Host
     int hostIdx = cluster.serverIndexToHostIndex[destinationServerIdx];
-    Set<RegionInfo> hostRegions = Arrays.stream(cluster.regionsPerHost[hostIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> hostRegions = getRegionsFromIndex(hostIdx, cluster.regionsPerHost);
     if (isViolatingHost(regionPlan, hostRegions)) {
       return true;
     }
@@ -112,8 +112,7 @@ public abstract class RegionPlanConditional {
 
     // Check Rack
     int rackIdx = cluster.serverIndexToRackIndex[destinationServerIdx];
-    Set<RegionInfo> rackRegions = Arrays.stream(cluster.regionsPerRack[rackIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> rackRegions = getRegionsFromIndex(rackIdx, cluster.regionsPerRack);
     if (isViolatingRack(regionPlan, rackRegions)) {
       return true;
     }
@@ -130,4 +129,13 @@ public abstract class RegionPlanConditional {
   boolean isViolatingRack(RegionPlan regionPlan, Set<RegionInfo> destinationRegions) {
     return false;
   }
+
+  private Set<RegionInfo> getRegionsFromIndex(int index, int[][] regionsPerIndex) {
+    int[] regionIndices = regionsPerIndex[index];
+    if (regionIndices == null) {
+      return Collections.emptySet();
+    }
+    return Arrays.stream(regionIndices).mapToObj(idx -> cluster.regions[idx])
+      .collect(Collectors.toSet());
+  }
 }