get rid of copy-paste

This commit is contained in:
Vasilyev Nikita 2019-10-03 11:35:58 +03:00
parent 7ac9fadc0d
commit 2f4e7bbe7f
4 changed files with 25 additions and 25 deletions

View File

@ -46,18 +46,6 @@ namespace ErrorCodes
static constexpr size_t METADATA_FILE_BUFFER_SIZE = 32768;
static size_t getLastModifiedEpochTime(const String & table_metadata_path) {
Poco::File meta_file(table_metadata_path);
if (meta_file.exists())
{
return meta_file.getLastModified().epochTime();
}
else
{
return static_cast<time_t>(0);
}
}
DatabaseLazy::DatabaseLazy(const String & name_, const String & metadata_path_, time_t expiration_time_, const Context & context)
: name(name_)
@ -219,7 +207,7 @@ void DatabaseLazy::attachTable(const String & table_name, const StoragePtr & tab
std::forward_as_tuple(table_name),
std::forward_as_tuple(table,
current_time,
getLastModifiedEpochTime(getTableMetadataPath(table_name)))).second)
DatabaseOnDisk::getTableMetadataModificationTime(*this, table_name))).second)
throw Exception("Table " + getDatabaseName() + "." + table_name + " already exists.", ErrorCodes::TABLE_ALREADY_EXISTS);
if (!cache_expiration_queue.emplace(current_time, table_name).second)
throw Exception("Failed to insert element to expiration queue.", ErrorCodes::LOGICAL_ERROR);

View File

@ -233,6 +233,23 @@ String DatabaseOnDisk::getTableMetadataPath(const IDatabase & database, const St
return detail::getTableMetadataPath(database.getMetadataPath(), table_name);
}
time_t DatabaseOnDisk::getTableMetadataModificationTime(
const IDatabase & database,
const String & table_name)
{
String table_metadata_path = getTableMetadataPath(database, table_name);
Poco::File meta_file(table_metadata_path);
if (meta_file.exists())
{
return meta_file.getLastModified().epochTime();
}
else
{
return static_cast<time_t>(0);
}
}
void DatabaseOnDisk::iterateTableFiles(const IDatabase & database, Poco::Logger * log, const IteratingFunction & iterating_function)
{
Poco::DirectoryIterator dir_end;

View File

@ -64,6 +64,11 @@ public:
const IDatabase & database,
const String & table_name);
static time_t getTableMetadataModificationTime(
const IDatabase & database,
const String & table_name);
using IteratingFunction = std::function<void(const String &)>;
static void iterateTableFiles(const IDatabase & database, Poco::Logger * log, const IteratingFunction & iterating_function);

View File

@ -218,20 +218,10 @@ void DatabaseOrdinary::renameTable(
time_t DatabaseOrdinary::getTableMetadataModificationTime(
const Context & /*context*/,
const Context & /* context */,
const String & table_name)
{
String table_metadata_path = getTableMetadataPath(table_name);
Poco::File meta_file(table_metadata_path);
if (meta_file.exists())
{
return meta_file.getLastModified().epochTime();
}
else
{
return static_cast<time_t>(0);
}
return DatabaseOnDisk::getTableMetadataModificationTime(*this, table_name);
}
ASTPtr DatabaseOrdinary::getCreateTableQuery(const Context & context, const String & table_name) const