Skip to content

Commit db1332e

Browse files
committed
HADOOP-7087. SequenceFile.createWriter ignores FileSystem parameter. Contributed by Todd Lipcon
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1057789 13f79535-47bb-0310-9956-ffa450edef68
1 parent 52b4c73 commit db1332e

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ Release 0.22.0 - Unreleased
425425
HADOOP-7070. JAAS configuration should delegate unknown application names
426426
to pre-existing configuration. (todd)
427427

428+
HADOOP-7087. SequenceFile.createWriter ignores FileSystem parameter (todd)
429+
428430
Release 0.21.1 - Unreleased
429431

430432
IMPROVEMENTS

src/java/org/apache/hadoop/io/SequenceFile.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
288288
public static Writer
289289
createWriter(FileSystem fs, Configuration conf, Path name,
290290
Class keyClass, Class valClass) throws IOException {
291-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
291+
return createWriter(conf, Writer.filesystem(fs),
292+
Writer.file(name), Writer.keyClass(keyClass),
292293
Writer.valueClass(valClass));
293294
}
294295

@@ -310,7 +311,8 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
310311
createWriter(FileSystem fs, Configuration conf, Path name,
311312
Class keyClass, Class valClass,
312313
CompressionType compressionType) throws IOException {
313-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
314+
return createWriter(conf, Writer.filesystem(fs),
315+
Writer.file(name), Writer.keyClass(keyClass),
314316
Writer.valueClass(valClass),
315317
Writer.compression(compressionType));
316318
}
@@ -334,7 +336,9 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
334336
createWriter(FileSystem fs, Configuration conf, Path name,
335337
Class keyClass, Class valClass, CompressionType compressionType,
336338
Progressable progress) throws IOException {
337-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
339+
return createWriter(conf, Writer.file(name),
340+
Writer.filesystem(fs),
341+
Writer.keyClass(keyClass),
338342
Writer.valueClass(valClass),
339343
Writer.compression(compressionType),
340344
Writer.progressable(progress));
@@ -359,7 +363,9 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
359363
createWriter(FileSystem fs, Configuration conf, Path name,
360364
Class keyClass, Class valClass, CompressionType compressionType,
361365
CompressionCodec codec) throws IOException {
362-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
366+
return createWriter(conf, Writer.file(name),
367+
Writer.filesystem(fs),
368+
Writer.keyClass(keyClass),
363369
Writer.valueClass(valClass),
364370
Writer.compression(compressionType, codec));
365371
}
@@ -386,7 +392,9 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
386392
Class keyClass, Class valClass,
387393
CompressionType compressionType, CompressionCodec codec,
388394
Progressable progress, Metadata metadata) throws IOException {
389-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
395+
return createWriter(conf, Writer.file(name),
396+
Writer.filesystem(fs),
397+
Writer.keyClass(keyClass),
390398
Writer.valueClass(valClass),
391399
Writer.compression(compressionType, codec),
392400
Writer.progressable(progress),
@@ -419,7 +427,9 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
419427
short replication, long blockSize,
420428
CompressionType compressionType, CompressionCodec codec,
421429
Progressable progress, Metadata metadata) throws IOException {
422-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
430+
return createWriter(conf, Writer.file(name),
431+
Writer.filesystem(fs),
432+
Writer.keyClass(keyClass),
423433
Writer.valueClass(valClass),
424434
Writer.bufferSize(bufferSize),
425435
Writer.replication(replication),
@@ -450,7 +460,9 @@ public static Writer createWriter(Configuration conf, Writer.Option... opts
450460
Class keyClass, Class valClass,
451461
CompressionType compressionType, CompressionCodec codec,
452462
Progressable progress) throws IOException {
453-
return createWriter(conf, Writer.file(name), Writer.keyClass(keyClass),
463+
return createWriter(conf, Writer.file(name),
464+
Writer.filesystem(fs),
465+
Writer.keyClass(keyClass),
454466
Writer.valueClass(valClass),
455467
Writer.compression(compressionType, codec),
456468
Writer.progressable(progress));
@@ -777,6 +789,21 @@ static class FileOption extends Options.PathOption
777789
}
778790
}
779791

792+
/**
793+
* @deprecated only used for backwards-compatibility in the createWriter methods
794+
* that take FileSystem.
795+
*/
796+
@Deprecated
797+
private static class FileSystemOption implements Option {
798+
private final FileSystem value;
799+
protected FileSystemOption(FileSystem value) {
800+
this.value = value;
801+
}
802+
public FileSystem getValue() {
803+
return value;
804+
}
805+
}
806+
780807
static class StreamOption extends Options.FSDataOutputStreamOption
781808
implements Option {
782809
StreamOption(FSDataOutputStream stream) {
@@ -857,6 +884,15 @@ CompressionCodec getCodec() {
857884
public static Option file(Path value) {
858885
return new FileOption(value);
859886
}
887+
888+
/**
889+
* @deprecated only used for backwards-compatibility in the createWriter methods
890+
* that take FileSystem.
891+
*/
892+
@Deprecated
893+
private static Option filesystem(FileSystem fs) {
894+
return new SequenceFile.Writer.FileSystemOption(fs);
895+
}
860896

861897
public static Option bufferSize(int value) {
862898
return new BufferSizeOption(value);
@@ -916,6 +952,7 @@ public static Option compression(CompressionType value,
916952
ProgressableOption progressOption =
917953
Options.getOption(ProgressableOption.class, opts);
918954
FileOption fileOption = Options.getOption(FileOption.class, opts);
955+
FileSystemOption fsOption = Options.getOption(FileSystemOption.class, opts);
919956
StreamOption streamOption = Options.getOption(StreamOption.class, opts);
920957
KeyClassOption keyClassOption =
921958
Options.getOption(KeyClassOption.class, opts);
@@ -941,7 +978,12 @@ public static Option compression(CompressionType value,
941978
boolean ownStream = fileOption != null;
942979
if (ownStream) {
943980
Path p = fileOption.getValue();
944-
FileSystem fs = p.getFileSystem(conf);
981+
FileSystem fs;
982+
if (fsOption != null) {
983+
fs = fsOption.getValue();
984+
} else {
985+
fs = p.getFileSystem(conf);
986+
}
945987
int bufferSize = bufferSizeOption == null ? getBufferSize(conf) :
946988
bufferSizeOption.getValue();
947989
short replication = replicationOption == null ?

src/test/core/org/apache/hadoop/io/TestSequenceFile.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.io.compress.DefaultCodec;
3131
import org.apache.hadoop.util.ReflectionUtils;
3232
import org.apache.hadoop.conf.*;
33+
import org.mockito.Mockito;
3334

3435

3536
/** Support for flat files of binary key/value pairs. */
@@ -457,6 +458,20 @@ public void testClose() throws IOException {
457458
assertFalse(reader2.next(text));
458459
}
459460

461+
/**
462+
* Test that makes sure the FileSystem passed to createWriter
463+
* @throws Exception
464+
*/
465+
public void testCreateUsesFsArg() throws Exception {
466+
FileSystem fs = FileSystem.getLocal(conf);
467+
FileSystem spyFs = Mockito.spy(fs);
468+
Path p = new Path(System.getProperty("test.build.data", ".")+"/testCreateUsesFSArg.seq");
469+
SequenceFile.Writer writer = SequenceFile.createWriter(
470+
spyFs, conf, p, NullWritable.class, NullWritable.class);
471+
writer.close();
472+
Mockito.verify(spyFs).getDefaultReplication();
473+
}
474+
460475
private static class TestFSDataInputStream extends FSDataInputStream {
461476
private boolean closed = false;
462477

0 commit comments

Comments
 (0)