Allow to DROP database with Dictionary engine

This commit is contained in:
Alexey Milovidov 2019-06-29 20:27:32 +03:00
parent de8a15b5f4
commit 90898905e0
4 changed files with 16 additions and 13 deletions

View File

@ -86,7 +86,7 @@ DatabaseIteratorPtr DatabaseDictionary::getIterator(const Context & context, con
bool DatabaseDictionary::empty(const Context & context) const
{
return context.getExternalDictionaries().getNumberOfNames() == 0;
return !context.getExternalDictionaries().hasCurrentlyLoadedObjects();
}
StoragePtr DatabaseDictionary::detachTable(const String & /*table_name*/)

View File

@ -343,12 +343,6 @@ public:
enable_async_loading = enable;
}
size_t getNumberOfNames() const
{
std::lock_guard lock{mutex};
return infos.size();
}
/// Returns the status of the object.
/// If the object has not been loaded yet then the function returns Status::NOT_LOADED.
/// If the specified name isn't found in the configuration then the function returns Status::NOT_EXIST.
@ -406,6 +400,15 @@ public:
return count;
}
bool hasCurrentlyLoadedObjects() const
{
std::lock_guard lock{mutex};
for (auto & [name, info] : infos)
if (info.loaded())
return true;
return false;
}
/// Starts loading of a specified object.
void load(const String & name)
{
@ -995,9 +998,9 @@ void ExternalLoader::enablePeriodicUpdates(bool enable_, const ExternalLoaderUpd
periodic_updater->enable(enable_, settings_);
}
size_t ExternalLoader::getNumberOfNames() const
bool ExternalLoader::hasCurrentlyLoadedObjects() const
{
return loading_dispatcher->getNumberOfNames();
return loading_dispatcher->hasCurrentlyLoadedObjects();
}
ExternalLoader::Status ExternalLoader::getCurrentStatus(const String & name) const

View File

@ -107,9 +107,6 @@ public:
/// Sets settings for periodic updates.
void enablePeriodicUpdates(bool enable, const ExternalLoaderUpdateSettings & settings = {});
/// Returns the names of all the objects in the configuration (loaded or not).
size_t getNumberOfNames() const;
/// Returns the status of the object.
/// If the object has not been loaded yet then the function returns Status::NOT_LOADED.
/// If the specified name isn't found in the configuration then the function returns Status::NOT_EXIST.
@ -132,6 +129,9 @@ public:
Loadables getCurrentlyLoadedObjects(const FilterByNameFunction & filter_by_name) const;
size_t getNumberOfCurrentlyLoadedObjects() const;
/// Returns true if any object was loaded.
bool hasCurrentlyLoadedObjects() const;
static constexpr Duration NO_TIMEOUT = Duration::max();
/// Starts loading of a specified object.

View File

@ -30,5 +30,5 @@ CREATE DATABASE test_DatabaseDictionary ENGINE = Dictionary;
SELECT sum(ignore(*, metadata_modification_time, engine_full, create_table_query)) FROM system.tables;
DROP DATABASE test_DatabaseDictionary; -- { serverError 48 }
DROP DATABASE test_DatabaseDictionary;
DROP DATABASE test_DatabaseMemory;