Skip to content

Commit aecfcf1

Browse files
HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid. (#3185)
* HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid * HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid * HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid * HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid * HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid Co-authored-by: jiaguodong5 <[email protected]>
1 parent fa0289b commit aecfcf1

4 files changed

Lines changed: 59 additions & 5 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
735735
public static final String DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_KEY =
736736
"dfs.balancer.getBlocks.hot-time-interval";
737737
public static final long DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_DEFAULT =
738-
0;
738+
0L;
739739
public static final String DFS_BALANCER_KEYTAB_ENABLED_KEY = "dfs.balancer.keytab.enabled";
740740
public static final boolean DFS_BALANCER_KEYTAB_ENABLED_DEFAULT = false;
741741
public static final String DFS_BALANCER_ADDRESS_KEY = "dfs.balancer.address";

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Balancer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ static int getFailedTimesSinceLastSuccessfulBalance() {
324324
* Balancer prefer to get blocks which are belong to the cold files
325325
* created before this time period.
326326
*/
327-
final long hotBlockTimeInterval = conf.getTimeDuration(
328-
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_KEY,
329-
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_DEFAULT,
330-
TimeUnit.MILLISECONDS);
327+
final long hotBlockTimeInterval =
328+
p.getHotBlockTimeInterval() != 0L ? p.getHotBlockTimeInterval() :
329+
conf.getTimeDuration(
330+
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_KEY,
331+
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_HOT_TIME_INTERVAL_DEFAULT,
332+
TimeUnit.MILLISECONDS);
331333

332334
// DataNode configuration parameters for balancing
333335
final int maxConcurrentMovesPerNode = getInt(conf,

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerParameters.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ boolean getSortTopNodes() {
110110
return this.sortTopNodes;
111111
}
112112

113+
long getHotBlockTimeInterval() {
114+
return this.hotBlockTimeInterval;
115+
}
116+
113117
@Override
114118
public String toString() {
115119
return String.format("%s.%s [%s," + " threshold = %s,"

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY;
3939
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY;
4040

41+
import java.lang.reflect.Field;
4142
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
4243
import org.junit.AfterClass;
4344
import static org.junit.Assert.assertEquals;
@@ -67,6 +68,7 @@
6768
import java.util.concurrent.atomic.AtomicLong;
6869

6970
import org.apache.commons.lang3.StringUtils;
71+
import org.junit.Assert;
7072
import org.junit.Before;
7173
import org.slf4j.Logger;
7274
import org.slf4j.LoggerFactory;
@@ -1219,6 +1221,52 @@ public void testBalancerCliParseBlockpools() {
12191221
assertEquals(1, p.getBlockPools().size());
12201222
}
12211223

1224+
@Test
1225+
public void testBalancerCliParseHotBlockTimeInterval() {
1226+
String[] parameters = new String[]{"-hotBlockTimeInterval", "1000"};
1227+
BalancerParameters p = Balancer.Cli.parse(parameters);
1228+
assertEquals(1000, p.getHotBlockTimeInterval());
1229+
}
1230+
1231+
@Test
1232+
public void testBalancerDispatchHotBlockTimeInterval() {
1233+
String[] parameters = new String[]{"-hotBlockTimeInterval", "1000"};
1234+
BalancerParameters p = Balancer.Cli.parse(parameters);
1235+
Configuration conf = new HdfsConfiguration();
1236+
initConf(conf);
1237+
try {
1238+
cluster = new MiniDFSCluster
1239+
.Builder(conf)
1240+
.numDataNodes(0)
1241+
.setNNRedundancyConsiderLoad(false)
1242+
.build();
1243+
cluster.getConfiguration(0).setInt(DFSConfigKeys.DFS_REPLICATION_KEY,
1244+
DFSConfigKeys.DFS_REPLICATION_DEFAULT);
1245+
conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY,
1246+
DFSConfigKeys.DFS_REPLICATION_DEFAULT);
1247+
cluster.waitClusterUp();
1248+
cluster.waitActive();
1249+
Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
1250+
List<NameNodeConnector> connectors =
1251+
NameNodeConnector.newNameNodeConnectors(namenodes,
1252+
Balancer.class.getSimpleName(),
1253+
Balancer.BALANCER_ID_PATH, conf,
1254+
BalancerParameters.DEFAULT.getMaxIdleIteration());
1255+
Balancer run = new Balancer(
1256+
connectors.get(0), p, new HdfsConfiguration());
1257+
Field field = run.getClass().getDeclaredField("dispatcher");
1258+
field.setAccessible(true);
1259+
Object dispatcher = field.get(run);
1260+
Field field1 =
1261+
dispatcher.getClass().getDeclaredField("hotBlockTimeInterval");
1262+
field1.setAccessible(true);
1263+
Object hotBlockTimeInterval = field1.get(dispatcher);
1264+
assertEquals(1000, (long)hotBlockTimeInterval);
1265+
} catch (Exception e) {
1266+
Assert.fail(e.getMessage());
1267+
}
1268+
}
1269+
12221270
/**
12231271
* Verify balancer exits 0 on success.
12241272
*/

0 commit comments

Comments
 (0)