hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject hadoop git commit: HDFS-10543: libhdfs++: hdfsRead stops at block boundary. Contributed by Xiaowei Zhu.
Date Fri, 24 Jun 2016 16:20:55 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-8707 adb1a63e1 -> a903f780e


HDFS-10543: libhdfs++: hdfsRead stops at block boundary.  Contributed by Xiaowei Zhu.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a903f780
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a903f780
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a903f780

Branch: refs/heads/HDFS-8707
Commit: a903f780e5f9935d9e1d9e2780d63cd065fb8f5d
Parents: adb1a63
Author: James <jhc@apache.org>
Authored: Fri Jun 24 12:15:18 2016 -0400
Committer: James <jhc@apache.org>
Committed: Fri Jun 24 12:15:18 2016 -0400

----------------------------------------------------------------------
 .../main/native/libhdfspp/lib/fs/filehandle.cc  | 38 ++++++++++++--------
 1 file changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a903f780/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
index 471281a..38d50f6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc
@@ -78,26 +78,34 @@ Status FileHandleImpl::PositionRead(void *buf, size_t *nbyte, off_t offset)
{
   LOG_TRACE(kFileHandle, << "FileHandleImpl::[sync]PositionRead("
                          << FMT_THIS_ADDR << ", buf=" << buf
                          << ", nbyte=" << *nbyte << ") called");
+  size_t totalBytesRead = 0;
+  Status stat = Status::OK();
+  while (*nbyte != 0 && offset < (off_t)(file_info_->file_length_)) {
+    auto callstate = std::make_shared<std::promise<std::tuple<Status, size_t>>>();
+    std::future<std::tuple<Status, size_t>> future(callstate->get_future());
 
-  auto callstate = std::make_shared<std::promise<std::tuple<Status, size_t>>>();
-  std::future<std::tuple<Status, size_t>> future(callstate->get_future());
+    /* wrap async call with promise/future to make it blocking */
+    auto callback = [callstate](const Status &s, size_t bytes) {
+      callstate->set_value(std::make_tuple(s,bytes));
+    };
 
-  /* wrap async call with promise/future to make it blocking */
-  auto callback = [callstate](const Status &s, size_t bytes) {
-    callstate->set_value(std::make_tuple(s,bytes));
-  };
+    PositionRead(buf, *nbyte, offset, callback);
 
-  PositionRead(buf, *nbyte, offset, callback);
+    /* wait for async to finish */
+    auto returnstate = future.get();
+    stat = std::get<0>(returnstate);
 
-  /* wait for async to finish */
-  auto returnstate = future.get();
-  auto stat = std::get<0>(returnstate);
+    if (!stat.ok()) {
+      return stat;
+    }
 
-  if (!stat.ok()) {
-    return stat;
+    size_t bytesRead = std::get<1>(returnstate);
+    *nbyte = *nbyte - bytesRead;
+    totalBytesRead += bytesRead;
+    offset += bytesRead;
   }
-
-  *nbyte = std::get<1>(returnstate);
+  /* Update the bytes read for return */
+  *nbyte = totalBytesRead;
   return stat;
 }
 
@@ -110,8 +118,8 @@ Status FileHandleImpl::Read(void *buf, size_t *nbyte) {
   if(!stat.ok()) {
     return stat;
   }
-
   offset_ += *nbyte;
+
   return Status::OK();
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message