Fix hdfs race

This commit is contained in:
kssenii 2024-04-20 14:46:32 +01:00
parent c7f0cfc4c2
commit a4daf2b454
2 changed files with 10 additions and 1 deletions

View File

@ -33,11 +33,16 @@ void HDFSObjectStorage::startup()
void HDFSObjectStorage::initializeHDFS() const
{
if (hdfs_fs)
if (initialized)
return;
std::lock_guard lock(init_mutex);
if (initialized)
return;
hdfs_builder = createHDFSBuilder(url, config);
hdfs_fs = createHDFSFS(hdfs_builder.get());
initialized = true;
}
ObjectStorageKey HDFSObjectStorage::generateObjectKeyForPath(const std::string & /* path */) const

View File

@ -121,6 +121,10 @@ private:
mutable HDFSBuilderWrapper hdfs_builder;
mutable HDFSFSPtr hdfs_fs;
mutable std::mutex init_mutex;
mutable std::atomic_bool initialized{false};
SettingsPtr settings;
std::string url;
std::string url_without_path;