Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
import org.apache.hadoop.hbase.io.util.MemorySizeUtil;
import org.apache.hadoop.hbase.ipc.RpcServerInterface;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.master.MasterRpcServices;
import org.apache.hadoop.hbase.namequeues.NamedQueueRecorder;
import org.apache.hadoop.hbase.regionserver.ChunkCreator;
import org.apache.hadoop.hbase.regionserver.HeapMemoryManager;
import org.apache.hadoop.hbase.regionserver.MemStoreLAB;
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.regionserver.ShutdownHook;
import org.apache.hadoop.hbase.security.Superusers;
import org.apache.hadoop.hbase.security.User;
Expand Down Expand Up @@ -614,11 +616,41 @@ public ConfigurationManager getConfigurationManager() {
/**
* Reload the configuration from disk.
*/
public void updateConfiguration() {
public void updateConfiguration() throws IOException {
LOG.info("Reloading the configuration from disk.");
// Reload the configuration from disk.
preUpdateConfiguration();
conf.reloadConfiguration();
configurationManager.notifyAllObservers(conf);
postUpdateConfiguration();
}

private void preUpdateConfiguration() throws IOException {
if (rpcServices instanceof RSRpcServices && rpcServices.server != null) {
RSRpcServices rsRpcServices = (RSRpcServices) rpcServices;
if (rsRpcServices.server.getRegionServerCoprocessorHost() != null) {
rsRpcServices.server.getRegionServerCoprocessorHost().preUpdateConfiguration(conf);
}
} else if (rpcServices instanceof MasterRpcServices && rpcServices.server != null) {
MasterRpcServices masterRpcServices = (MasterRpcServices) rpcServices;
if (masterRpcServices.server.getMasterCoprocessorHost() != null) {
masterRpcServices.server.getMasterCoprocessorHost().preUpdateConfiguration(conf);
}
}
}

private void postUpdateConfiguration() throws IOException {
if (rpcServices instanceof RSRpcServices && rpcServices.server != null) {
RSRpcServices rsRpcServices = (RSRpcServices) rpcServices;
if (rsRpcServices.server.getRegionServerCoprocessorHost() != null) {
rsRpcServices.server.getRegionServerCoprocessorHost().postUpdateConfiguration(conf);
}
} else if (rpcServices instanceof MasterRpcServices && rpcServices.server != null) {
MasterRpcServices masterRpcServices = (MasterRpcServices) rpcServices;
if (masterRpcServices.server.getMasterCoprocessorHost() != null) {
masterRpcServices.server.getMasterCoprocessorHost().postUpdateConfiguration(conf);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.MetaMutationAnnotation;
Expand Down Expand Up @@ -1873,4 +1874,12 @@ default void preHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment>
default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
String userName, List<Permission> permissions) throws IOException {
}

default void preUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration preReloadConf) throws IOException {
}

default void postUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration postReloadConf) throws IOException {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.hadoop.hbase.coprocessor;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CacheEvictionStats;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
Expand Down Expand Up @@ -169,4 +171,22 @@ default void postReplicationSinkBatchMutate(

}

default void preClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> ctx)
throws IOException {
}

default void postClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
CacheEvictionStats stats) throws IOException {
}

default void preUpdateRegionServerConfiguration(
ObserverContext<RegionServerCoprocessorEnvironment> ctx, Configuration preReloadConf)
throws IOException {
}

default void postUpdateRegionServerConfiguration(
ObserverContext<RegionServerCoprocessorEnvironment> ctx, Configuration postReloadConf)
throws IOException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2114,4 +2114,22 @@ public void call(MasterObserver observer) throws IOException {
}
});
}

public void preUpdateConfiguration(Configuration preReloadConf) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preUpdateMasterConfiguration(this, preReloadConf);
}
});
}

public void postUpdateConfiguration(Configuration postReloadConf) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postUpdateMasterConfiguration(this, postReloadConf);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3802,19 +3802,25 @@ public GetSpaceQuotaSnapshotsResponse getSpaceQuotaSnapshots(RpcController contr
@Override
public ClearRegionBlockCacheResponse clearRegionBlockCache(RpcController controller,
ClearRegionBlockCacheRequest request) throws ServiceException {
rpcPreCheck("clearRegionBlockCache");
ClearRegionBlockCacheResponse.Builder builder = ClearRegionBlockCacheResponse.newBuilder();
CacheEvictionStatsBuilder stats = CacheEvictionStats.builder();
List<HRegion> regions = getRegions(request.getRegionList(), stats);
for (HRegion region : regions) {
try {
stats = stats.append(this.server.clearRegionBlockCache(region));
} catch (Exception e) {
stats.addException(region.getRegionInfo().getRegionName(), e);
try {
rpcPreCheck("clearRegionBlockCache");
ClearRegionBlockCacheResponse.Builder builder = ClearRegionBlockCacheResponse.newBuilder();
CacheEvictionStatsBuilder stats = CacheEvictionStats.builder();
server.getRegionServerCoprocessorHost().preClearRegionBlockCache();
List<HRegion> regions = getRegions(request.getRegionList(), stats);
for (HRegion region : regions) {
try {
stats = stats.append(this.server.clearRegionBlockCache(region));
} catch (Exception e) {
stats.addException(region.getRegionInfo().getRegionName(), e);
}
}
stats.withMaxCacheSize(server.getBlockCache().map(BlockCache::getMaxSize).orElse(0L));
server.getRegionServerCoprocessorHost().postClearRegionBlockCache(stats.build());
return builder.setStats(ProtobufUtil.toCacheEvictionStats(stats.build())).build();
} catch (IOException e) {
throw new ServiceException(e);
}
stats.withMaxCacheSize(server.getBlockCache().map(BlockCache::getMaxSize).orElse(0L));
return builder.setStats(ProtobufUtil.toCacheEvictionStats(stats.build())).build();
}

private void executeOpenRegionProcedures(OpenRegionRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CacheEvictionStats;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Mutation;
Expand Down Expand Up @@ -240,6 +241,42 @@ public void call(RegionServerObserver observer) throws IOException {
});
}

public void preUpdateConfiguration(Configuration preReloadConf) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new RegionServerObserverOperation() {
@Override
public void call(RegionServerObserver observer) throws IOException {
observer.preUpdateRegionServerConfiguration(this, preReloadConf);
}
});
}

