Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -46,16 +46,19 @@
import org.apache.hadoop.hbase.conf.ConfigurationManager;
import org.apache.hadoop.hbase.conf.ConfigurationObserver;
import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.executor.ExecutorService;
import org.apache.hadoop.hbase.fs.HFileSystem;
import org.apache.hadoop.hbase.http.InfoServer;
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.MasterCoprocessorHost;
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.RegionServerCoprocessorHost;
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 @@ -184,14 +187,14 @@ public abstract class HBaseServerBase<R extends HBaseRpcServicesBase<?>> extends

protected final NettyEventLoopGroupConfig eventLoopGroupConfig;

/**
* If running on Windows, do windows-specific setup.
*/
private static void setupWindows(final Configuration conf, ConfigurationManager cm) {
private void setupSignalHandlers() {
if (!SystemUtils.IS_OS_WINDOWS) {
HBasePlatformDependent.handle("HUP", (number, name) -> {
conf.reloadConfiguration();
cm.notifyAllObservers(conf);
try {
updateConfiguration();
} catch (IOException e) {
LOG.error("Problem while reloading configuration", e);
}
});
}
}
Expand Down Expand Up @@ -276,7 +279,7 @@ public HBaseServerBase(Configuration conf, String name) throws IOException {
new ZKWatcher(conf, getProcessName() + ":" + addr.getPort(), this, canCreateBaseZNode());

this.configurationManager = new ConfigurationManager();
setupWindows(conf, configurationManager);
setupSignalHandlers();

initializeFileSystem();

Expand Down Expand Up @@ -614,18 +617,40 @@ 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 {
CoprocessorHost<?, ?> coprocessorHost = getCoprocessorHost();
if (coprocessorHost instanceof RegionServerCoprocessorHost) {
((RegionServerCoprocessorHost) coprocessorHost).preUpdateConfiguration(conf);
} else if (coprocessorHost instanceof MasterCoprocessorHost) {
((MasterCoprocessorHost) coprocessorHost).preUpdateConfiguration(conf);
}
}

private void postUpdateConfiguration() throws IOException {
CoprocessorHost<?, ?> coprocessorHost = getCoprocessorHost();
if (coprocessorHost instanceof RegionServerCoprocessorHost) {
((RegionServerCoprocessorHost) coprocessorHost).postUpdateConfiguration(conf);
} else if (coprocessorHost instanceof MasterCoprocessorHost) {
((MasterCoprocessorHost) coprocessorHost).postUpdateConfiguration(conf);
}
}

@Override
public String toString() {
return getServerName().toString();
}

protected abstract CoprocessorHost<?, ?> getCoprocessorHost();

protected abstract boolean canCreateBaseZNode();

protected abstract String getProcessName();
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,24 @@ default void preHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment>
default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
String userName, List<Permission> permissions) throws IOException {
}

/**
* Called before reloading the HMaster's {@link Configuration} from disk
* @param ctx the coprocessor instance's environment
* @param preReloadConf the {@link Configuration} in use prior to reload
* @throws IOException if you need to signal an IO error
*/
default void preUpdateMasterConfiguration(ObserverContext<MasterCoprocessorEnvironment> ctx,
Configuration preReloadConf) throws IOException {
}

/**
* Called after reloading the HMaster's {@link Configuration} from disk
* @param ctx the coprocessor instance's environment
* @param postReloadConf the {@link Configuration} that was loaded
* @throws IOException if you need to signal an IO error
*/
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,45 @@ default void postReplicationSinkBatchMutate(

}

/**
* Called before clearing the block caches for one or more regions
* @param ctx the coprocessor instance's environment
* @throws IOException if you need to signal an IO error
*/
default void preClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> ctx)
throws IOException {
}

/**
* Called after clearing the block caches for one or more regions
* @param ctx the coprocessor instance's environment
* @param stats statistics about the cache evictions that happened
* @throws IOException if you need to signal an IO error
*/
default void postClearRegionBlockCache(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
CacheEvictionStats stats) throws IOException {
}

/**
* Called before reloading the RegionServer's {@link Configuration} from disk
* @param ctx the coprocessor instance's environment
* @param preReloadConf the {@link Configuration} in use prior to reload
* @throws IOException if you need to signal an IO error
*/
default void preUpdateRegionServerConfiguration(
ObserverContext<RegionServerCoprocessorEnvironment> ctx, Configuration preReloadConf)
throws IOException {
}

/**
* Called after reloading the RegionServer's {@link Configuration} from disk
* @param ctx the coprocessor instance's environment
* @param postReloadConf the {@link Configuration} that was loaded
* @throws IOException if you need to signal an IO error
*/
default void postUpdateRegionServerConfiguration(
ObserverContext<RegionServerCoprocessorEnvironment> ctx, Configuration postReloadConf)
throws IOException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,11 @@ public MasterRpcServices getMasterRpcServices() {
return rpcServices;
}

@Override
protected MasterCoprocessorHost getCoprocessorHost() {
return getMasterCoprocessorHost();
}

public boolean balanceSwitch(final boolean b) throws IOException {
return getMasterRpcServices().switchBalancer(b, BalanceSwitchMode.ASYNC);
}
Expand Down
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 @@ -587,6 +587,11 @@ protected String getProcessName() {
return REGIONSERVER;
}

@Override
protected RegionServerCoprocessorHost getCoprocessorHost() {
return getRegionServerCoprocessorHost();
}

@Override
protected boolean canCreateBaseZNode() {
return !clusterMode();
Expand Down
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);
}

}
Loading