apurtell commented on code in PR #8733:
URL: https://github.com/apache/hbase/pull/8733#discussion_r4223367801


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java:
##########
@@ -742,30 +831,267 @@ private void updateCacheOfRSGroups(final Set<String> 
currentGroups) {
     this.prevRSGroups.addAll(currentGroups);
   }
 
-  // Called by ServerEventsListenerThread. Presume it has lock on this manager 
when it runs.
-  private SortedSet<Address> getDefaultServers() {
-    return getDefaultServers(listRSGroups()/* get from rsGroupMap */);
+  /**
+   * Parses {@code hbase.rsgroup.regex.<groupname>=<regex>} entries out of 
{@code conf}. Entries
+   * with an invalid group name, targeting the reserved {@link 
RSGroupInfo#DEFAULT_GROUP}, or with
+   * an unparsable regex are logged and skipped.
+   */
+  static Map<String, Pattern> getRegexGroupMap(Configuration conf) {
+    Map<String, String> rsGroupNameToRegexMap = 
conf.getPropsWithPrefix(RS_GROUP_REGEX_PREFIX);
+    Map<String, Pattern> rsGroupNameToPatternMap = new HashMap<>();
+    for (Map.Entry<String, String> e : rsGroupNameToRegexMap.entrySet()) {

Review Comment:
   Same!



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java:
##########
@@ -742,30 +831,267 @@ private void updateCacheOfRSGroups(final Set<String> 
currentGroups) {
     this.prevRSGroups.addAll(currentGroups);
   }
 
-  // Called by ServerEventsListenerThread. Presume it has lock on this manager 
when it runs.
-  private SortedSet<Address> getDefaultServers() {
-    return getDefaultServers(listRSGroups()/* get from rsGroupMap */);
+  /**
+   * Parses {@code hbase.rsgroup.regex.<groupname>=<regex>} entries out of 
{@code conf}. Entries
+   * with an invalid group name, targeting the reserved {@link 
RSGroupInfo#DEFAULT_GROUP}, or with
+   * an unparsable regex are logged and skipped.
+   */
+  static Map<String, Pattern> getRegexGroupMap(Configuration conf) {
+    Map<String, String> rsGroupNameToRegexMap = 
conf.getPropsWithPrefix(RS_GROUP_REGEX_PREFIX);
+    Map<String, Pattern> rsGroupNameToPatternMap = new HashMap<>();
+    for (Map.Entry<String, String> e : rsGroupNameToRegexMap.entrySet()) {
+      if (e.getValue() == null) {
+        // getPropsWithPrefix reads names and values separately, so an entry 
removed by a concurrent
+        // configuration reload can show up here with a null value. Treat it 
as unset.
+        continue;
+      }
+      if (!GROUP_NAME_PATTERN.matcher(e.getKey()).matches()) {
+        LOG.warn("Ignoring {}{} -- '{}' is not a valid RSGroup name (only 
alphanumeric characters "
+          + "and underscore allowed)", RS_GROUP_REGEX_PREFIX, e.getKey(), 
e.getKey());
+        continue;
+      }
+      if (RSGroupInfo.DEFAULT_GROUP.equals(e.getKey())) {
+        LOG.warn("Ignoring {}{} -- regex-based membership cannot target the 
reserved '{}' group",
+          RS_GROUP_REGEX_PREFIX, e.getKey(), RSGroupInfo.DEFAULT_GROUP);
+        continue;
+      }
+      try {
+        rsGroupNameToPatternMap.put(e.getKey(), Pattern.compile(e.getValue()));
+      } catch (PatternSyntaxException ex) {
+        LOG.warn("Invalid regex '{}' for RSGroup '{}' ({}{}); ignoring this 
entry", e.getValue(),
+          e.getKey(), RS_GROUP_REGEX_PREFIX, e.getKey());
+      }
+    }
+    LOG.info("Resolved regex-based RSGroup membership config: {}", 
rsGroupNameToPatternMap);
+    return rsGroupNameToPatternMap;
   }
 
-  // Called by ServerEventsListenerThread. Presume it has lock on this manager 
when it runs.
-  private SortedSet<Address> getDefaultServers(List<RSGroupInfo> 
rsGroupInfoList) {
-    // Build a list of servers in other groups than default group, from 
rsGroupMap
-    Set<Address> serversInOtherGroup = new HashSet<>();
-    for (RSGroupInfo group : rsGroupInfoList) {
-      if (!RSGroupInfo.DEFAULT_GROUP.equals(group.getName())) { // not default 
group
-        serversInOtherGroup.addAll(group.getServers());
+  private static List<String> getMatchingRSGroupNames(String hostname,
+    Map<String, Pattern> rsGroupNameToPatternMap) {
+    List<String> rsGroupNames = new ArrayList<>();
+    for (Map.Entry<String, Pattern> e : rsGroupNameToPatternMap.entrySet()) {
+      if (e.getValue().matcher(hostname).matches()) {
+        rsGroupNames.add(e.getKey());
       }
     }
+    LOG.info("Hostname '{}' matches RSGroup name(s) {}", hostname, 
rsGroupNames);
+    return rsGroupNames;
+  }

Review Comment:
   Same!!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to