HDFS-10543: libhdfs++: hdfsRead stops at block boundary. Contributed by Xiaowei Zhu.
This commit is contained in:
parent
d4c3cfbf47
commit
a0c7aee3b6
@ -78,7 +78,9 @@ 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());
|
||||
|
||||
@ -91,13 +93,19 @@ Status FileHandleImpl::PositionRead(void *buf, size_t *nbyte, off_t offset) {
|
||||
|
||||
/* wait for async to finish */
|
||||
auto returnstate = future.get();
|
||||
auto stat = std::get<0>(returnstate);
|
||||
stat = std::get<0>(returnstate);
|
||||
|
||||
if (!stat.ok()) {
|
||||
return stat;
|
||||
}
|
||||
|
||||
*nbyte = std::get<1>(returnstate);
|
||||
size_t bytesRead = std::get<1>(returnstate);
|
||||
*nbyte = *nbyte - bytesRead;
|
||||
totalBytesRead += bytesRead;
|
||||
offset += bytesRead;
|
||||
}
|
||||
/* 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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user