minor improve read buffer of hdfs

This commit is contained in:
kevinyhzou 2023-05-22 12:23:31 +08:00
parent da8590a26c
commit e6d6d41f22

View File

@ -41,6 +41,7 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S
off_t file_offset = 0; off_t file_offset = 0;
off_t read_until_position = 0; off_t read_until_position = 0;
off_t file_size;
explicit ReadBufferFromHDFSImpl( explicit ReadBufferFromHDFSImpl(
const std::string & hdfs_uri_, const std::string & hdfs_uri_,
@ -63,6 +64,7 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S
throw Exception(ErrorCodes::CANNOT_OPEN_FILE, throw Exception(ErrorCodes::CANNOT_OPEN_FILE,
"Unable to open HDFS file: {}. Error: {}", "Unable to open HDFS file: {}. Error: {}",
hdfs_uri + hdfs_file_path, std::string(hdfsGetLastError())); hdfs_uri + hdfs_file_path, std::string(hdfsGetLastError()));
file_size = getFileSize();
} }
~ReadBufferFromHDFSImpl() override ~ReadBufferFromHDFSImpl() override
@ -95,6 +97,10 @@ struct ReadBufferFromHDFS::ReadBufferFromHDFSImpl : public BufferWithOwnMemory<S
{ {
num_bytes_to_read = internal_buffer.size(); 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); ResourceGuard rlock(read_settings.resource_link, num_bytes_to_read);
int bytes_read; int bytes_read;