sharmaar12 commented on code in PR #7743:
URL: https://github.com/apache/hbase/pull/7743#discussion_r2834753621
##########
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]);
+ } else if (updated.length != coprocessors.length) {
+ conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, updated);
+ }
+ }
+
+ private void syncReadOnlyConfigurations(boolean readOnlyMode) {
+ this.baseConf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
readOnlyMode);
+ this.conf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
readOnlyMode);
+ // If readonly is true then add the coprocessor of master
+ if (readOnlyMode) {
+ addReadOnlyCoprocessors(this.baseConf);
Review Comment:
We must sync both conf as well as baseConf object because baseConf is used
when new table/region is created and synching just conf will make the new table
to use initial value with which the cluster started with. This is also
important when region split happens as in the split baseConf gets used instead
of conf object.
--
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]