[ 
https://issues.apache.org/jira/browse/HDFS-9368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15009677#comment-15009677
 ] 

Haohui Mai commented on HDFS-9368:
----------------------------------

Looks good to me overall. The patch needs to be rebased towards the latest tip.

{code}
+ssize_t FileHandle::Read(void *buf, size_t nbyte) {
+off_t FileHandle::Seek(off_t offset, Whence whence) {
{code}

Instead of returning -1, these function can return a {{Status}} object that 
encapsulates the error code. Then the wrapper in the c binding side would 
become:

{code}
static int Error(const Status &stat) {
  errno = ...;
  return -1;
}

int hdfsSeek(hdfsFS fs, hdfsFile file, tOffset desiredPos) {
  Status stat = CheckSystemAndHandle(fs, file);
  if (!stat.ok()) {
    return Error(stat);
  }
  int pos = desiredPos;
  stat = file->get_impl()->Seek(pos, FileHandle::Whence::SET);
  if (!stat.ok()) {
    ...
  }
}
{code}

You can simplify as it needs.

{code}
+  enum Whence {
+    SET = SEEK_SET,
+    CUR = SEEK_CUR,
+    END = SEEK_END,
+  };
{code}

Let's use {{ios_base::seekdir}}

http://www.cplusplus.com/reference/ios/ios_base/seekdir/

{code}
+  FileHandle(InputStream *is) : input_stream_(is), offset_(0){};
{code}

Might make sense to move the inline function to a {{.cc}} file.

{code}
+  unsigned long long get_file_length();
{code}

Can be

{code}
uint64_t get_file_length() const;
{code}

> Implement reads with implicit offset state in libhdfs++
> -------------------------------------------------------
>
>                 Key: HDFS-9368
>                 URL: https://issues.apache.org/jira/browse/HDFS-9368
>             Project: Hadoop HDFS
>          Issue Type: Sub-task
>          Components: hdfs-client
>            Reporter: James Clampffer
>            Assignee: James Clampffer
>         Attachments: HDFS-9368.HDFS-8707.000.patch, 
> HDFS-9368.HDFS-8707.001.patch
>
>
> Currently only positional reads are supported.  Implement a stateful read 
> that keeps track of offset into file.  Also expose it in the c bindings as 
> hdfsRead.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to