Hadoop Common
  1. Hadoop Common
  2. HADOOP-4494

libhdfs does not call FileSystem.append when O_APPEND passed to hdfsOpenFile

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.19.1, 0.20.0
    • Fix Version/s: 0.19.1
    • Component/s: None
    • Labels:
      None
    • Hadoop Flags:
      Reviewed
    • Release Note:
      libhdfs supports O_APPEND flag

      Description

      libhdfs currently calls FileSystem.create when O_APPEND passed in - ie it ignores this flag

      1. HADOOP-4494.txt
        6 kB
        Pete Wyckoff
      2. HADOOP-4494.txt
        6 kB
        Pete Wyckoff

        Issue Links

          Activity

          Hide
          Hudson added a comment -
          Show
          Hudson added a comment - Integrated in Hadoop-trunk #756 (See http://hudson.zones.apache.org/hudson/job/Hadoop-trunk/756/ )
          Hide
          Craig Macdonald added a comment -

          +1 looks good to me.

          Show
          Craig Macdonald added a comment - +1 looks good to me.
          Hide
          dhruba borthakur added a comment -

          I just committed this. Thanks Pete!

          Show
          dhruba borthakur added a comment - I just committed this. Thanks Pete!
          Hide
          dhruba borthakur added a comment -

          Thanks Craig. Please do let me know if this patch looks good to you.

          Show
          dhruba borthakur added a comment - Thanks Craig. Please do let me know if this patch looks good to you.
          Hide
          Craig Macdonald added a comment -

          Hi Dhruba,

          Sorry, I'm currently traveling. I can test for end of next week at earliest.

          Show
          Craig Macdonald added a comment - Hi Dhruba, Sorry, I'm currently traveling. I can test for end of next week at earliest.
          Hide
          dhruba borthakur added a comment -

          Hi Craig, can you pl review this patch? Thanks. Also, I see some earlier review comments from Sanjay.

          Sanjay: do you want to review this patch too?

          Show
          dhruba borthakur added a comment - Hi Craig, can you pl review this patch? Thanks. Also, I see some earlier review comments from Sanjay. Sanjay: do you want to review this patch too?
          Hide
          dhruba borthakur added a comment -

          Hi Craig, will it be possible for you to review and test this patch on trunk? Also, I would like to put it in 0.19, unless you think otherwise.

          Show
          dhruba borthakur added a comment - Hi Craig, will it be possible for you to review and test this patch on trunk? Also, I would like to put it in 0.19, unless you think otherwise.
          Hide
          Craig Macdonald added a comment -

          Anything needed to get this patch in? HADOOP-4508 is now committed.

          Show
          Craig Macdonald added a comment - Anything needed to get this patch in? HADOOP-4508 is now committed.
          Hide
          Pete Wyckoff added a comment -

          the unit tests will not pass without fixing getPos

          Show
          Pete Wyckoff added a comment - the unit tests will not pass without fixing getPos
          Hide
          Pete Wyckoff added a comment -

          added more comments to the flags param and also issue a stderr warning if O_CREAT & O_EXCL are but set.

          Show
          Pete Wyckoff added a comment - added more comments to the flags param and also issue a stderr warning if O_CREAT & O_EXCL are but set.
          Hide
          Pete Wyckoff added a comment -

          idea - we deprecate not having the O_CREAT flag by writing out a warning and updating the docs.

          The good thing about this kind of deprecation is we can ultimately just return -ENOENT when we are ready - should be easy for users to see they have to fix something.

          but, should also look at O_EXCL at the same time ...

          Show
          Pete Wyckoff added a comment - idea - we deprecate not having the O_CREAT flag by writing out a warning and updating the docs. The good thing about this kind of deprecation is we can ultimately just return -ENOENT when we are ready - should be easy for users to see they have to fix something. but, should also look at O_EXCL at the same time ...
          Hide
          Pete Wyckoff added a comment -

          I just noticed that the test uses O_CREAT but the impl does not even bother checking for this (ie treats O_WRONLY as create):

          Yes, open on writes should i guess be O_WRONLY + one of the following:

          1. O_CREAT | O_EXCL - create new file
          2. O_CREATE|O_APPEND - create new file if it doesn't exist, else append

          But, as you point out hdfsOpenFile has only ever checked for O_WRONLY|O_RDONLY. And #2 cannot be done without underlying FileSystem API.

          But, as you point out, if someone does something like `echo hello >> foo` where foo does not exist, libhdfs will do the wrong thing probably.

          We need:

          FSDataOutputStream FileSystem.appendIfExistsElseCreate(Path p);
          

          I can open a JIRA for it. I guess that means anyone using libhdfs (e.g. fuse) would have to do a hacky check if the file exists and decide whether to pass on the append flag, which of course is not transactional.

          And of course, let's not even get into passing on O_TRUNCATE But, the libhdfs code should probably check for that flag and error out if it comes.

          Show
          Pete Wyckoff added a comment - I just noticed that the test uses O_CREAT but the impl does not even bother checking for this (ie treats O_WRONLY as create): Yes, open on writes should i guess be O_WRONLY + one of the following: 1. O_CREAT | O_EXCL - create new file 2. O_CREATE|O_APPEND - create new file if it doesn't exist, else append But, as you point out hdfsOpenFile has only ever checked for O_WRONLY|O_RDONLY. And #2 cannot be done without underlying FileSystem API. But, as you point out, if someone does something like `echo hello >> foo` where foo does not exist, libhdfs will do the wrong thing probably. We need: FSDataOutputStream FileSystem.appendIfExistsElseCreate(Path p); I can open a JIRA for it. I guess that means anyone using libhdfs (e.g. fuse) would have to do a hacky check if the file exists and decide whether to pass on the append flag, which of course is not transactional. And of course, let's not even get into passing on O_TRUNCATE But, the libhdfs code should probably check for that flag and error out if it comes.
          Hide
          Sanjay Radia added a comment -

          Minor doc suggestion:

          In the documentation in hdfs.h
          + * @param flags Either O_RDONLY or O_WRONLY[|O_APPEND] for read-only or write-only.

          O_WRONLY is for create not for writing to arbitrary part of a file.
          Update the comment to indicate that O_WRONLY is for creating, etc.

          I just noticed that the test uses O_CREAT but the impl does not even bother checking for this (ie treats O_WRONLY as create):
          +++ src/c++/libhdfs/hdfs_test.c (working copy)
          + // CREATE
          + hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);

          Unfortunately fixing this to match posix will break compatibility of apps, since truck libhdfs did not check for O_CREAT either.

          Show
          Sanjay Radia added a comment - Minor doc suggestion: In the documentation in hdfs.h + * @param flags Either O_RDONLY or O_WRONLY [|O_APPEND] for read-only or write-only. O_WRONLY is for create not for writing to arbitrary part of a file. Update the comment to indicate that O_WRONLY is for creating, etc. I just noticed that the test uses O_CREAT but the impl does not even bother checking for this (ie treats O_WRONLY as create): +++ src/c++/libhdfs/hdfs_test.c (working copy) + // CREATE + hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0); Unfortunately fixing this to match posix will break compatibility of apps, since truck libhdfs did not check for O_CREAT either.
          Hide
          dhruba borthakur added a comment -

          +1. Looks good.

          Show
          dhruba borthakur added a comment - +1. Looks good.

            People

            • Assignee:
              Pete Wyckoff
              Reporter:
              Pete Wyckoff
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development