Better check of dictionary lifetime for updates

This commit is contained in:
alesapin 2019-10-23 16:02:40 +03:00
parent 6a0246f58e
commit c3519ff376
3 changed files with 34 additions and 4 deletions

View File

@ -848,7 +848,11 @@ private:
else
error_count = 0;
next_update_time = calculateNextUpdateTime(new_object, error_count);
LoadablePtr object = previous_version;
if (new_object)
object = new_object;
next_update_time = calculateNextUpdateTime(object, error_count);
}
catch (...)
{
@ -963,7 +967,8 @@ private:
TimePoint calculateNextUpdateTime(const LoadablePtr & loaded_object, size_t error_count) const
{
static constexpr auto never = TimePoint::max();
if (!error_count)
if (loaded_object)
{
if (!loaded_object->supportUpdates())
return never;
@ -973,8 +978,11 @@ private:
if (lifetime.min_sec == 0 || lifetime.max_sec == 0)
return never;
std::uniform_int_distribution<UInt64> distribution{lifetime.min_sec, lifetime.max_sec};
return std::chrono::system_clock::now() + std::chrono::seconds{distribution(rnd_engine)};
if (!error_count)
{
std::uniform_int_distribution<UInt64> distribution{lifetime.min_sec, lifetime.max_sec};
return std::chrono::system_clock::now() + std::chrono::seconds{distribution(rnd_engine)};
}
}
return std::chrono::system_clock::now() + std::chrono::seconds(calculateDurationWithBackoff(rnd_engine, error_count));

View File

@ -15,3 +15,5 @@ dict2 Dictionary
table_for_dict MergeTree
database_for_dict dict1 ComplexKeyCache
database_for_dict dict2 Hashed
6
6

View File

@ -95,4 +95,24 @@ SELECT name, engine FROM system.tables WHERE database = 'database_for_dict' ORDE
SELECT database, name, type FROM system.dictionaries WHERE database = 'database_for_dict' ORDER BY name;
-- check dictionary will not update
CREATE DICTIONARY database_for_dict.dict3
(
key_column UInt64 DEFAULT 0,
some_column String EXPRESSION toString(fourth_column),
fourth_column Float64 DEFAULT 42.0
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' DB 'database_for_dict'))
LIFETIME(0)
LAYOUT(HASHED());
SELECT dictGetString('database_for_dict.dict3', 'some_column', toUInt64(12));
DROP TABLE database_for_dict.table_for_dict;
SYSTEM RELOAD DICTIONARIES;
SELECT dictGetString('database_for_dict.dict3', 'some_column', toUInt64(12));
DROP DATABASE IF EXISTS database_for_dict;