Forráskód Böngészése

MAPREDUCE-4843. When using DefaultTaskController, JobLocalizer not thread safe. (kkambatl via tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1442404 13f79535-47bb-0310-9956-ffa450edef68
Alejandro Abdelnur 12 éve
szülő
commit
9410b00e73

+ 3 - 0
CHANGES.txt

@@ -468,6 +468,9 @@ Release 1.2.0 - unreleased
     MAPREDUCE-4969. TestKeyValueTextInputFormat test fails with Open JDK 7.
     (Arpit Agarwal via suresh)
 
+    MAPREDUCE-4843. When using DefaultTaskController, JobLocalizer not thread 
+    safe. (kkambatl via tucu)
+
 Release 1.1.2 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 5 - 5
src/mapred/org/apache/hadoop/mapred/JobLocalizer.java

@@ -82,7 +82,7 @@ public class JobLocalizer {
   private final FileSystem lfs;
   private final List<Path> localDirs;
   private final LocalDirAllocator lDirAlloc;
-  private final JobConf ttConf;
+  protected final JobConf ttConf;
 
   private final String JOBDIR;
   private final String DISTDIR;
@@ -90,7 +90,7 @@ public class JobLocalizer {
   private final String JARDST;
   private final String JOBCONF;
   private final String JOBTOKEN;
-  private static final String JOB_LOCAL_CTXT = "mapred.job.local.dir";
+  protected static final String JOB_LOCAL_CTXT = "mapred.job.local.dir";
 
   public JobLocalizer(JobConf ttConf, String user, String jobid)
       throws IOException {
@@ -108,10 +108,10 @@ public class JobLocalizer {
       throw new IOException("Cannot initialize for null jobid");
     }
     this.jobid = jobid;
-    this.ttConf = ttConf;
-    lfs = FileSystem.getLocal(ttConf).getRaw();
+    this.ttConf = new JobConf(ttConf);
+    lfs = FileSystem.getLocal(this.ttConf).getRaw();
     this.localDirs = createPaths(user, localDirs);
-    ttConf.setStrings(JOB_LOCAL_CTXT, localDirs);
+    this.ttConf.setStrings(JOB_LOCAL_CTXT, localDirs);
     Collections.shuffle(this.localDirs);
     lDirAlloc = new LocalDirAllocator(JOB_LOCAL_CTXT);
     JOBDIR = TaskTracker.JOBCACHE + Path.SEPARATOR + jobid;

+ 44 - 0
src/test/org/apache/hadoop/mapred/TestJobLocalizer.java

@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.mapred;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
+
+public class TestJobLocalizer {
+
+  @Test(timeout = 1000)
+  public void testConcurrentJobLocalizers() throws IOException {
+    final String LOCAL_DIR = "/tmp/mapred/local";
+    JobConf conf = new JobConf(new Configuration());
+    
+    JobLocalizer localizer1 = new JobLocalizer(conf, "user1", "jobid1",
+        LOCAL_DIR);
+    JobLocalizer localizer2 = new JobLocalizer(conf, "user2", "jobid2",
+        LOCAL_DIR);
+    assertTrue("Localizer 1 job local dirs should have user1",
+        localizer1.ttConf.get(JobLocalizer.JOB_LOCAL_CTXT).contains("user1"));
+    assertTrue("Localizer 2 job local dirs should have user2",
+        localizer2.ttConf.get(JobLocalizer.JOB_LOCAL_CTXT).contains("user2"));
+  }
+}