From 19db965c2776e86095ecd31d7e582aca07d1e789 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Tue, 17 May 2016 20:19:01 +0900 Subject: [PATCH] MAPREDUCE-6693. ArrayIndexOutOfBoundsException occurs when the length of the job name is equal to mapreduce.jobhistory.jobname.limit. Contributed by Ajith S. (cherry picked from commit b3579305268bffc44a8041c5b75f15f01ebb9ce4) --- .../v2/jobhistory/FileNameIndexUtils.java | 2 +- .../v2/jobhistory/TestFileNameIndexUtils.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/jobhistory/FileNameIndexUtils.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/jobhistory/FileNameIndexUtils.java index 284fe80afad..aac3cb2b510 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/jobhistory/FileNameIndexUtils.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/jobhistory/FileNameIndexUtils.java @@ -311,7 +311,7 @@ public class FileNameIndexUtils { String encodedString, int limitLength) { assert(limitLength >= 0) : "limitLength should be positive integer"; - if (encodedString.length() < limitLength) { + if (encodedString.length() <= limitLength) { return encodedString; } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapreduce/v2/jobhistory/TestFileNameIndexUtils.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapreduce/v2/jobhistory/TestFileNameIndexUtils.java index 6fa7dbc7c12..f9322d86d17 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapreduce/v2/jobhistory/TestFileNameIndexUtils.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapreduce/v2/jobhistory/TestFileNameIndexUtils.java @@ -481,4 +481,29 @@ public class TestFileNameIndexUtils { Assert.assertNull("Queue name incorrect after decoding old history file", info.getQueueName()); } + + @Test + public void testTrimJobNameEqualsLimitLength() throws IOException { + int jobNameTrimLength = 9; + JobIndexInfo info = new JobIndexInfo(); + JobID oldJobId = JobID.forName(JOB_ID); + JobId jobId = TypeConverter.toYarn(oldJobId); + info.setJobId(jobId); + info.setSubmitTime(Long.parseLong(SUBMIT_TIME)); + info.setUser(USER_NAME); + info.setJobName(JOB_NAME); + info.setFinishTime(Long.parseLong(FINISH_TIME)); + info.setNumMaps(Integer.parseInt(NUM_MAPS)); + info.setNumReduces(Integer.parseInt(NUM_REDUCES)); + info.setJobStatus(JOB_STATUS); + info.setQueueName(QUEUE_NAME); + info.setJobStartTime(Long.parseLong(JOB_START_TIME)); + + String jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, + jobNameTrimLength); + JobIndexInfo parsedInfo = FileNameIndexUtils.getIndexInfo(jobHistoryFile); + + Assert.assertEquals("Job name did not get trimmed correctly", info + .getJobName().substring(0, jobNameTrimLength), parsedInfo.getJobName()); + } }