Skip to content

Commit 664f5f8

Browse files
committed
MAPREDUCE-5300. Fix backward incompatibility for o.a.h.mapreduce.filecache.DistributedCache. Contributed by Zhijie Shen.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1489227 13f79535-47bb-0310-9956-ffa450edef68
1 parent efca0ff commit 664f5f8

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

hadoop-mapreduce-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ Release 2.1.0-beta - UNRELEASED
487487
MAPREDUCE-5296. Fix backward incompatibility for JobControl by adding the
488488
omitted addJob. (Zhijie Shen via acmurthy)
489489

490+
MAPREDUCE-5300. Fix backward incompatibility for
491+
o.a.h.mapreduce.filecache.DistributedCache. (Zhijie Shen via acmurthy)
492+
490493
BREAKDOWN OF HADOOP-8562 SUBTASKS
491494

492495
MAPREDUCE-4739. Some MapReduce tests fail to find winutils.

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,6 @@ public static Path getStartJobCommitFile(Configuration conf, String user,
336336
return startCommitFile;
337337
}
338338

339-
private static long[] parseTimeStamps(String[] strs) {
340-
if (null == strs) {
341-
return null;
342-
}
343-
long[] result = new long[strs.length];
344-
for(int i=0; i < strs.length; ++i) {
345-
result[i] = Long.parseLong(strs[i]);
346-
}
347-
return result;
348-
}
349-
350339
public static void setupDistributedCache(
351340
Configuration conf,
352341
Map<String, LocalResource> localResources)
@@ -356,7 +345,7 @@ public static void setupDistributedCache(
356345
parseDistributedCacheArtifacts(conf, localResources,
357346
LocalResourceType.ARCHIVE,
358347
DistributedCache.getCacheArchives(conf),
359-
parseTimeStamps(DistributedCache.getArchiveTimestamps(conf)),
348+
DistributedCache.getArchiveTimestamps(conf),
360349
getFileSizes(conf, MRJobConfig.CACHE_ARCHIVES_SIZES),
361350
DistributedCache.getArchiveVisibilities(conf));
362351

@@ -365,7 +354,7 @@ public static void setupDistributedCache(
365354
localResources,
366355
LocalResourceType.FILE,
367356
DistributedCache.getCacheFiles(conf),
368-
parseTimeStamps(DistributedCache.getFileTimestamps(conf)),
357+
DistributedCache.getFileTimestamps(conf),
369358
getFileSizes(conf, MRJobConfig.CACHE_FILES_SIZES),
370359
DistributedCache.getFileVisibilities(conf));
371360
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestMRWithDistributedCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ public void testDeprecatedFunctions() throws Exception {
245245
Assert.assertEquals(1,
246246
DistributedCache.getArchiveTimestamps(conf).length);
247247
Assert.assertEquals(1234567890,
248-
Long.parseLong(DistributedCache.getArchiveTimestamps(conf)[0]));
248+
DistributedCache.getArchiveTimestamps(conf)[0]);
249249
DistributedCache.setFileTimestamps(conf, "1234567890");
250250
Assert.assertEquals(1234567890,
251251
conf.getLong(DistributedCache.CACHE_FILES_TIMESTAMPS, 0));
252252
Assert.assertEquals(1,
253253
DistributedCache.getFileTimestamps(conf).length);
254254
Assert.assertEquals(1234567890,
255-
Long.parseLong(DistributedCache.getFileTimestamps(conf)[0]));
255+
DistributedCache.getFileTimestamps(conf)[0]);
256256

257257
DistributedCache.createAllSymlink(conf, new File("Test Job Cache Dir"),
258258
new File("Test Work Dir"));

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/filecache/DistributedCache.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,49 @@ public static Path[] getLocalCacheFiles(Configuration conf)
214214
return StringUtils.stringToPath(conf.getStrings(MRJobConfig.CACHE_LOCALFILES));
215215
}
216216

217+
/**
218+
* Parse a list of strings into longs.
219+
* @param strs the list of strings to parse
220+
* @return a list of longs that were parsed. same length as strs.
221+
*/
222+
private static long[] parseTimestamps(String[] strs) {
223+
if (strs == null) {
224+
return null;
225+
}
226+
long[] result = new long[strs.length];
227+
for(int i=0; i < strs.length; ++i) {
228+
result[i] = Long.parseLong(strs[i]);
229+
}
230+
return result;
231+
}
232+
217233
/**
218234
* Get the timestamps of the archives. Used by internal
219235
* DistributedCache and MapReduce code.
220236
* @param conf The configuration which stored the timestamps
221-
* @return a string array of timestamps
237+
* @return a long array of timestamps
222238
* @throws IOException
223239
* @deprecated Use {@link JobContext#getArchiveTimestamps()} instead
224240
*/
225241
@Deprecated
226-
public static String[] getArchiveTimestamps(Configuration conf) {
227-
return conf.getStrings(MRJobConfig.CACHE_ARCHIVES_TIMESTAMPS);
242+
public static long[] getArchiveTimestamps(Configuration conf) {
243+
return parseTimestamps(
244+
conf.getStrings(MRJobConfig.CACHE_ARCHIVES_TIMESTAMPS));
228245
}
229246

230247

231248
/**
232249
* Get the timestamps of the files. Used by internal
233250
* DistributedCache and MapReduce code.
234251
* @param conf The configuration which stored the timestamps
235-
* @return a string array of timestamps
252+
* @return a long array of timestamps
236253
* @throws IOException
237254
* @deprecated Use {@link JobContext#getFileTimestamps()} instead
238255
*/
239256
@Deprecated
240-
public static String[] getFileTimestamps(Configuration conf) {
241-
return conf.getStrings(MRJobConfig.CACHE_FILE_TIMESTAMPS);
257+
public static long[] getFileTimestamps(Configuration conf) {
258+
return parseTimestamps(
259+
conf.getStrings(MRJobConfig.CACHE_FILE_TIMESTAMPS));
242260
}
243261

244262
/**

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/JobContextImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,31 @@ public Path[] getLocalCacheFiles()
342342
public Path[] getFileClassPaths() {
343343
return DistributedCache.getFileClassPaths(conf);
344344
}
345-
345+
346+
/**
347+
* Parse a list of longs into strings.
348+
* @param timestamps the list of longs to parse
349+
* @return a list of string that were parsed. same length as timestamps.
350+
*/
351+
private static String[] toTimestampStrs(long[] timestamps) {
352+
if (timestamps == null) {
353+
return null;
354+
}
355+
String[] result = new String[timestamps.length];
356+
for(int i=0; i < timestamps.length; ++i) {
357+
result[i] = Long.toString(timestamps[i]);
358+
}
359+
return result;
360+
}
361+
346362
/**
347363
* Get the timestamps of the archives. Used by internal
348364
* DistributedCache and MapReduce code.
349365
* @return a string array of timestamps
350366
* @throws IOException
351367
*/
352368
public String[] getArchiveTimestamps() {
353-
return DistributedCache.getArchiveTimestamps(conf);
369+
return toTimestampStrs(DistributedCache.getArchiveTimestamps(conf));
354370
}
355371

356372
/**
@@ -360,7 +376,7 @@ public String[] getArchiveTimestamps() {
360376
* @throws IOException
361377
*/
362378
public String[] getFileTimestamps() {
363-
return DistributedCache.getFileTimestamps(conf);
379+
return toTimestampStrs(DistributedCache.getFileTimestamps(conf));
364380
}
365381

366382
/**

0 commit comments

Comments
 (0)