Skip to content

Commit

Permalink
Merge pull request #60900 from ClickHouse/cherrypick/23.8/a39c00aab50…
Browse files Browse the repository at this point in the history
…80824fddc3eec5042b9e8ba405d76

Cherry pick #60849 to 23.8: Remove recursion when reading from S3
  • Loading branch information
robot-clickhouse-ci-2 committed Mar 6, 2024
2 parents 06d3515 + bbecd29 commit 64bfa3c
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/Storages/StorageS3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,36 @@ class StorageS3Source::DisclosedGlobIterator::Impl : WithContext

KeyWithInfo nextAssumeLocked()
{
if (buffer_iter != buffer.end())
do
{
auto answer = *buffer_iter;
++buffer_iter;
return answer;
}
if (buffer_iter != buffer.end())
{
auto answer = *buffer_iter;
++buffer_iter;
return answer;
}

if (is_finished)
return {};
if (is_finished)
return {};

try
{
fillInternalBufferAssumeLocked();
}
catch (...)
{
/// In case of exception thrown while listing new batch of files
/// iterator may be partially initialized and its further using may lead to UB.
/// Iterator is used by several processors from several threads and
/// it may take some time for threads to stop processors and they
/// may still use this iterator after exception is thrown.
/// To avoid this UB, reset the buffer and return defaults for further calls.
is_finished = true;
buffer.clear();
buffer_iter = buffer.begin();
throw;
}

return nextAssumeLocked();
try
{
fillInternalBufferAssumeLocked();
}
catch (...)
{
/// In case of exception thrown while listing new batch of files
/// iterator may be partially initialized and its further using may lead to UB.
/// Iterator is used by several processors from several threads and
/// it may take some time for threads to stop processors and they
/// may still use this iterator after exception is thrown.
/// To avoid this UB, reset the buffer and return defaults for further calls.
is_finished = true;
buffer.clear();
buffer_iter = buffer.begin();
throw;
}
} while (true);
}

void fillInternalBufferAssumeLocked()
Expand Down

0 comments on commit 64bfa3c

Please sign in to comment.