HDFS-12085. Reconfigure namenode heartbeat interval fails if the interval was set with time unit. Contributed by Weiwei Yang.

This commit is contained in:
Yiqun Lin 2017-07-11 20:40:11 +08:00
parent 34f113df5c
commit 3a7f02b815
3 changed files with 24 additions and 2 deletions

View File

@ -1667,7 +1667,15 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
}
}
private long getTimeDurationHelper(String name, String vStr, TimeUnit unit) {
/**
* Return time duration in the given time unit. Valid units are encoded in
* properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds
* (ms), seconds (s), minutes (m), hours (h), and days (d).
* @param name Property name
* @param vStr The string value with time unit suffix to be converted.
* @param unit Unit to convert the stored property, if it exists.
*/
public long getTimeDurationHelper(String name, String vStr, TimeUnit unit) {
vStr = vStr.trim();
vStr = StringUtils.toLowerCase(vStr);
ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr);

View File

@ -2050,7 +2050,10 @@ public class NameNode extends ReconfigurableBase implements
datanodeManager.setHeartbeatInterval(DFS_HEARTBEAT_INTERVAL_DEFAULT);
return String.valueOf(DFS_HEARTBEAT_INTERVAL_DEFAULT);
} else {
datanodeManager.setHeartbeatInterval(Long.parseLong(newVal));
long newInterval = getConf()
.getTimeDurationHelper(DFS_HEARTBEAT_INTERVAL_KEY,
newVal, TimeUnit.SECONDS);
datanodeManager.setHeartbeatInterval(newInterval);
return String.valueOf(datanodeManager.getHeartbeatInterval());
}
} catch (NumberFormatException nfe) {

View File

@ -182,6 +182,17 @@ public class TestNameNodeReconfigure {
+ " has wrong value", 10 * 60 * 1000,
datanodeManager.getHeartbeatRecheckInterval());
// change to a value with time unit
nameNode.reconfigureProperty(DFS_HEARTBEAT_INTERVAL_KEY, "1m");
assertEquals(
DFS_HEARTBEAT_INTERVAL_KEY + " has wrong value",
60,
nameNode.getConf().getLong(DFS_HEARTBEAT_INTERVAL_KEY,
DFS_HEARTBEAT_INTERVAL_DEFAULT));
assertEquals(DFS_HEARTBEAT_INTERVAL_KEY + " has wrong value", 60,
datanodeManager.getHeartbeatInterval());
// revert to defaults
nameNode.reconfigureProperty(DFS_HEARTBEAT_INTERVAL_KEY, null);
nameNode.reconfigureProperty(DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY,