Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-13870

Incorrect behavior of copyFromLocalFile on implementations of FilterFileSystem

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • None
    • None
    • fs
    • None

    Description

      This may be an incorrect assumption on my part, but it was my belief that overriding the create method on a FilterFileSystem was sufficient to intercept all calls that would write data through the FileSystem. This is apparently not true because calling copyFromLocalFile on the FilterFileSystem eventually invokes the create method on the wrapped FileSystem. I would expect open -> create -> copy(opened, created) to be functionally equivalent to copyFromLocal when using the same input and output paths, but this is not the case.

      import java.io.IOException;
      import java.net.URI;
      import java.nio.charset.StandardCharsets;
      import org.apache.commons.io.IOUtils;
      import org.apache.hadoop.conf.Configuration;
      import org.apache.hadoop.fs.FSDataInputStream;
      import org.apache.hadoop.fs.FSDataOutputStream;
      import org.apache.hadoop.fs.FileSystem;
      import org.apache.hadoop.fs.FilterFileSystem;
      import org.apache.hadoop.fs.Path;
      import org.apache.hadoop.fs.permission.FsPermission;
      import org.apache.hadoop.util.Progressable;
      import org.junit.Before;
      import org.junit.Test;
      
      public final class CopyFromLocalFileTest {
      
          private static final Path DATA_PATH = new Path("file:///tmp/test_in");
          private static final Path OUT_PATH = new Path("file:///tmp/test_out");
      
          private FileSystem localFs;
          private FileSystem wrappedFs;
      
          @Before
          public void before() throws IOException {
              localFs = FileSystem.get(URI.create("file:///"), new Configuration());
              wrappedFs = new FailingFileSystem(localFs);
      
              FSDataOutputStream tmpFile = localFs.create(DATA_PATH);
              byte[] bytes = "data".getBytes(StandardCharsets.UTF_8);
              tmpFile.write(bytes);
              tmpFile.close();
          }
      
          @Test
          public void test_correct() throws IOException {
              FSDataInputStream in = wrappedFs.open(DATA_PATH);
              FSDataOutputStream out = wrappedFs.create(OUT_PATH); // this call fails
              IOUtils.copy(in, out);
          }
      
          @Test
          public void test_incorrect() throws IOException {
              wrappedFs.copyFromLocalFile(DATA_PATH, OUT_PATH); // this call does not fail
          }
      
          private static final class FailingFileSystem extends FilterFileSystem {
      
              public FailingFileSystem(FileSystem fs) {
                  super(fs);
              }
      
              @Override
              public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
                      short replication, long blockSize, Progressable progress) throws IOException {
                  throw new IOException("fail");
              }
      
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            jellis Joe Ellis
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: