Skip to content
16 changes: 13 additions & 3 deletions src/Databases/DataLake/RestCatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,14 +1053,15 @@ 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<DB::ReadSettings> read_settings_override) const
{
std::ostringstream oss; // STYLE_CHECK_ALLOW_STD_STRING_STREAM
if (request_body)
request_body->stringify(oss);
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())
Expand All @@ -1082,7 +1083,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)
Expand Down Expand Up @@ -1117,7 +1118,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;

@subkanthi subkanthi Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldnt find a better way to stop retrying as the retries happen in sendRequest, adding to nonRetriable error codes will affect all http calls.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http_max_retries is checked in ReadWriteBufferFromHTTP::doWithRetries.
try-catch block in this method set local variable is_retriable to false for some cases.
I think better to improve this way - add some hint or callback with additional logic, which errors are retriable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it is important to understand what the correct behavior should be. Either ClickHouse or ice-rest-catalog is doing something wrong. I don't think we should be getting namespace already exists in each commit we try to do.

Either ClickHouse is sending a request with wrong arguments or ice-rest-catalog is responding the wrong code.

sendRequest(endpoint, request_body, Poco::Net::HTTPRequest::HTTP_POST, false, read_settings);
Comment on lines +1121 to +1123
}
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 (...)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Databases/DataLake/RestCatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Databases/DataLake/ICatalog.h>
#include <Poco/Net/HTTPBasicCredentials.h>
#include <IO/ReadWriteBufferFromHTTP.h>
#include <IO/ReadSettings.h>
#include <IO/HTTPHeaderEntries.h>
#include <Interpreters/Context_fwd.h>
#include <base/defines.h>
Expand Down Expand Up @@ -217,7 +218,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<DB::ReadSettings> read_settings_override = std::nullopt) const;

VendedStorageCredentials getCredentialsAndEndpoint(Poco::JSON::Object::Ptr object, const String & location) const;

Expand Down
Loading