Update AsynchronousReadIndirectBufferFromRemoteFS.cpp

This commit is contained in:
Kseniia Sumarokova 2022-11-25 16:01:06 +01:00 committed by GitHub
parent ce062d2e01
commit 37d1eb353f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,8 +133,18 @@ void AsynchronousReadIndirectBufferFromRemoteFS::prefetch()
void AsynchronousReadIndirectBufferFromRemoteFS::setReadUntilPosition(size_t position)
{
/// Do not reinitialize internal state in case the new end of range is already included.
/// Actually it is likely that we will anyway reinitialize it as seek method is called after
/// changing end position, but seek avoiding feature might help to avoid reinitialization,
/// so this check is useful to save the prefetch for the time when we try to avoid seek by
/// reading and ignoring some data.
if (!read_until_position || position > *read_until_position)
{
/// We must wait on future and reset the prefetch here, because otherwise there might be
/// a race between reading the data in the threadpool and impl->setReadUntilPosition()
/// which reinitializes internal remote read buffer (because if we have a new read range
/// then we need a new range request) and in case of reading from cache we need to request
/// and hold more file segment ranges from cache.
if (prefetch_future.valid())
{
ProfileEvents::increment(ProfileEvents::RemoteFSCancelledPrefetches);