|
36 | 36 | import java.util.concurrent.atomic.AtomicInteger; |
37 | 37 | import java.util.function.IntSupplier; |
38 | 38 | import org.apache.hadoop.conf.Configuration; |
| 39 | +import org.apache.hadoop.hbase.HConstants; |
39 | 40 | import org.apache.hadoop.hbase.client.RegionInfo; |
40 | 41 | import org.apache.hadoop.hbase.conf.ConfigurationManager; |
41 | 42 | import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver; |
@@ -339,8 +340,8 @@ private void requestCompactionInternal(HRegion region, String why, int priority, |
339 | 340 | protected void requestCompactionInternal(HRegion region, HStore store, String why, int priority, |
340 | 341 | boolean selectNow, CompactionLifeCycleTracker tracker, |
341 | 342 | CompactionCompleteTracker completeTracker, User user) throws IOException { |
342 | | - if (!this.isCompactionsEnabled()) { |
343 | | - LOG.info("Ignoring compaction request for " + region + ",because compaction is disabled."); |
| 343 | + if (!this.isCompactionsEnabled() || isReadOnlyEnabled()) { |
| 344 | + LOG.info("Ignoring compaction request for " + region + ",because compaction is disabled or read-only mode is on."); |
344 | 345 | return; |
345 | 346 | } |
346 | 347 |
|
@@ -438,8 +439,8 @@ private Optional<CompactionContext> selectCompaction(HRegion region, HStore stor |
438 | 439 | CompactionLifeCycleTracker tracker, CompactionCompleteTracker completeTracker, User user) |
439 | 440 | throws IOException { |
440 | 441 | // don't even select for compaction if disableCompactions is set to true |
441 | | - if (!isCompactionsEnabled()) { |
442 | | - LOG.info(String.format("User has disabled compactions")); |
| 442 | + if (!isCompactionsEnabled() || isReadOnlyEnabled()) { |
| 443 | + LOG.info(String.format("User has disabled compactions or read-only mode is on")); |
443 | 444 | return Optional.empty(); |
444 | 445 | } |
445 | 446 | Optional<CompactionContext> compaction = store.requestCompaction(priority, tracker, user); |
@@ -856,6 +857,11 @@ public boolean isCompactionsEnabled() { |
856 | 857 | return compactionsEnabled; |
857 | 858 | } |
858 | 859 |
|
| 860 | + private boolean isReadOnlyEnabled() { |
| 861 | + return conf.getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY, |
| 862 | + HConstants.HBASE_GLOBAL_READONLY_ENABLED_DEFAULT); |
| 863 | + } |
| 864 | + |
859 | 865 | public void setCompactionsEnabled(boolean compactionsEnabled) { |
860 | 866 | this.compactionsEnabled = compactionsEnabled; |
861 | 867 | this.conf.setBoolean(HBASE_REGION_SERVER_ENABLE_COMPACTION, compactionsEnabled); |
|
0 commit comments