Skip to content

Commit 28856a3

Browse files
committed
Disable stack trace for file-not-found errors in libhdfs client
1 parent 20f4011 commit 28856a3

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,25 @@ int printExceptionAndFreeV(JNIEnv *env, jthrowable exc, int noPrintFlags,
189189
if (!rootCause) {
190190
fprintf(stderr, "(unable to get root cause for %s)\n", className);
191191
} else {
192-
fprintf(stderr, "%s", rootCause);
192+
// Trim overly long rootCause message after new-line.
193+
const char *newlnIndex = strchr(rootCause, '\n');
194+
int displayLen = 80;
195+
if (newlnIndex != NULL) {
196+
int newLen = (int) (newlnIndex - rootCause);
197+
if (newLen > 10 && newLen < 200) {
198+
// Keep message a reasonable length.
199+
displayLen = newLen;
200+
}
201+
}
202+
fprintf(stderr, "%.*s\n", displayLen, rootCause);
193203
}
194-
if (!stackTrace) {
195-
fprintf(stderr, "(unable to get stack trace for %s)\n", className);
196-
} else {
197-
fprintf(stderr, "%s", stackTrace);
204+
if (!(noPrintFlags & NOSTACK_FILE_NOT_FOUND)) {
205+
// Do not print stack for file not found
206+
if (!stackTrace) {
207+
fprintf(stderr, "(unable to get stack trace for %s)\n", className);
208+
} else {
209+
fprintf(stderr, "%s", stackTrace);
210+
}
198211
}
199212
}
200213

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
*/
6666
#define PRINT_EXC_ALL 0x00
6767
#define NOPRINT_EXC_FILE_NOT_FOUND 0x01
68+
#define NOSTACK_FILE_NOT_FOUND 0x100
6869
#define NOPRINT_EXC_ACCESS_CONTROL 0x02
6970
#define NOPRINT_EXC_UNRESOLVED_LINK 0x04
7071
#define NOPRINT_EXC_PARENT_NOT_DIRECTORY 0x08

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ static hdfsFile hdfsOpenFileImpl(hdfsFS fs, const char *path, int flags,
12471247
jReplication, jBlockSize);
12481248
}
12491249
if (jthr) {
1250-
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
1250+
ret = printExceptionAndFree(env, jthr, NOSTACK_FILE_NOT_FOUND,
12511251
"hdfsOpenFile(%s): FileSystem#%s(%s)", path, method, signature);
12521252
goto done;
12531253
}

0 commit comments

Comments
 (0)