Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the limit on the number of opened files in clickhouse-local #46853

Merged
merged 4 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions programs/local/LocalServer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "LocalServer.h"

#include <sys/resource.h>
#include <Common/logger_useful.h>
#include <base/errnoToString.h>
#include <Poco/Util/XMLConfiguration.h>
#include <Poco/String.h>
#include <Poco/Logger.h>
Expand Down Expand Up @@ -179,9 +182,9 @@ void LocalServer::tryInitPath()
parent_folder = std::filesystem::temp_directory_path();

}
catch (const fs::filesystem_error& e)
catch (const fs::filesystem_error & e)
{
// tmp folder don't exists? misconfiguration? chroot?
// The tmp folder doesn't exist? Is it a misconfiguration? Or chroot?
LOG_DEBUG(log, "Can not get temporary folder: {}", e.what());
parent_folder = std::filesystem::current_path();

Expand Down Expand Up @@ -390,6 +393,21 @@ try
std::cout << std::fixed << std::setprecision(3);
std::cerr << std::fixed << std::setprecision(3);

/// Try to increase limit on number of open files.
{
rlimit rlim;
if (getrlimit(RLIMIT_NOFILE, &rlim))
throw Poco::Exception("Cannot getrlimit");

if (rlim.rlim_cur < rlim.rlim_max)
{
rlim.rlim_cur = config().getUInt("max_open_files", static_cast<unsigned>(rlim.rlim_max));
int rc = setrlimit(RLIMIT_NOFILE, &rlim);
if (rc != 0)
std::cerr << fmt::format("Cannot set max number of file descriptors to {}. Try to specify max_open_files according to your system limits. error: {}", rlim.rlim_cur, errnoToString()) << '\n';
}
}

#if defined(FUZZING_MODE)
static bool first_time = true;
if (first_time)
Expand Down
1 change: 0 additions & 1 deletion programs/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <Poco/Version.h>
#include <Poco/Net/HTTPServer.h>
#include <Poco/Net/NetException.h>
#include <Poco/Util/HelpFormatter.h>
Expand Down
27 changes: 15 additions & 12 deletions src/IO/ReadWriteBufferFromHTTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ namespace detail

enum class InitializeError
{
RETRIABLE_ERROR,
RETRYABLE_ERROR,
/// If error is not retriable, `exception` variable must be set.
NON_RETRIABLE_ERROR,
NON_RETRYABLE_ERROR,
/// Allows to skip not found urls for globs
SKIP_NOT_FOUND_URL,
NONE,
Expand Down Expand Up @@ -398,7 +398,7 @@ namespace detail
}
else if (!isRetriableError(http_status))
{
initialization_error = InitializeError::NON_RETRIABLE_ERROR;
initialization_error = InitializeError::NON_RETRYABLE_ERROR;
exception = std::current_exception();
}
else
Expand All @@ -409,7 +409,7 @@ namespace detail
}

/**
* Throws if error is retriable, otherwise sets initialization_error = NON_RETRIABLE_ERROR and
* Throws if error is retryable, otherwise sets initialization_error = NON_RETRYABLE_ERROR and
* saves exception into `exception` variable. In case url is not found and skip_not_found_url == true,
* sets initialization_error = SKIP_NOT_FOUND_URL, otherwise throws.
*/
Expand Down Expand Up @@ -453,9 +453,9 @@ namespace detail

/// Retry 200OK
if (response.getStatus() == Poco::Net::HTTPResponse::HTTPStatus::HTTP_OK)
initialization_error = InitializeError::RETRIABLE_ERROR;
initialization_error = InitializeError::RETRYABLE_ERROR;
else
initialization_error = InitializeError::NON_RETRIABLE_ERROR;
initialization_error = InitializeError::NON_RETRYABLE_ERROR;

return;
}
Expand Down Expand Up @@ -544,7 +544,7 @@ namespace detail
{
initialize();

if (initialization_error == InitializeError::NON_RETRIABLE_ERROR)
if (initialization_error == InitializeError::NON_RETRYABLE_ERROR)
{
assert(exception);
break;
Expand All @@ -553,7 +553,7 @@ namespace detail
{
return false;
}
else if (initialization_error == InitializeError::RETRIABLE_ERROR)
else if (initialization_error == InitializeError::RETRYABLE_ERROR)
{
LOG_ERROR(
log,
Expand Down Expand Up @@ -582,10 +582,13 @@ namespace detail
}
catch (const Poco::Exception & e)
{
/**
* Retry request unconditionally if nothing has been read yet.
* Otherwise if it is GET method retry with range header.
*/
/// Too many open files - non-retryable.
if (e.code() == POCO_EMFILE)
throw;

/** Retry request unconditionally if nothing has been read yet.
* Otherwise if it is GET method retry with range header.
*/
bool can_retry_request = !offset_from_begin_pos || method == Poco::Net::HTTPRequest::HTTP_GET;
if (!can_retry_request)
throw;
Expand Down