apache/hadoop · error · IOException
Unable to parse relative time value of {}: unknown time unit
Error message
Unable to parse relative time value of {}: unknown time unit {} What it means
DFSUtil.parseRelativeTime only accepts the lowercase unit suffixes s, m, h and d. If the string parses as a number but its last character is none of these, it throws 'unknown time unit <c>'. Note that a bare number like '100' lands here too, and uppercase units ('7D') are rejected because the endsWith checks are case-sensitive.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java:1702
}
String ttlString = relTime.substring(0, relTime.length()-1);
long ttl;
try {
ttl = Long.parseLong(ttlString);
} catch (NumberFormatException e) {
throw new IOException("Unable to parse relative time value of " + relTime
+ ": " + ttlString + " is not a number");
}
if (relTime.endsWith("s")) {
// pass
} else if (relTime.endsWith("m")) {
ttl *= 60;
} else if (relTime.endsWith("h")) {
ttl *= 60*60;
} else if (relTime.endsWith("d")) {
ttl *= 60*60*24;
} else {
throw new IOException("Unable to parse relative time value of " + relTime
+ ": unknown time unit " + relTime.charAt(relTime.length() - 1));
}
return ttl*1000;
}
/**
* Load HTTPS-related configuration.
*/
public static Configuration loadSslConfiguration(Configuration conf) {
Configuration sslConf = new Configuration(false);
sslConf.addResource(conf.get(
DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY,
DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_DEFAULT));
final String[] reqSslProps = {
DFSConfigKeys.DFS_SERVER_HTTPS_TRUSTSTORE_LOCATION_KEY,
DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_LOCATION_KEY,View on GitHub (pinned to 2add963021)
Solutions
- Use a supported lowercase unit: s, m, h or d (e.g. 10w -> 70d or 168h)
- Append a unit to bare numbers (100 -> 100s)
- Lowercase the suffix (7D -> 7d)
Example fix
// before hdfs cacheadmin -addDirective -ttl 7D // after hdfs cacheadmin -addDirective -ttl 7d
Defensive patterns
Strategy: validation
Validate before calling
import java.util.regex.*;
private static final Pattern REL_TIME = Pattern.compile("^([0-9]+)([smhd])$");
static Long parseTtlSafely(String s) {
Matcher m = REL_TIME.matcher(s == null ? "" : s);
if (!m.matches()) return null; // caller reports a friendly error
long v = Long.parseLong(m.group(1));
switch (m.group(2)) {
case "m": return v * 60 * 1000;
case "h": return v * 3600 * 1000;
case "d": return v * 86400 * 1000;
default: return v * 1000;
}
} Type guard
static boolean isParsableRelativeTime(String s) {
return s != null && s.matches("[0-9]+[smhd]");
} Try / catch
catch (IOException e) around DFSUtil.parseRelativeTime; on 'unknown time unit' surface the accepted suffix list (s, m, h, d, lowercase) to the user.
Prevention
- Remember units are lowercase-only and weeks/years are unsupported - convert w/y to d before passing
- Never pass bare numbers as TTLs
When it happens
Trigger: TTL strings ending in an unsupported character: '10w', '7D', or unitless '100' (its last char '0' is treated as the unit). Reached from `hdfs cacheadmin -addDirective -ttl` and AdminHelper max-ttl parsing.
Common situations: Weeks ('w') or years ('y') entered as units that HDFS does not support; uppercase suffixes; bare integers without any suffix.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse relative time value of {}: too short
- Unable to parse relative time value of {}: {} is not a numbe
- Illegal option {}
- Not enough arguments: expected {} but got {}
- Too many arguments: expected {} but got {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/bec399bdb4e27412.
Report an issue: GitHub.