From 9d5c43454239049a4cfcdd29eec7fd9e41a3e879 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 16 Jun 2026 23:21:29 +0200 Subject: [PATCH 1/4] Added handling of 409 namespacealreadyexists in createNamespaceIfNotExists --- src/Databases/DataLake/RestCatalog.cpp | 21 ++++++++++++++++++--- src/Databases/DataLake/RestCatalog.h | 4 +++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Databases/DataLake/RestCatalog.cpp b/src/Databases/DataLake/RestCatalog.cpp index 60e6dbc59c12..5ee4eb74763c 100644 --- a/src/Databases/DataLake/RestCatalog.cpp +++ b/src/Databases/DataLake/RestCatalog.cpp @@ -1021,7 +1021,12 @@ 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 +1034,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 ? *read_settings_override : context->getReadSettings(); DB::ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback; if (!body_str.empty()) @@ -1050,7 +1056,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 +1091,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; From d356334f36e5fd8a04778c6e8a4ce9dd8ae31762 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 16 Jun 2026 23:27:14 +0200 Subject: [PATCH 2/4] Added handling of 409 namespacealreadyexists in createNamespaceIfNotExists --- src/Databases/DataLake/RestCatalog.cpp | 6 ++---- src/Databases/DataLake/RestCatalog.h | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Databases/DataLake/RestCatalog.cpp b/src/Databases/DataLake/RestCatalog.cpp index 5ee4eb74763c..a66f2c7c1589 100644 --- a/src/Databases/DataLake/RestCatalog.cpp +++ b/src/Databases/DataLake/RestCatalog.cpp @@ -1056,7 +1056,7 @@ void RestCatalog::sendRequest( auto wb = DB::BuilderRWBufferFromHTTP(url) .withConnectionGroup(DB::HTTPConnectionGroupType::HTTP) .withMethod(method) - .withSettings(read_settings) + .withSettings(context->getReadSettings()) .withTimeouts(DB::ConnectionTimeouts::getHTTPTimeouts(context->getSettingsRef(), context->getServerSettings())) .withHostFilter(&context->getRemoteHostFilter()) .withHeaders(headers) @@ -1091,9 +1091,7 @@ void RestCatalog::createNamespaceIfNotExists(const String & namespace_name, cons { ProfileEvents::increment(ProfileEvents::DataLakeRestCatalogCreateNamespace); auto timer = DB::CurrentThread::getProfileEvents().timer(ProfileEvents::DataLakeRestCatalogCreateNamespaceMicroseconds); - DB::ReadSettings read_settings = getContext()->getReadSettings(); - read_settings.http_max_tries = 1; - sendRequest(endpoint, request_body, Poco::Net::HTTPRequest::HTTP_POST, false, read_settings); + sendRequest(endpoint, request_body); } catch (const DB::HTTPException & e) { diff --git a/src/Databases/DataLake/RestCatalog.h b/src/Databases/DataLake/RestCatalog.h index a66044505d59..49fe684e0eaa 100644 --- a/src/Databases/DataLake/RestCatalog.h +++ b/src/Databases/DataLake/RestCatalog.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -193,8 +192,7 @@ 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, - std::optional read_settings_override = std::nullopt) const; + bool ignore_result = false) const; std::pair, String> getCredentialsAndEndpoint(Poco::JSON::Object::Ptr object, const String & location) const; From 105f7297e19869e5a01d8bca216ce365504e2671 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 16 Jun 2026 23:31:46 +0200 Subject: [PATCH 3/4] rollback not required change --- src/Databases/DataLake/RestCatalog.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Databases/DataLake/RestCatalog.cpp b/src/Databases/DataLake/RestCatalog.cpp index a66f2c7c1589..2ee8f2b35d1b 100644 --- a/src/Databases/DataLake/RestCatalog.cpp +++ b/src/Databases/DataLake/RestCatalog.cpp @@ -1021,12 +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, - std::optional read_settings_override) const +void RestCatalog::sendRequest(const String & endpoint, Poco::JSON::Object::Ptr request_body, const String & method, bool ignore_result) const { std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM if (request_body) @@ -1034,7 +1029,6 @@ void RestCatalog::sendRequest( const std::string body_str = DB::removeEscapedSlashes(oss.str()); const auto & context = getContext(); - DB::ReadSettings read_settings = read_settings_override ? *read_settings_override : context->getReadSettings(); DB::ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback; if (!body_str.empty()) From 9ea143f7d6245543042feb2d2fdd4d8085605428 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 16 Jun 2026 23:53:14 +0200 Subject: [PATCH 4/4] set http_max_tries to 1 for createNamespaceIfNotExists --- src/Databases/DataLake/RestCatalog.cpp | 9 ++++++--- src/Databases/DataLake/RestCatalog.h | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Databases/DataLake/RestCatalog.cpp b/src/Databases/DataLake/RestCatalog.cpp index 2ee8f2b35d1b..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,9 @@ 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) { 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;