diff --git a/src/Databases/DataLake/RestCatalog.cpp b/src/Databases/DataLake/RestCatalog.cpp index 60e6dbc59c12..eaac3ea9b6ec 100644 --- a/src/Databases/DataLake/RestCatalog.cpp +++ b/src/Databases/DataLake/RestCatalog.cpp @@ -1021,7 +1021,7 @@ bool RestCatalog::getTableMetadataImpl( return true; } -void RestCatalog::sendRequest(const String & endpoint, Poco::JSON::Object::Ptr request_body, const String & method, bool ignore_result) const +void RestCatalog::sendRequest(const String & endpoint, Poco::JSON::Object::Ptr request_body, const String & method, bool ignore_result, std::optional read_settings_override) const { std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM if (request_body) @@ -1029,6 +1029,7 @@ void RestCatalog::sendRequest(const String & endpoint, Poco::JSON::Object::Ptr r const std::string body_str = DB::removeEscapedSlashes(oss.str()); const auto & context = getContext(); + DB::ReadSettings read_settings = read_settings_override.value_or(context->getReadSettings()); DB::ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback; if (!body_str.empty()) @@ -1050,7 +1051,7 @@ void RestCatalog::sendRequest(const String & endpoint, Poco::JSON::Object::Ptr r auto wb = DB::BuilderRWBufferFromHTTP(url) .withConnectionGroup(DB::HTTPConnectionGroupType::HTTP) .withMethod(method) - .withSettings(context->getReadSettings()) + .withSettings(read_settings) .withTimeouts(DB::ConnectionTimeouts::getHTTPTimeouts(context->getSettingsRef(), context->getServerSettings())) .withHostFilter(&context->getRemoteHostFilter()) .withHeaders(headers) @@ -1085,7 +1086,16 @@ void RestCatalog::createNamespaceIfNotExists(const String & namespace_name, cons { ProfileEvents::increment(ProfileEvents::DataLakeRestCatalogCreateNamespace); auto timer = DB::CurrentThread::getProfileEvents().timer(ProfileEvents::DataLakeRestCatalogCreateNamespaceMicroseconds); - sendRequest(endpoint, request_body); + DB::ReadSettings read_settings = getContext()->getReadSettings(); + read_settings.http_max_tries = 1; + sendRequest(endpoint, request_body, Poco::Net::HTTPRequest::HTTP_POST, false, read_settings); + } + catch (const DB::HTTPException & e) + { + if (e.getHTTPStatus() == Poco::Net::HTTPResponse::HTTP_CONFLICT) + LOG_DEBUG(log, "Namespace {} already exists", namespace_name); + else + DB::tryLogCurrentException(log); } catch (...) { diff --git a/src/Databases/DataLake/RestCatalog.h b/src/Databases/DataLake/RestCatalog.h index 49fe684e0eaa..a66044505d59 100644 --- a/src/Databases/DataLake/RestCatalog.h +++ b/src/Databases/DataLake/RestCatalog.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -192,7 +193,8 @@ class RestCatalog : public ICatalog, public DB::WithContext const String & endpoint, Poco::JSON::Object::Ptr request_body, const String & method = Poco::Net::HTTPRequest::HTTP_POST, - bool ignore_result = false) const; + bool ignore_result = false, + std::optional read_settings_override = std::nullopt) const; std::pair, String> getCredentialsAndEndpoint(Poco::JSON::Object::Ptr object, const String & location) const;