fix metadata time

This commit is contained in:
Vasilyev Nikita 2019-10-03 17:18:17 +03:00
parent 66506e26d0
commit d6490892a7
4 changed files with 25 additions and 21 deletions

View File

@ -64,6 +64,12 @@ void DatabaseLazy::createTable(
if (!endsWith(table->getName(), "Log"))
throw Exception("Lazy engine can be used only with *Log tables.", ErrorCodes::UNSUPPORTED_METHOD);
DatabaseOnDisk::createTable(*this, context, table_name, table, query);
/// DatabaseOnDisk::createTable renames file, so we need to get new metadata_modification_time.
std::lock_guard lock(tables_mutex);
auto it = tables_cache.find(table_name);
if (it != tables_cache.end())
it->second.metadata_modification_time = DatabaseOnDisk::getTableMetadataModificationTime(*this, table_name);
}
@ -191,9 +197,7 @@ void DatabaseLazy::attachTable(const String & table_name, const StoragePtr & tab
auto [it, inserted] = tables_cache.emplace(std::piecewise_construct,
std::forward_as_tuple(table_name),
std::forward_as_tuple(table,
current_time,
DatabaseOnDisk::getTableMetadataModificationTime(*this, table_name)));
std::forward_as_tuple(table, current_time, DatabaseOnDisk::getTableMetadataModificationTime(*this, table_name)));
if (!inserted)
throw Exception("Table " + getDatabaseName() + "." + table_name + " already exists.", ErrorCodes::TABLE_ALREADY_EXISTS);

View File

@ -65,9 +65,9 @@ static bool needLockStructure(const DatabasePtr& database, const Block& header)
if (database->getEngineName() != "Lazy")
return true;
static std::set<std::string> columns_without_lock = { "database", "name", "metadata_modification_time" };
static const std::set<std::string> columns_without_lock = { "database", "name", "metadata_modification_time" };
for (const auto& column : header.getColumnsWithTypeAndName()) {
if (columns_without_lock.find(column.name) != columns_without_lock.end()) {
if (columns_without_lock.find(column.name) == columns_without_lock.end()) {
return true;
}
}

View File

@ -1,15 +1,15 @@
testlazy log Log 0 ['/var/lib/clickhouse/data/testlazy/log/'] /var/lib/clickhouse/metadata/testlazy/log.sql 0000-00-00 00:00:00 [] [] CREATE TABLE testlazy.log (`a` UInt64, `b` UInt64) ENGINE = Log Log
testlazy slog StripeLog 0 ['/var/lib/clickhouse/data/testlazy/slog/'] /var/lib/clickhouse/metadata/testlazy/slog.sql 0000-00-00 00:00:00 [] [] CREATE TABLE testlazy.slog (`a` UInt64, `b` UInt64) ENGINE = StripeLog StripeLog
testlazy tlog TinyLog 0 ['/var/lib/clickhouse/data/testlazy/tlog/'] /var/lib/clickhouse/metadata/testlazy/tlog.sql 0000-00-00 00:00:00 [] [] CREATE TABLE testlazy.tlog (`a` UInt64, `b` UInt64) ENGINE = TinyLog TinyLog
testlazy log 0000-00-00 00:00:00
testlazy slog 0000-00-00 00:00:00
testlazy tlog 0000-00-00 00:00:00
testlazy log2 0000-00-00 00:00:00
testlazy slog 0000-00-00 00:00:00
testlazy tlog 0000-00-00 00:00:00
testlazy log2 0000-00-00 00:00:00
testlazy slog 0000-00-00 00:00:00
testlazy tlog 0000-00-00 00:00:00
testlazy log CREATE TABLE testlazy.log (`a` UInt64, `b` UInt64) ENGINE = Log
testlazy slog CREATE TABLE testlazy.slog (`a` UInt64, `b` UInt64) ENGINE = StripeLog
testlazy tlog CREATE TABLE testlazy.tlog (`a` UInt64, `b` UInt64) ENGINE = TinyLog
testlazy log
testlazy slog
testlazy tlog
testlazy log2
testlazy slog
testlazy tlog
testlazy log2
testlazy slog
testlazy tlog
1 1
2 2
3 3

View File

@ -14,13 +14,13 @@ ${CLICKHOUSE_CLIENT} -n -q "
sleep 1.5
${CLICKHOUSE_CLIENT} -q "
SELECT * FROM system.tables WHERE database = 'testlazy';
SELECT database, name, create_table_query FROM system.tables WHERE database = 'testlazy';
"
sleep 1.5
${CLICKHOUSE_CLIENT} -q "
SELECT database, name, metadata_modification_time FROM system.tables WHERE database = 'testlazy';
SELECT database, name FROM system.tables WHERE database = 'testlazy';
"
sleep 1.5
@ -28,13 +28,13 @@ sleep 1.5
${CLICKHOUSE_CLIENT} -n -q "
SELECT * FROM testlazy.log LIMIT 0; -- drop testlazy.log from cache
RENAME TABLE testlazy.log TO testlazy.log2;
SELECT database, name, metadata_modification_time FROM system.tables WHERE database = 'testlazy';
SELECT database, name FROM system.tables WHERE database = 'testlazy';
"
sleep 1.5
${CLICKHOUSE_CLIENT} -q "
SELECT database, name, metadata_modification_time FROM system.tables WHERE database = 'testlazy';
SELECT database, name FROM system.tables WHERE database = 'testlazy';
"
sleep 1.5