HADOOP-6283. Improve the exception messages thrown by FileUtil$HardLink.getLinkCount(..).
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@823263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
64f537da0a
commit
710d517768
@ -12,6 +12,9 @@ Trunk (unreleased changes)
|
|||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
|
|
||||||
|
HADOOP-6283. Improve the exception messages thrown by
|
||||||
|
FileUtil$HardLink.getLinkCount(..). (szetszwo)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -628,14 +628,18 @@ public static void createHardLink(File target,
|
|||||||
* Retrieves the number of links to the specified file.
|
* Retrieves the number of links to the specified file.
|
||||||
*/
|
*/
|
||||||
public static int getLinkCount(File fileName) throws IOException {
|
public static int getLinkCount(File fileName) throws IOException {
|
||||||
|
if (!fileName.exists()) {
|
||||||
|
throw new FileNotFoundException(fileName + " not found.");
|
||||||
|
}
|
||||||
|
|
||||||
int len = getLinkCountCommand.length;
|
int len = getLinkCountCommand.length;
|
||||||
String[] cmd = new String[len + 1];
|
String[] cmd = new String[len + 1];
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
cmd[i] = getLinkCountCommand[i];
|
cmd[i] = getLinkCountCommand[i];
|
||||||
}
|
}
|
||||||
cmd[len] = fileName.toString();
|
cmd[len] = fileName.toString();
|
||||||
String inpMsg = "";
|
String inpMsg = null;
|
||||||
String errMsg = "";
|
String errMsg = null;
|
||||||
int exitValue = -1;
|
int exitValue = -1;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
BufferedReader err = null;
|
BufferedReader err = null;
|
||||||
@ -647,14 +651,11 @@ public static int getLinkCount(File fileName) throws IOException {
|
|||||||
in = new BufferedReader(new InputStreamReader(
|
in = new BufferedReader(new InputStreamReader(
|
||||||
process.getInputStream()));
|
process.getInputStream()));
|
||||||
inpMsg = in.readLine();
|
inpMsg = in.readLine();
|
||||||
if (inpMsg == null) inpMsg = "";
|
|
||||||
|
|
||||||
err = new BufferedReader(new InputStreamReader(
|
err = new BufferedReader(new InputStreamReader(
|
||||||
process.getErrorStream()));
|
process.getErrorStream()));
|
||||||
errMsg = err.readLine();
|
errMsg = err.readLine();
|
||||||
if (errMsg == null) errMsg = "";
|
if (inpMsg == null || exitValue != 0) {
|
||||||
if (exitValue != 0) {
|
throw createIOException(fileName, inpMsg, errMsg, exitValue, null);
|
||||||
throw new IOException(inpMsg + errMsg);
|
|
||||||
}
|
}
|
||||||
if (getOSType() == OSType.OS_TYPE_SOLARIS) {
|
if (getOSType() == OSType.OS_TYPE_SOLARIS) {
|
||||||
String[] result = inpMsg.split("\\s+");
|
String[] result = inpMsg.split("\\s+");
|
||||||
@ -663,13 +664,9 @@ public static int getLinkCount(File fileName) throws IOException {
|
|||||||
return Integer.parseInt(inpMsg);
|
return Integer.parseInt(inpMsg);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IOException(StringUtils.stringifyException(e) +
|
throw createIOException(fileName, inpMsg, errMsg, exitValue, e);
|
||||||
inpMsg + errMsg +
|
|
||||||
" on file:" + fileName);
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException(StringUtils.stringifyException(e) +
|
throw createIOException(fileName, inpMsg, errMsg, exitValue, e);
|
||||||
inpMsg + errMsg +
|
|
||||||
" on file:" + fileName);
|
|
||||||
} finally {
|
} finally {
|
||||||
process.destroy();
|
process.destroy();
|
||||||
if (in != null) in.close();
|
if (in != null) in.close();
|
||||||
@ -678,6 +675,16 @@ public static int getLinkCount(File fileName) throws IOException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create an IOException for failing to get link count. */
|
||||||
|
static private IOException createIOException(File f, String message,
|
||||||
|
String error, int exitvalue, Exception cause) {
|
||||||
|
final String s = "Failed to get link count on file " + f
|
||||||
|
+ ": message=" + message
|
||||||
|
+ "; error=" + error
|
||||||
|
+ "; exit value=" + exitvalue;
|
||||||
|
return cause == null? new IOException(s): new IOException(s, cause);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a soft link between a src and destination
|
* Create a soft link between a src and destination
|
||||||
* only on a local disk. HDFS does not support this
|
* only on a local disk. HDFS does not support this
|
||||||
|
Loading…
Reference in New Issue
Block a user