Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improve HDFS ReadBuffer for read end of file #50063

Merged
merged 12 commits into from Aug 3, 2023
6 changes: 6 additions & 0 deletions src/Storages/HDFS/ReadBufferFromHDFS.cpp
Expand Up @@ -41,6 +41,7 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S

off_t file_offset = 0;
off_t read_until_position = 0;
off_t file_size;

explicit ReadBufferFromHDFSImpl(
const std::string & hdfs_uri_,
Expand All @@ -63,6 +64,7 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S
throw Exception(ErrorCodes::CANNOT_OPEN_FILE,
"Unable to open HDFS file: {}. Error: {}",
hdfs_uri + hdfs_file_path, std::string(hdfsGetLastError()));
file_size = getFileSize();
kssenii marked this conversation as resolved.
Show resolved Hide resolved
}

~ReadBufferFromHDFSImpl() override
Expand Down Expand Up @@ -95,6 +97,10 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S
{
num_bytes_to_read = internal_buffer.size();
}
if (file_size != 0 && file_offset >= file_size)
{
return false;
}

ResourceGuard rlock(read_settings.resource_link, num_bytes_to_read);
int bytes_read;
Expand Down