Browse Source

commit 3bdd37c9e65690f729ac12e8d8c17495ef2a4f7d
Author: Arun C Murthy <acmurthy@apache.org>
Date: Sun Oct 3 23:14:01 2010 -0700

MAPREDUCE-323. Fixed the search funtion in jobhistory browsing.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077731 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 years ago
parent
commit
2a6baef8bc

+ 10 - 7
src/mapred/org/apache/hadoop/mapred/JobHistory.java

@@ -119,6 +119,8 @@ public class JobHistory {
   
   public static final int JOB_NAME_TRIM_LENGTH = 50;
   private static String JOBTRACKER_UNIQUE_STRING = null;
+  private static final String JOBHISTORY_DEBUG_MODE =
+    "mapreduce.jobhistory.debug.mode";
   private static String LOG_DIR = null;
   private static final String SECONDARY_FILE_SUFFIX = ".recover";
   private static long jobHistoryBlockSize = 0;
@@ -139,15 +141,11 @@ public class JobHistory {
   static final String CONF_FILE_NAME_SUFFIX = "_conf.xml";
 
   // XXXXX debug mode -- set this to false for production
-  private static final boolean DEBUG_MODE = false;
-
+  private static boolean DEBUG_MODE;
   private static final int SERIAL_NUMBER_DIRECTORY_DIGITS = 6;
-  private static final int SERIAL_NUMBER_LOW_DIGITS = DEBUG_MODE ? 1 : 3;
+  private static int SERIAL_NUMBER_LOW_DIGITS;
 
-  private static final String SERIAL_NUMBER_FORMAT
-    = ("%0"
-       + (SERIAL_NUMBER_DIRECTORY_DIGITS + SERIAL_NUMBER_LOW_DIGITS)
-       + "d");
+  private static String SERIAL_NUMBER_FORMAT;
 
   private static final Set<Path> existingDoneSubdirs = new HashSet<Path>();
 
@@ -499,6 +497,11 @@ public class JobHistory {
   public static void init(JobTracker jobTracker, JobConf conf,
              String hostname, long jobTrackerStartTime) throws IOException {
     initLogDir(conf);
+    DEBUG_MODE = conf.getBoolean(JOBHISTORY_DEBUG_MODE, false);
+    SERIAL_NUMBER_LOW_DIGITS = DEBUG_MODE ? 1 : 3;
+    SERIAL_NUMBER_FORMAT = ("%0"
+       + (SERIAL_NUMBER_DIRECTORY_DIGITS + SERIAL_NUMBER_LOW_DIGITS)
+       + "d");
     JOBTRACKER_UNIQUE_STRING = hostname + "_" + 
                                   String.valueOf(jobTrackerStartTime) + "_";
     jobtrackerHostname = hostname;

+ 33 - 46
src/webapps/history/jobhistoryhome.jsp

@@ -30,12 +30,9 @@
     trackerName = StringUtils.simpleHostname(infoSocAddr.getHostName());
   }
 %>
-<%!	
-  private static SimpleDateFormat dateFormat = 
-                                    new SimpleDateFormat("d/MM HH:mm:ss");
-%>
-<%!	private static final long serialVersionUID = 1L;
-%>
+<%!private static SimpleDateFormat dateFormat = new SimpleDateFormat(
+      "d/MM HH:mm:ss");%>
+<%!private static final long serialVersionUID = 1L;%>
 <html>
 <head>
 <script type="text/JavaScript">
@@ -74,7 +71,7 @@ window.location.href = url;
 
     final int FILENAME_JOBNAME_PART = FILENAME_JOBID_END + 2;
 
-    final int[] SCAN_SIZES = { 20, 50, 200 };
+    final int[] SCAN_SIZES = { 20, 50, 200, 1000 };
 
     final int FILES_PER_SCAN = 1000;
 
@@ -104,7 +101,9 @@ window.location.href = url;
 
     final int currentScanSizeIndex
       = (request.getParameter("scansize") == null)
-           ? 0 : Integer.parseInt(request.getParameter("scansize"));
+           ? 0 : 
+             Math.min(Integer.parseInt(request.getParameter("scansize")), 
+                 SCAN_SIZES.length-1);
 
     final String SEARCH_PARSE_REGEX
       = "([0-1]?[0-9])/([0-3]?[0-9])/((?:2[0-9])[0-9][0-9])";
@@ -152,12 +151,12 @@ window.location.href = url;
       return;
     }
 
-    Comparator<Path> lastPathFirst
-      = new Comparator<Path>() {
-          public int compare(Path path1, Path path2) {
-            // these are backwards because we want the lexically lesser names
-            // to occur later in the sort.
-            return path2.getName().compareTo(path1.getName());
+    Comparator<FileStatus> mtimeComparator
+      = new Comparator<FileStatus>() {
+          public int compare(FileStatus status1, FileStatus status2) {
+            Long time1 = new Long(status1.getModificationTime());
+            Long time2 = new Long(status2.getModificationTime());
+            return time2.compareTo(time1);
           }
     };
 
@@ -239,35 +238,16 @@ window.location.href = url;
     // I would have used MutableBoxedBoolean if such had been provided.
     AtomicBoolean hasLegacyFiles = new AtomicBoolean(false);
 
-    Path[] snPaths
-      = FileUtil.stat2Paths(JobHistory.localGlobber
-                            (fs, historyPath, "/" + leadGlob, null, hasLegacyFiles));
-
-    Arrays.sort(snPaths, lastPathFirst);
-
-    int arrayLimit = 0;
-    int tranchesSeen = 0;
-
-    Path lastPath = null;
-
-    while (arrayLimit < snPaths.length
-           && tranchesSeen <= SCAN_SIZES[currentScanSizeIndex]) {
-      if (lastPath == null
-          || lastPathFirst.compare(lastPath, snPaths[arrayLimit]) != 0) {
-        ++tranchesSeen;
-        lastPath = snPaths[arrayLimit];
-      }
-
-      ++arrayLimit;
-    }
-
-    if (tranchesSeen > SCAN_SIZES[currentScanSizeIndex]) {
-      --arrayLimit;
-    }
-
-    // arrayLimit points to the first element [which could be element 0] that 
-    // we shouldn't consider
+    FileStatus[] buckets = 
+      JobHistory.localGlobber
+                            (fs, historyPath, "/" + leadGlob, null, hasLegacyFiles);
+    Arrays.sort(buckets, mtimeComparator);
 
+    int arrayLimit = SCAN_SIZES[currentScanSizeIndex] > buckets.length ? 
+        buckets.length : SCAN_SIZES[currentScanSizeIndex];
+    FileStatus[] scanSizeBuckets = Arrays.copyOf(buckets, arrayLimit);
+    Path[] snPaths = FileUtil.stat2Paths(scanSizeBuckets);
+    
     int numHistoryFiles = 0;
 
     Path[] jobFiles = null;
@@ -307,9 +287,16 @@ window.location.href = url;
 
     out.println("<!--  user : " + rawUser +
         ", jobname : " + rawJobname + "-->");
-    if (null == jobFiles || jobFiles.length == 0)  {
-      out.println("No files found!"); 
-      return ; 
+    final String searchMore = "&search=" + search;
+    if (null == jobFiles || jobFiles.length == 0) {
+      if (currentScanSizeIndex < SCAN_SIZES.length -1) {
+        out.println(" [<span class=\"small\"><a href=\"jobhistoryhome.jsp?pageno=1"
+          + searchMore + "&scansize=" + (currentScanSizeIndex +1)
+          + "\">No files found - try and get more results</a></span>]");
+      } else {
+        out.println("No files found!"); 
+      }
+      return;
     }
 
     // get the pageno
@@ -400,7 +387,7 @@ window.location.href = url;
     final String searchPlusScan = searchPart + scansizePart;
 
     // show the expand scope link, if we're restricted
-    if (sizeIsExact || currentScanSizeIndex == SCAN_SIZES.length - 1) {
+    if (currentScanSizeIndex == SCAN_SIZES.length - 1) {
       out.println("[<span class=\"small\">get more results</span>]");
     } else {
       out.println(" [<span class=\"small\"><a href=\"jobhistoryhome.jsp?pageno=1"