You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ra...@apache.org on 2008/01/08 21:09:37 UTC
svn commit: r610124 - in /lucene/hadoop/trunk: CHANGES.txt
src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
src/java/org/apache/hadoop/util/Shell.java
Author: rangadi
Date: Tue Jan 8 12:09:36 2008
New Revision: 610124
URL: http://svn.apache.org/viewvc?rev=610124&view=rev
Log:
HADOOP-2512. Fix error stream handling in Shell. Use exit code to
detect shell command errors in RawLocalFileSystem. (Raghu Angadi)
Modified:
lucene/hadoop/trunk/CHANGES.txt
lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
lucene/hadoop/trunk/src/java/org/apache/hadoop/util/Shell.java
Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=610124&r1=610123&r2=610124&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Jan 8 12:09:36 2008
@@ -354,6 +354,9 @@
Configuration changes to hadoop-default.xml:
remove mapred.child.heap.size
+ HADOOP-2512. Fix error stream handling in Shell. Use exit code to
+ detect shell command errors in RawLocalFileSystem. (Raghu Angadi)
+
Release 0.15.2 - 2008-01-02
BUG FIXES
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=610124&r1=610123&r2=610124&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java Tue Jan 8 12:09:36 2008
@@ -397,6 +397,7 @@
/// loads permissions, owner, and group from `ls -ld`
private void loadPermissionInfo() {
+ IOException e = null;
try {
StringTokenizer t = new StringTokenizer(
execCommand(new File(getPath().toUri()),
@@ -411,16 +412,18 @@
t.nextToken();
setOwner(t.nextToken());
setGroup(t.nextToken());
- } catch (IOException e) {
- if (e.getMessage().contains("No such file or directory")) {
- /* XXX This is a temporary hack till HADOOP-2344 goes in.
- * will fix it soon.
- */
+ } catch (Shell.ExitCodeException ioe) {
+ if (ioe.getExitCode() != 1) {
+ e = ioe;
+ } else {
setPermission(null);
setOwner(null);
setGroup(null);
- } else {
- //this is not expected
+ }
+ } catch (IOException ioe) {
+ e = ioe;
+ } finally {
+ if (e != null) {
throw new RuntimeException("Error while running command to get " +
"file permissions : " +
StringUtils.stringifyException(e));
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/util/Shell.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/util/Shell.java?rev=610124&r1=610123&r2=610124&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/util/Shell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/util/Shell.java Tue Jan 8 12:09:36 2008
@@ -130,7 +130,7 @@
String line = errReader.readLine();
while((line != null) && !isInterrupted()) {
errMsg.append(line);
- errMsg.append(System.getProperty("line.seperator"));
+ errMsg.append(System.getProperty("line.separator"));
line = errReader.readLine();
}
} catch(IOException ioe) {
@@ -150,13 +150,16 @@
}
// wait for the process to finish and check the exit code
exitCode = process.waitFor();
- if (exitCode != 0) {
- if (errMsg.length() == 0) {
- errMsg.append("Command exit with status code " + exitCode);
- }
- throw new IOException(errMsg.toString());
+ try {
+ // make sure that the error thread exits
+ errThread.join();
+ } catch (InterruptedException ie) {
+ LOG.warn("Interrupted while reading the error stream", ie);
}
completed = true;
+ if (exitCode != 0) {
+ throw new ExitCodeException(exitCode, errMsg.toString());
+ }
} catch (InterruptedException ie) {
throw new IOException(ie.toString());
} finally {
@@ -166,14 +169,7 @@
} catch (IOException ioe) {
LOG.warn("Error while closing the input stream", ioe);
}
- if (completed) {
- try {
- // make sure that the error thread exits
- errThread.join();
- } catch (InterruptedException ie) {
- LOG.warn("Interrupted while reading the error stream", ie);
- }
- } else {
+ if (!completed) {
errThread.interrupt();
}
try {
@@ -207,6 +203,22 @@
return exitCode;
}
+ /**
+ * This is an IOException with exit code added.
+ */
+ public static class ExitCodeException extends IOException {
+ int exitCode;
+
+ public ExitCodeException(int exitCode, String message) {
+ super(message);
+ this.exitCode = exitCode;
+ }
+
+ public int getExitCode() {
+ return exitCode;
+ }
+ }
+
/**
* A simple shell command executor.
*