Skip to content

Commit a96ea52

Browse files
author
Tsz-Wo Nicholas Sze
committed
HDFS-10309 Balancer doesn't honor dfs.blocksize value defined with suffix k(kilo), m(mega), g(giga). Contributed by Amit Anand
1 parent 5245254 commit a96ea52

File tree

1 file changed

+13
-4
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ static long getLong(Configuration conf, String key, long defaultValue) {
230230
return v;
231231
}
232232

233+
static long getLongBytes(Configuration conf, String key, long defaultValue) {
234+
final long v = conf.getLongBytes(key, defaultValue);
235+
LOG.info(key + " = " + v + " (default=" + defaultValue + ")");
236+
if (v <= 0) {
237+
throw new HadoopIllegalArgumentException(key + " = " + v + " <= " + 0);
238+
}
239+
return v;
240+
}
241+
233242
static int getInt(Configuration conf, String key, int defaultValue) {
234243
final int v = conf.getInt(key, defaultValue);
235244
LOG.info(key + " = " + v + " (default=" + defaultValue + ")");
@@ -261,10 +270,10 @@ static int getInt(Configuration conf, String key, int defaultValue) {
261270
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_KEY,
262271
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_DEFAULT);
263272

264-
final long getBlocksSize = getLong(conf,
273+
final long getBlocksSize = getLongBytes(conf,
265274
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_SIZE_KEY,
266275
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_SIZE_DEFAULT);
267-
final long getBlocksMinBlockSize = getLong(conf,
276+
final long getBlocksMinBlockSize = getLongBytes(conf,
268277
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY,
269278
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_DEFAULT);
270279

@@ -279,10 +288,10 @@ static int getInt(Configuration conf, String key, int defaultValue) {
279288
this.sourceNodes = p.getSourceNodes();
280289
this.runDuringUpgrade = p.getRunDuringUpgrade();
281290

282-
this.maxSizeToMove = getLong(conf,
291+
this.maxSizeToMove = getLongBytes(conf,
283292
DFSConfigKeys.DFS_BALANCER_MAX_SIZE_TO_MOVE_KEY,
284293
DFSConfigKeys.DFS_BALANCER_MAX_SIZE_TO_MOVE_DEFAULT);
285-
this.defaultBlockSize = getLong(conf,
294+
this.defaultBlockSize = getLongBytes(conf,
286295
DFSConfigKeys.DFS_BLOCK_SIZE_KEY,
287296
DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT);
288297
}

0 commit comments

Comments
 (0)