dlmarion commented on code in PR #6146:
URL: https://github.com/apache/accumulo/pull/6146#discussion_r2848155944


##########
server/tserver/src/main/java/org/apache/accumulo/tserver/ScanServer.java:
##########
@@ -477,6 +488,77 @@ public void run() {
     }
   }
 
+  // Visible for testing
+  protected boolean isAllowed(TableId tid) {
+    Boolean result = allowedTables.get(tid);
+    if (result == null) {
+      // Clear the cache and try again, maybe there
+      // is a race condition in table creation and
+      // scan
+      updateAllowedTables(true);
+      result = allowedTables.get(tid);
+    }
+    return result;
+  }
+
+  private synchronized void updateAllowedTables(boolean clearCache) {
+
+    LOG.debug("Updating allowed tables for ScanServer");
+    if (clearCache) {
+      context.clearTableListCache();
+    }
+
+    // Remove tables that no longer exist
+    allowedTables.keySet().forEach(tid -> {
+      if (!getContext().getTableIdToNameMap().containsKey(tid)) {
+        LOG.debug("Removing table {} from allowed table map as it no longer 
exists", tid);
+        allowedTables.remove(tid);
+      }
+    });
+
+    final String propName = Property.SSERV_SCAN_ALLOWED_TABLES.getKey() + 
groupName;
+    String allowedTableRegex = getConfiguration().get(propName);
+    if (allowedTableRegex == null) {
+      allowedTableRegex = DEFAULT_SCAN_ALLOWED_PATTERN;
+    }
+
+    if (currentAllowedTableRegex == null) {
+      LOG.debug("Property {} initial value: {}", propName, allowedTableRegex);
+    } else if (currentAllowedTableRegex.equals(allowedTableRegex)) {
+      // Property value has not changed, do nothing
+    } else {
+      LOG.debug("Property {} has changed. Old value: {}, new value: {}", 
propName,
+          currentAllowedTableRegex, allowedTableRegex);
+    }
+
+    Pattern allowedTablePattern;
+    try {
+      allowedTablePattern = Pattern.compile(allowedTableRegex);
+    } catch (PatternSyntaxException e) {
+      LOG.error(
+          "Property {} contains an invalid regular expression. Property value: 
{}. Using default pattern: {}",
+          propName, allowedTableRegex, DEFAULT_SCAN_ALLOWED_PATTERN);
+      allowedTablePattern = Pattern.compile(DEFAULT_SCAN_ALLOWED_PATTERN);
+    }
+    // Regex is valid, store it
+    currentAllowedTableRegex = allowedTableRegex;
+
+    Pattern p = allowedTablePattern;
+    context.getTableNameToIdMap().entrySet().forEach(e -> {
+      String tname = e.getKey();
+      TableId tid = e.getValue();
+      Matcher m = p.matcher(tname);
+      if (m.matches()) {
+        LOG.debug("Table {} can now be scanned via this ScanServer", tname);

Review Comment:
   My plan is to adjust the logging before I merge. Leaving it as debug for now 
in case of testing issues.



##########
server/tserver/src/main/java/org/apache/accumulo/tserver/ScanServer.java:
##########
@@ -477,6 +488,77 @@ public void run() {
     }
   }
 
+  // Visible for testing
+  protected boolean isAllowed(TableId tid) {
+    Boolean result = allowedTables.get(tid);
+    if (result == null) {
+      // Clear the cache and try again, maybe there
+      // is a race condition in table creation and
+      // scan
+      updateAllowedTables(true);
+      result = allowedTables.get(tid);
+    }
+    return result;
+  }
+
+  private synchronized void updateAllowedTables(boolean clearCache) {
+
+    LOG.debug("Updating allowed tables for ScanServer");
+    if (clearCache) {
+      context.clearTableListCache();
+    }
+
+    // Remove tables that no longer exist
+    allowedTables.keySet().forEach(tid -> {
+      if (!getContext().getTableIdToNameMap().containsKey(tid)) {
+        LOG.debug("Removing table {} from allowed table map as it no longer 
exists", tid);
+        allowedTables.remove(tid);
+      }
+    });
+
+    final String propName = Property.SSERV_SCAN_ALLOWED_TABLES.getKey() + 
groupName;
+    String allowedTableRegex = getConfiguration().get(propName);
+    if (allowedTableRegex == null) {
+      allowedTableRegex = DEFAULT_SCAN_ALLOWED_PATTERN;
+    }
+
+    if (currentAllowedTableRegex == null) {
+      LOG.debug("Property {} initial value: {}", propName, allowedTableRegex);
+    } else if (currentAllowedTableRegex.equals(allowedTableRegex)) {
+      // Property value has not changed, do nothing
+    } else {
+      LOG.debug("Property {} has changed. Old value: {}, new value: {}", 
propName,
+          currentAllowedTableRegex, allowedTableRegex);
+    }
+
+    Pattern allowedTablePattern;
+    try {
+      allowedTablePattern = Pattern.compile(allowedTableRegex);
+    } catch (PatternSyntaxException e) {
+      LOG.error(
+          "Property {} contains an invalid regular expression. Property value: 
{}. Using default pattern: {}",
+          propName, allowedTableRegex, DEFAULT_SCAN_ALLOWED_PATTERN);
+      allowedTablePattern = Pattern.compile(DEFAULT_SCAN_ALLOWED_PATTERN);

Review Comment:
   Updated in 02b55d1



-- 
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