From c5caed914d1378dab58344df83f12a46aee8aadc Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Fri, 27 Jan 2012 00:09:10 +0000 Subject: [PATCH] HADOOP-7997. SequenceFile.createWriter(...createParent...) no longer works on existing file. Contributed by Gregory Chanan git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1236456 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/io/SequenceFile.java | 2 +- .../org/apache/hadoop/io/TestSequenceFile.java | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index ed4bb945d4d..dc9ad36440f 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -292,6 +292,9 @@ Release 0.23.1 - Unreleased HADOOP-7981. Improve documentation for org.apache.hadoop.io.compress. Decompressor.getRemaining (Jonathan Eagles via mahadev) + HADOOP-7997. SequenceFile.createWriter(...createParent...) no + longer works on existing file. (Gregory Chanan via eli) + Release 0.23.0 - 2011-11-01 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java index a64bd1bf9e2..476eaeb14b5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java @@ -467,7 +467,7 @@ public class SequenceFile { Metadata metadata) throws IOException { return createWriter(FileContext.getFileContext(fs.getUri(), conf), conf, name, keyClass, valClass, compressionType, codec, - metadata, EnumSet.of(CreateFlag.CREATE), + metadata, EnumSet.of(CreateFlag.CREATE,CreateFlag.OVERWRITE), CreateOpts.bufferSize(bufferSize), createParent ? CreateOpts.createParent() : CreateOpts.donotCreateParent(), diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFile.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFile.java index 18bc8df6515..58998be8e65 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFile.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFile.java @@ -517,6 +517,23 @@ public class TestSequenceFile extends TestCase { assertTrue("InputStream for " + path + " should have been closed.", openedFile[0].isClosed()); } + /** + * Test that makes sure createWriter succeeds on a file that was + * already created + * @throws IOException + */ + public void testCreateWriterOnExistingFile() throws IOException { + Configuration conf = new Configuration(); + FileSystem fs = FileSystem.getLocal(conf); + Path name = new Path(new Path(System.getProperty("test.build.data","."), + "createWriterOnExistingFile") , "file"); + + fs.create(name); + SequenceFile.createWriter(fs, conf, name, RandomDatum.class, + RandomDatum.class, 512, (short) 1, 4096, false, + CompressionType.NONE, null, new Metadata()); + } + public void testRecursiveSeqFileCreate() throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.getLocal(conf);