Skip to content
Closed
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 @@ -746,6 +746,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
*/
public static final String DFS_NAMENODE_GETBLOCKS_MAX_QPS_KEY = "dfs.namenode.get-blocks.max-qps";
public static final int DFS_NAMENODE_GETBLOCKS_MAX_QPS_DEFAULT = 20;
public static final String DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY
= "dfs.namenode.get-blocks.check.operation";
public static final boolean DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_DEFAULT
= true;

public static final String DFS_BALANCER_MOVEDWINWIDTH_KEY = "dfs.balancer.movedWinWidth";
public static final long DFS_BALANCER_MOVEDWINWIDTH_DEFAULT = 5400*1000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ public static void checkOtherInstanceRunning(boolean toCheck) {

private final BalancerProtocols namenode;
/**
* If set requestToStandby true, Balancer will getBlocks from
* If set getBlocksToStandby true, Balancer will getBlocks from
* Standby NameNode only and it can reduce the performance impact of Active
* NameNode, especially in a busy HA mode cluster.
*/
private boolean requestToStandby;
private boolean getBlocksToStandby;
private String nsId;
private Configuration config;
private final KeyManager keyManager;
Expand Down Expand Up @@ -191,9 +191,9 @@ public NameNodeConnector(String name, URI nameNodeUri, Path idPath,

this.namenode = NameNodeProxies.createProxy(conf, nameNodeUri,
BalancerProtocols.class, fallbackToSimpleAuth).getProxy();
this.requestToStandby = conf.getBoolean(
DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_KEY,
DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_DEFAULT);
this.getBlocksToStandby = !conf.getBoolean(
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY,
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_DEFAULT);
this.config = conf;

this.fs = (DistributedFileSystem)FileSystem.get(nameNodeUri, conf);
Expand Down Expand Up @@ -318,7 +318,7 @@ public DatanodeStorageReport[] getLiveDatanodeStorageReport()
private ProxyPair getProxy() throws IOException {
boolean isRequestStandby = false;
ClientProtocol clientProtocol = null;
if (requestToStandby && nsId != null
if (getBlocksToStandby && nsId != null
&& HAUtil.isHAEnabled(config, nsId)) {
List<ClientProtocol> namenodes =
HAUtil.getProxiesForAllNameNodesInNameservice(config, nsId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ private boolean isClientPortInfoAbsent(CallerContext ctx){
private final int snapshotDiffReportLimit;
private final int blockDeletionIncrement;

/**
* Whether enable checkOperation when call getBlocks.
* It is enabled by default.
*/
private final boolean isGetBlocksCheckOperationEnabled;

/** Interval between each check of lease to release. */
private final long leaseRecheckIntervalMs;
/** Maximum time the lock is hold to release lease. */
Expand Down Expand Up @@ -1066,6 +1072,10 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
Preconditions.checkArgument(blockDeletionIncrement > 0,
DFSConfigKeys.DFS_NAMENODE_BLOCK_DELETION_INCREMENT_KEY +
" must be a positive integer.");
this.isGetBlocksCheckOperationEnabled = conf.getBoolean(
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY,
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_DEFAULT);

} catch(IOException e) {
LOG.error(getClass().getSimpleName() + " initialization failed.", e);
close();
Expand Down Expand Up @@ -1938,10 +1948,13 @@ public boolean isInStandbyState() {
*/
public BlocksWithLocations getBlocks(DatanodeID datanode, long size, long
minimumBlockSize, long timeInterval) throws IOException {
checkOperation(OperationCategory.READ);
OperationCategory checkOp =
isGetBlocksCheckOperationEnabled ? OperationCategory.READ :
OperationCategory.UNCHECKED;
checkOperation(checkOp);
readLock();
try {
checkOperation(OperationCategory.READ);
checkOperation(checkOp);
return getBlockManager().getBlocksWithLocations(datanode, size,
minimumBlockSize, timeInterval);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,14 @@
Mover, and StoragePolicySatisfier.
</description>
</property>
<property>
<name>dfs.namenode.get-blocks.check.operation</name>
<value>true</value>
<description>
Set false to disable checkOperation and getBlocks for Balancer
will route to Standby NameNode for HA mode setup.
</description>
</property>
<property>
<name>dfs.balancer.dispatcherThreads</name>
<value>200</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package org.apache.hadoop.hdfs.server.balancer;

import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -146,8 +144,9 @@ void doTest(Configuration conf, boolean withHA) throws Exception {
TestBalancer.createFile(cluster, TestBalancer.filePath, totalUsedSpace
/ numOfDatanodes, (short) numOfDatanodes, 0);

boolean isRequestStandby = conf.getBoolean(
DFS_HA_ALLOW_STALE_READ_KEY, DFS_HA_ALLOW_STALE_READ_DEFAULT);
boolean isRequestStandby = !conf.getBoolean(
DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY,
DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_DEFAULT);
if (isRequestStandby) {
HATestUtil.waitForStandbyToCatchUp(cluster.getNameNode(0),
cluster.getNameNode(1));
Expand Down Expand Up @@ -182,7 +181,7 @@ void doTest(Configuration conf, boolean withHA) throws Exception {
@Test(timeout = 60000)
public void testBalancerRequestSBNWithHA() throws Exception {
Configuration conf = new HdfsConfiguration();
conf.setBoolean(DFS_HA_ALLOW_STALE_READ_KEY, true);
conf.setBoolean(DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY, false);
conf.setLong(DFS_HA_TAILEDITS_PERIOD_KEY, 1);
//conf.setBoolean(DFS_HA_BALANCER_REQUEST_STANDBY_KEY, true);
TestBalancer.initConf(conf);
Expand Down Expand Up @@ -329,8 +328,8 @@ nsId, new Path("/test"),
nncActive.close();

// Request to standby namenode.
conf.setBoolean(DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_KEY,
true);
conf.setBoolean(DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY,
false);
NameNodeConnector nncStandby = new NameNodeConnector(
"nncStandby", namenode,
nsId, new Path("/test"),
Expand Down