Throw an error instead of silenty ignore storage_file_read_method=mmap in server

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-06-24 21:14:28 +02:00
parent 0c7a4142e4
commit a7b14f87e0
2 changed files with 6 additions and 4 deletions

View File

@ -205,7 +205,7 @@ std::unique_ptr<ReadBuffer> selectReadBuffer(
{
auto read_method = context->getSettingsRef().storage_file_read_method;
/** But using mmap on server-side is unsafe for the following reasons:
/** Using mmap on server-side is unsafe for the following reasons:
* - concurrent modifications of a file will result in SIGBUS;
* - IO error from the device will result in SIGBUS;
* - recovery from this signal is not feasible even with the usage of siglongjmp,
@ -214,10 +214,10 @@ std::unique_ptr<ReadBuffer> selectReadBuffer(
*
* But we keep this mode for clickhouse-local as it is not so bad for a command line tool.
*/
if (context->getApplicationType() == Context::ApplicationType::SERVER && read_method == LocalFSReadMethod::mmap)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Using storage_file_read_method=mmap is not safe in server mode. Consider using pread.");
if (S_ISREG(file_stat.st_mode)
&& context->getApplicationType() != Context::ApplicationType::SERVER
&& read_method == LocalFSReadMethod::mmap)
if (S_ISREG(file_stat.st_mode) && read_method == LocalFSReadMethod::mmap)
{
try
{

View File

@ -13,4 +13,6 @@ $CLICKHOUSE_LOCAL --storage_file_read_method=mmap --print-profile-events -q "SEL
$CLICKHOUSE_LOCAL --storage_file_read_method=pread --print-profile-events -q "SELECT * FROM file($DATA_FILE) FORMAT Null" 2>&1 | grep -F -c "CreatedReadBufferMMap"
$CLICKHOUSE_LOCAL --storage_file_read_method=pread --print-profile-events -q "SELECT * FROM file($DATA_FILE) FORMAT Null" 2>&1 | grep -F -c "CreatedReadBufferOrdinary"
$CLICKHOUSE_CLIENT --storage_file_read_method=mmap -nq "SELECT * FROM file('/dev/null', 'LineAsString') FORMAT Null -- { serverError BAD_ARGUMENTS }"
rm $DATA_FILE