Skip to content

Commit e7cb788

Browse files
committed
HBASE-29644: Refresh_meta triggering compaction on user table
Link to JIRA: https://issues.apache.org/jira/browse/HBASE-29644 Description: Consider the two cluster setup with one being active and one read replica. If active cluster create a table with FILE based SFT. If you add few rows through active and do flushes to create few Hfiles and then do refresh_meta from read replica its triggering minor compaction. Which should not happen via read replica, it may create inconsitencies because active is not aware of that event. Cause: This is happening because we should block the compaction event in ReadOnlyController but we missed adding read only guard to preCompactSelection() function. Fix: Add internalReadOnlyGuard to preCompactSelection() in ReadOnlyController
1 parent 365f16e commit e7cb788

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.concurrent.atomic.AtomicInteger;
3737
import java.util.function.IntSupplier;
3838
import org.apache.hadoop.conf.Configuration;
39+
import org.apache.hadoop.hbase.HConstants;
3940
import org.apache.hadoop.hbase.client.RegionInfo;
4041
import org.apache.hadoop.hbase.conf.ConfigurationManager;
4142
import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver;
@@ -339,8 +340,8 @@ private void requestCompactionInternal(HRegion region, String why, int priority,
339340
protected void requestCompactionInternal(HRegion region, HStore store, String why, int priority,
340341
boolean selectNow, CompactionLifeCycleTracker tracker,
341342
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.");
344345
return;
345346
}
346347

@@ -438,8 +439,8 @@ private Optional<CompactionContext> selectCompaction(HRegion region, HStore stor
438439
CompactionLifeCycleTracker tracker, CompactionCompleteTracker completeTracker, User user)
439440
throws IOException {
440441
// 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"));
443444
return Optional.empty();
444445
}
445446
Optional<CompactionContext> compaction = store.requestCompaction(priority, tracker, user);
@@ -856,6 +857,11 @@ public boolean isCompactionsEnabled() {
856857
return compactionsEnabled;
857858
}
858859

860+
private boolean isReadOnlyEnabled() {
861+
return conf.getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
862+
HConstants.HBASE_GLOBAL_READONLY_ENABLED_DEFAULT);
863+
}
864+
859865
public void setCompactionsEnabled(boolean compactionsEnabled) {
860866
this.compactionsEnabled = compactionsEnabled;
861867
this.conf.setBoolean(HBASE_REGION_SERVER_ENABLE_COMPACTION, compactionsEnabled);

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/StoreFileTrackerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private HFileContext createFileContext(Compression.Algorithm compression,
143143
public final StoreFileWriter createWriter(CreateStoreFileWriterParams params) throws IOException {
144144
if (!isPrimaryReplica || isReadOnlyEnabled()) {
145145
throw new IllegalStateException(
146-
"Should not call create writer on secondary replicas or in read only mode");
146+
"Should not call create writer on secondary replicas or in read-only mode");
147147
}
148148
// creating new cache config for each new writer
149149
final CacheConfig cacheConf = ctx.getCacheConf();

hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/ReadOnlyController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
import org.apache.hadoop.hbase.filter.Filter;
5454
import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker;
5555
import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
56+
import org.apache.hadoop.hbase.regionserver.Store;
57+
import org.apache.hadoop.hbase.regionserver.StoreFile;
58+
import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
5659
import org.apache.hadoop.hbase.util.Pair;
5760
import org.apache.hadoop.hbase.wal.WALEdit;
5861
import org.apache.yetus.audience.InterfaceAudience;
@@ -81,6 +84,7 @@ private void internalReadOnlyGuard() throws IOException {
8184

8285
@Override
8386
public void start(CoprocessorEnvironment env) throws IOException {
87+
8488
this.globalReadOnlyEnabled =
8589
env.getConfiguration().getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
8690
HConstants.HBASE_GLOBAL_READONLY_ENABLED_DEFAULT);
@@ -131,6 +135,13 @@ public void preFlush(final ObserverContext<? extends RegionCoprocessorEnvironmen
131135
internalReadOnlyGuard();
132136
}
133137

138+
@Override
139+
public void preCompactSelection(ObserverContext<? extends RegionCoprocessorEnvironment> c,
140+
Store store, List<? extends StoreFile> candidates, CompactionLifeCycleTracker tracker)
141+
throws IOException {
142+
internalReadOnlyGuard();
143+
}
144+
134145
@Override
135146
public boolean preCheckAndPut(ObserverContext<? extends RegionCoprocessorEnvironment> c,
136147
byte[] row, byte[] family, byte[] qualifier, CompareOperator op, ByteArrayComparable comparator,

0 commit comments

Comments
 (0)