HBASE-20163 Forbid major compaction when standby cluster replay the remote wals

This commit is contained in:
Guanghao Zhang 2018-04-12 14:44:25 +08:00 committed by zhangduo
parent 2389c09d75
commit d57c80c415
6 changed files with 80 additions and 1 deletions

View File

@ -144,6 +144,7 @@ import org.apache.hadoop.hbase.regionserver.ScannerContext.LimitScope;
import org.apache.hadoop.hbase.regionserver.ScannerContext.NextState;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
import org.apache.hadoop.hbase.regionserver.compactions.ForbidMajorCompactionChecker;
import org.apache.hadoop.hbase.regionserver.throttle.CompactionThroughputControllerFactory;
import org.apache.hadoop.hbase.regionserver.throttle.NoLimitThroughputController;
import org.apache.hadoop.hbase.regionserver.throttle.StoreHotnessProtector;
@ -1992,6 +1993,14 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
return compact(compaction, store, throughputController, null);
}
private boolean shouldForbidMajorCompaction() {
if (rsServices != null && rsServices.getReplicationSourceService() != null) {
return rsServices.getReplicationSourceService().getSyncReplicationPeerInfoProvider()
.checkState(getRegionInfo(), ForbidMajorCompactionChecker.get());
}
return false;
}
public boolean compact(CompactionContext compaction, HStore store,
ThroughputController throughputController, User user) throws IOException {
assert compaction != null && compaction.hasSelection();
@ -2001,6 +2010,15 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
store.cancelRequestedCompaction(compaction);
return false;
}
if (compaction.getRequest().isAllFiles() && shouldForbidMajorCompaction()) {
LOG.warn("Skipping major compaction on " + this
+ " because this cluster is transiting sync replication state"
+ " from STANDBY to DOWNGRADE_ACTIVE");
store.cancelRequestedCompaction(compaction);
return false;
}
MonitoredTask status = null;
boolean requestNeedsCancellation = true;
/*

View File

@ -2475,7 +2475,7 @@ public class HRegionServer extends HasThread implements
* @return Return the object that implements the replication
* source executorService.
*/
@VisibleForTesting
@Override
public ReplicationSourceService getReplicationSourceService() {
return replicationSourceHandler;
}

View File

@ -262,4 +262,9 @@ public interface RegionServerServices extends Server, MutableOnlineRegions, Favo
* @return True if cluster is up; false if cluster is not up (we are shutting down).
*/
boolean isClusterUp();
/**
* @return Return the object that implements the replication source executorService.
*/
ReplicationSourceService getReplicationSourceService();
}

View File

@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.regionserver.compactions;
import java.util.function.BiPredicate;
import org.apache.hadoop.hbase.replication.SyncReplicationState;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Check whether forbid major compaction for region.
*/
@InterfaceAudience.Private
public class ForbidMajorCompactionChecker
implements BiPredicate<SyncReplicationState, SyncReplicationState> {
private static final ForbidMajorCompactionChecker INST = new ForbidMajorCompactionChecker();
@Override
public boolean test(SyncReplicationState state, SyncReplicationState newState) {
// Forbid major compaction when cluster transit sync replication state from S to DA
return state == SyncReplicationState.STANDBY
|| newState == SyncReplicationState.DOWNGRADE_ACTIVE;
}
public static ForbidMajorCompactionChecker get() {
return INST;
}
}

View File

@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.regionserver.MetricsRegionServer;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.regionserver.ReplicationSourceService;
import org.apache.hadoop.hbase.regionserver.SecureBulkLoadManager;
import org.apache.hadoop.hbase.regionserver.ServerNonceManager;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester;
@ -353,4 +354,9 @@ public class MockRegionServerServices implements RegionServerServices {
public boolean isClusterUp() {
return true;
}
@Override
public ReplicationSourceService getReplicationSourceService() {
return null;
}
}

View File

@ -61,6 +61,7 @@ import org.apache.hadoop.hbase.regionserver.MetricsRegionServer;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.regionserver.ReplicationSourceService;
import org.apache.hadoop.hbase.regionserver.SecureBulkLoadManager;
import org.apache.hadoop.hbase.regionserver.ServerNonceManager;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester;
@ -696,4 +697,9 @@ ClientProtos.ClientService.BlockingInterface, RegionServerServices {
public boolean isClusterUp() {
return true;
}
@Override
public ReplicationSourceService getReplicationSourceService() {
return null;
}
}