This commit is contained in:
Nikita Mikhaylov 2024-02-09 23:25:02 +01:00
parent 64596c6b3b
commit d726f28b6c
6 changed files with 37 additions and 14 deletions

View File

@ -46,12 +46,14 @@ static constexpr size_t METADATA_FILE_BUFFER_SIZE = 32768;
DatabaseOrdinary::DatabaseOrdinary(const String & name_, const String & metadata_path_, ContextPtr context_)
: DatabaseOrdinary(name_, metadata_path_, "data/" + escapeForFileName(name_) + "/", "DatabaseOrdinary (" + name_ + ")", context_)
{
getContext()->addWarningMessageAboutDatabaseOrdinary(name_);
}
DatabaseOrdinary::DatabaseOrdinary(
const String & name_, const String & metadata_path_, const String & data_path_, const String & logger, ContextPtr context_)
: DatabaseOnDisk(name_, metadata_path_, data_path_, logger, context_)
{
getContext()->addWarningMessageAboutDatabaseOrdinary(name_);
}
void DatabaseOrdinary::loadStoredObjects(ContextMutablePtr, LoadingStrictnessLevel)

View File

@ -1171,6 +1171,30 @@ void Context::addWarningMessage(const String & msg) const
shared->addWarningMessage(msg);
}
void Context::addWarningMessageAboutDatabaseOrdinary(const String & database_name) const
{
std::lock_guard lock(shared->mutex);
/// We would like to report only about the first database with engine Ordinary
static std::atomic_bool is_called = false;
if (is_called.exchange(true))
return;
auto suppress_re = shared->getConfigRefWithLock(lock).getString("warning_supress_regexp", "");
/// We don't use getFlagsPath method, because it takes a shared lock.
auto convert_databases_flag = fs::path(shared->flags_path) / "convert_ordinary_to_atomic";
auto message = fmt::format("Server has databases (for example `{}`) with Ordinary engine, which was deprecated.\n"
"To convert this database to a new Atomic engine, please create a forcing flag {} and make sure that ClickHouse has write permission for it.\n"
"Example:\n"
"sudo touch '{}' && sudo chmod 666 '{}'",
database_name,
convert_databases_flag.string(), convert_databases_flag.string(), convert_databases_flag.string());
bool is_supressed = !suppress_re.empty() && re2::RE2::PartialMatch(message, suppress_re);
if (!is_supressed)
shared->addWarningMessage(message);
}
void Context::setConfig(const ConfigurationPtr & config)
{
shared->setConfig(config);

View File

@ -532,6 +532,7 @@ public:
void setUserScriptsPath(const String & path);
void addWarningMessage(const String & msg) const;
void addWarningMessageAboutDatabaseOrdinary(const String & database_name) const;
void setTemporaryStorageInCache(const String & cache_disk_name, size_t max_size);
void setTemporaryStoragePolicy(const String & policy_name, size_t max_size);

View File

@ -227,26 +227,13 @@ LoadTaskPtrs loadMetadata(ContextMutablePtr context, const String & default_data
databases.emplace(default_database_name, std::filesystem::path(path) / escapeForFileName(default_database_name));
}
bool has_ordinary_databases = false;
TablesLoader::Databases loaded_databases;
for (const auto & [name, db_path] : databases)
{
loadDatabase(context, name, db_path, has_force_restore_data_flag);
auto database = DatabaseCatalog::instance().getDatabase(name);
loaded_databases.insert({name, database});
if (database->getEngineName() == "Ordinary")
has_ordinary_databases = true;
loaded_databases.insert({name,database});
loaded_databases.insert({name, DatabaseCatalog::instance().getDatabase(name)});
}
if (has_ordinary_databases)
context->addWarningMessage("Server has databases with Ordinary engine, which is not optimal. \n "
"To convert this database to a new Atomic engine, please create a flag named `convert_ordinary_to_atomic` in flags directory");
auto mode = getLoadingStrictnessLevel(/* attach */ true, /* force_attach */ true, has_force_restore_data_flag);
TablesLoader loader{context, std::move(loaded_databases), mode};
auto load_tasks = loader.loadTablesAsync();

View File

@ -0,0 +1,8 @@
DROP DATABASE IF EXISTS 02988_ordinary;
SET allow_deprecated_database_ordinary = 1;
CREATE DATABASE 02988_ordinary ENGINE=Ordinary;
SELECT 'Ok.' FROM system.warnings WHERE message ILIKE '%Ordinary%' and message ILIKE '%deprecated%';
DROP DATABASE IF EXISTS 02988_ordinary;