sharmaar12 commented on code in PR #7743:
URL: https://github.com/apache/hbase/pull/7743#discussion_r2834757713
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java:
##########
@@ -1292,6 +1306,80 @@ RegionEventDescriptor.EventType.REGION_CLOSE,
getRegionInfo(), mvcc.getReadPoint
}
}
+ private String[] append(String[] original, String value) {
+ String[] updated = new String[original.length + 1];
+ System.arraycopy(original, 0, updated, 0, original.length);
+ updated[original.length] = value;
+ return updated;
+ }
+
+ private void addReadOnlyCoprocessors(Configuration conf) {
+ String[] regionCoprocs =
conf.getStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
+
+ if (regionCoprocs == null) {
+ regionCoprocs = new String[0];
+ }
+
+ String regionCP = RegionReadOnlyController.class.getName();
+ String bulkCP = BulkLoadReadOnlyController.class.getName();
+ String endpointCP = EndpointReadOnlyController.class.getName();
+
+ // Add each CP independently if not present
+ if (!java.util.Arrays.asList(regionCoprocs).contains(regionCP)) {
+ regionCoprocs = append(regionCoprocs, regionCP);
+ }
+
+ if (!java.util.Arrays.asList(regionCoprocs).contains(bulkCP)) {
+ regionCoprocs = append(regionCoprocs, bulkCP);
+ }
+
+ if (!java.util.Arrays.asList(regionCoprocs).contains(endpointCP)) {
+ regionCoprocs = append(regionCoprocs, endpointCP);
+ }
+
+ conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
regionCoprocs);
+ }
+
+ private void removeReadOnlyCoprocessors(Configuration conf) {
+ String[] coprocessors =
conf.getStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
+
+ if (coprocessors == null) {
+ conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, new
String[0]);
+ return;
+ }
+
+ String regionCP = RegionReadOnlyController.class.getName();
+ String bulkCP = BulkLoadReadOnlyController.class.getName();
+ String endpointCP = EndpointReadOnlyController.class.getName();
+
+ String[] updated = java.util.Arrays.stream(coprocessors)
+ .filter(cp -> !regionCP.equals(cp) && !bulkCP.equals(cp) &&
!endpointCP.equals(cp))
+ .toArray(String[]::new);
+
+ if (updated.length == 0) {
+ // As conf is CompoundConfiguration, we need to set it to empty string
instead of null to
+ // remove the coprocessors
+ // Also conf.unset will not have any effect on CompoundConfiguration,
unlike with Hmaster and
+ // HRegionServer
+ conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, new
String[0]);
Review Comment:
We have to explicitly use setStrings instead of conf.unset() because unset
does not work with CompoundConfiguration (shallow copy), as setting it to null
or using unset has no effect on CompoundConfiguration.
--
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]