HBASE-30180: Can still add data to read-only region after flipping read-only flag multiple times#8280
Conversation
3f2cc32 to
024d94c
Compare
There was a problem hiding this comment.
Pull request overview
Fixes HBASE-30180 where toggling the read-only flag multiple times could leave a region writable. The root cause is that HRegion.this.conf is a CompoundConfiguration distinct from the newConf passed to onConfigurationChange(). The previous code synced the read-only coprocessor list onto newConf and built a new RegionCoprocessorHost from newConf rather than from this.conf, missing the table-descriptor layer and leaving stale data. For HMaster/HRegionServer, this.conf and newConf are the same object, so the issue is region-specific.
Changes:
- Overload
maybeUpdateCoprocessorsto accept a separateconfToUpdate, used for syncing read-only coprocessors and passed into the reload lambda. - Pass
this.conf(theCompoundConfiguration) asconfToUpdateinHRegion.onConfigurationChangeso the newRegionCoprocessorHostis built from the correct config layer; remove the now-unneededupdateCoprocessorListInConfhelper. - Simplify the HMaster/HRegionServer call sites since their
this.conf == newConf.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| hbase-server/src/main/java/org/apache/hadoop/hbase/util/CoprocessorConfigurationUtil.java | Adds confToUpdate parameter to maybeUpdateCoprocessors, removes obsolete updateCoprocessorListInConf helper, gates syncReadOnlyConfigurations on read-only-mode change only. |
| hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java | Passes this.conf (CompoundConfiguration) as confToUpdate and uses it for rebuilding RegionCoprocessorHost. |
| hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java | Simplifies lambda since this.conf == newConf. |
| hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java | Same simplification as HRegionServer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
taklwu
left a comment
There was a problem hiding this comment.
nit: Would you be able to come up with a unit test to prevent this error from happening?
| CoprocessorConfigurationUtil.syncReadOnlyConfigurations(newConf, coprocessorConfKey); | ||
| reloadTask.reload(newConf); | ||
| componentName, instance); | ||
| if (hasReadOnlyModeChanged) { |
There was a problem hiding this comment.
this reminded me about #7514 were facing the same issue, IMO you're doing the right change.
7d0ffb5 to
ffde80b
Compare
|
The unit test failures are not relevant. |
ffde80b to
e8d50c6
Compare
|
I force-pushed another commit to fix a poorly formatted comment. We can run the tests again if needed. However, all relevant tests passed on the last run. I also updated the PR description. |
e8d50c6 to
82a3576
Compare
|
Two more additions:
|
…ad-only flag multiple times Code generated with Cursor: - Unit test TestHRegion.testRegionOnConfigurationChangeLoadsReadOnlyCoprocessorsAfterRepeatedToggle() Code generated with Claude Opus: - Unit test TestHRegion.testRegionCoprocessorHostUsesCompoundConfigurationAfterConfigChange() Change-Id: I8c5edf6ae4775d36dbbe2b260f77e2168a2a92da
82a3576 to
f31676e
Compare
https://issues.apache.org/jira/browse/HBASE-30180
Note: Unit tests were generated using AI
testRegionOnConfigurationChangeLoadsReadOnlyCoprocessorsAfterRepeatedToggle()was generated with CursortestRegionCoprocessorHostUsesCompoundConfigurationAfterConfigChange()was generated with Claude OpusSummary
This pull request fixes an issue with the new Read-Replica feature where if you create a table on the active cluster and flip the read-only flag multiple times, then sometimes it is still possible to add data to a table despite the cluster being in read-only mode. This issue was happening due to how the configuration for
HRegionwas being updated after runningupdate_all_configin the HBase shell.Key Changes
CoprocessorConfigurationUtil.updateCoprocessorListInConf()method since running this inHMaster,HRegionServer, andHRegion'sonConfigurationChange()method is redundant.CompoundConfiguration, which was the main cause of HBASE-30180.RegionCoprocessorHostobject inHRegion.onConfigurationChange()after a dynamic configuration update.Configurationobject provided as an arg inHRegion.onConfigurationChange(). However, it needs to be created with an updated version of HRegion'sthis.confCompoundConfigurationobject.onConfigurationChange()methods regarding how theConfigurationobjects work.Configurationobject provided in theironConfigurationChange()methods is the same object reference as their respectivethis.confConfigurationobjects.More Details
Read-only mode is determined by checking whether the ReadOnly coprocessors are loaded on the cluster. If they are present, then read-only mode is active, and vice-vera if they are not present. HBASE-30180 was being caused by how the
CoprocessorConfigurationUtil.updateCoprocessorListInConf()method was unsetting the read-only coprocessors. HRegion'sthis.confobject is of typeCompoundConfiguration. This differs from HMaster and HRegionServer, which use typeConfiguration. When disabling read-only mode, theupdateCoprocessorListInConf()was runningunset()on the configuration object, which does not properly unset the config property forCompoundConfigurations. Instead, the property needs to explicitly be set to an empty string.After further investigation, the
updateCoprocessorListInConf()method was redundant and not necessary since the read-only coprocessors were already being added/removed inCoprocessorConfigurationUtil.syncReadOnlyConfigurations(). That is why this PR removes theupdateCoprocessorListInConf()entirely.One additional issue was with how HRegion's
this.coprocessorHostobject was being updated after a dynamic configuration update. The newRegionCoprocessorHostobject created forthis.coprocessorHostwas using the dynamically updatedConfigurationobject when it should have been using an updated version of HRegion'sCompoundConfigurationobject. This PR corrects that discrepancy.