public void postUpdateConfiguration(Configuration postReloadConf) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new RegionServerObserverOperation() {
@Override
public void call(RegionServerObserver observer) throws IOException {
observer.postUpdateRegionServerConfiguration(this, postReloadConf);
}
});
}

public void preClearRegionBlockCache() throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new RegionServerObserverOperation() {
@Override
public void call(RegionServerObserver observer) throws IOException {
observer.preClearRegionBlockCache(this);
}
});
}

public void postClearRegionBlockCache(CacheEvictionStats stats) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new RegionServerObserverOperation() {
@Override
public void call(RegionServerObserver observer) throws IOException {
observer.postClearRegionBlockCache(this, stats);
}
});
}

/**
* Coprocessor environment extension providing access to region server related services.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2576,4 +2576,27 @@ public void preUpdateRSGroupConfig(final ObserverContext<MasterCoprocessorEnviro
accessChecker.requirePermission(getActiveUser(ctx), "updateRSGroupConfig", null,
Permission.Action.ADMIN);
}

@Override
public void preClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> ctx)
throws IOException {
accessChecker.requirePermission(getActiveUser(ctx), "clearRegionBlockCache", null,
Permission.Action.ADMIN);
}

@Override
public void preUpdateRegionServerConfiguration(
ObserverContext<RegionServerCoprocessorEnvironment> ctx, Configuration preReloadConf)
throws IOException {
accessChecker.requirePermission(getActiveUser(ctx), "updateConfiguration", null,
Permission.Action.ADMIN);
}

@Override
public void preUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration preReloadConf) throws IOException {
accessChecker.requirePermission(getActiveUser(ctx), "updateConfiguration", null,
Permission.Action.ADMIN);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public static class CPMasterObserver implements MasterCoprocessor, MasterObserve
private boolean postLockHeartbeatCalled;
private boolean preMasterStoreFlushCalled;
private boolean postMasterStoreFlushCalled;
private boolean preUpdateMasterConfigurationCalled;
private boolean postUpdateMasterConfigurationCalled;

public void resetStates() {
preCreateTableRegionInfosCalled = false;
Expand Down Expand Up @@ -284,6 +286,8 @@ public void resetStates() {
postLockHeartbeatCalled = false;
preMasterStoreFlushCalled = false;
postMasterStoreFlushCalled = false;
preUpdateMasterConfigurationCalled = false;
postUpdateMasterConfigurationCalled = false;
}

@Override
Expand Down Expand Up @@ -1264,6 +1268,17 @@ public void postRollBackMergeRegionsAction(
throws IOException {
}

@Override
public void preUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration preReloadConf) throws IOException {
preUpdateMasterConfigurationCalled = true;
}

@Override
public void postUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration postReloadConf) throws IOException {
postUpdateMasterConfigurationCalled = true;
}
}

private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
Expand Down Expand Up @@ -1715,4 +1730,23 @@ public void testMasterStoreOperations() throws Exception {
assertTrue("Master store flush called", cp.postMasterStoreFlushCalled);
}
}

@Test
public void testUpdateConfiguration() throws Exception {
SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
cp.resetStates();
assertFalse("No update configuration call", cp.preUpdateMasterConfigurationCalled);
assertFalse("No update configuration call", cp.postUpdateMasterConfigurationCalled);

try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.updateConfiguration();

assertTrue("Update configuration called", cp.preUpdateMasterConfigurationCalled);
assertTrue("Update configuration called", cp.postUpdateMasterConfigurationCalled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,41 @@ public Object run() throws Exception {
verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER);
}

@Test
public void testUpdateMasterConfiguration() throws Exception {
AccessTestAction action = () -> {
ACCESS_CONTROLLER.preUpdateMasterConfiguration(ObserverContextImpl.createAndPrepare(CP_ENV),
null);
return null;
};

verifyAllowed(action, SUPERUSER, USER_ADMIN);
verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER);
}

@Test
public void testUpdateRegionServerConfiguration() throws Exception {
AccessTestAction action = () -> {
ACCESS_CONTROLLER
.preUpdateRegionServerConfiguration(ObserverContextImpl.createAndPrepare(RSCP_ENV), null);
return null;
};

verifyAllowed(action, SUPERUSER, USER_ADMIN);
verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER);
}

@Test
public void testClearRegionBlockCache() throws Exception {
AccessTestAction action = () -> {
ACCESS_CONTROLLER.preClearRegionBlockCache(ObserverContextImpl.createAndPrepare(RSCP_ENV));
return null;
};

verifyAllowed(action, SUPERUSER, USER_ADMIN);
verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_OWNER);
}

@Test
public void testTransitSyncReplicationPeerState() throws Exception {
AccessTestAction action = new AccessTestAction() {
Expand Down