Returns the unused byte capacity of an HDFS filesystem. This value does not take into account a replication factor, as that can vary from file to file. Thus if you are using this to determine if you data set will fit in the HDFS, you need to divide the result of this call by your specific replicatio
()
| 1208 | * @throws IOException |
| 1209 | */ |
| 1210 | public long capacity() throws IOException { |
| 1211 | if (pigContext.getExecType().isLocal()) { |
| 1212 | throw new IOException("capacity only supported for non-local execution"); |
| 1213 | } |
| 1214 | else { |
| 1215 | DataStorage dds = pigContext.getDfs(); |
| 1216 | |
| 1217 | Map<String, Object> stats = dds.getStatistics(); |
| 1218 | |
| 1219 | String rawCapacityStr = (String) stats.get(DataStorage.RAW_CAPACITY_KEY); |
| 1220 | String rawUsedStr = (String) stats.get(DataStorage.RAW_USED_KEY); |
| 1221 | |
| 1222 | if ((rawCapacityStr == null) || (rawUsedStr == null)) { |
| 1223 | throw new IOException("Failed to retrieve capacity stats"); |
| 1224 | } |
| 1225 | |
| 1226 | long rawCapacityBytes = new Long(rawCapacityStr).longValue(); |
| 1227 | long rawUsedBytes = new Long(rawUsedStr).longValue(); |
| 1228 | |
| 1229 | return rawCapacityBytes - rawUsedBytes; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Returns the length of a file in bytes which exists in the HDFS (accounts for replication). |