mirror of https://github.com/ByConity/ByConity
Fixed error when too long merges cannot be successful [#METR-21616].
This commit is contained in:
parent
3144117b44
commit
168ca22435
|
@ -47,6 +47,9 @@ struct MergeTreeSettings
|
||||||
/// Через сколько секунд удалять ненужные куски.
|
/// Через сколько секунд удалять ненужные куски.
|
||||||
time_t old_parts_lifetime = 8 * 60;
|
time_t old_parts_lifetime = 8 * 60;
|
||||||
|
|
||||||
|
/// Через сколько секунд удалять tmp_-директории.
|
||||||
|
time_t temporary_directories_lifetime = 86400;
|
||||||
|
|
||||||
/** Настройки вставок. */
|
/** Настройки вставок. */
|
||||||
|
|
||||||
/// Если в таблице хотя бы столько активных кусков, искусственно замедлять вставки в таблицу.
|
/// Если в таблице хотя бы столько активных кусков, искусственно замедлять вставки в таблицу.
|
||||||
|
|
|
@ -379,6 +379,26 @@ void MergeTreeData::loadDataParts(bool skip_sanity_checks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Является ли директория куска старой.
|
||||||
|
* Это так, если её дата модификации,
|
||||||
|
* и одновременно дата модификации всех файлов внутри неё
|
||||||
|
* (рассматриваются файлы только на одном уровне вложенности),
|
||||||
|
* меньше threshold.
|
||||||
|
*/
|
||||||
|
static bool isOldPartDirectory(Poco::File & directory, time_t threshold)
|
||||||
|
{
|
||||||
|
if (directory.getLastModified().epochTime() >= threshold)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Poco::DirectoryIterator end;
|
||||||
|
for (Poco::DirectoryIterator it(directory); it != end; ++it)
|
||||||
|
if (it->getLastModified().epochTime() >= threshold)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MergeTreeData::clearOldTemporaryDirectories()
|
void MergeTreeData::clearOldTemporaryDirectories()
|
||||||
{
|
{
|
||||||
/// Если метод уже вызван из другого потока, то можно ничего не делать.
|
/// Если метод уже вызван из другого потока, то можно ничего не делать.
|
||||||
|
@ -386,6 +406,8 @@ void MergeTreeData::clearOldTemporaryDirectories()
|
||||||
if (!lock.try_lock())
|
if (!lock.try_lock())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
time_t current_time = time(0);
|
||||||
|
|
||||||
/// Удаляем временные директории старше суток.
|
/// Удаляем временные директории старше суток.
|
||||||
Poco::DirectoryIterator end;
|
Poco::DirectoryIterator end;
|
||||||
for (Poco::DirectoryIterator it{full_path}; it != end; ++it)
|
for (Poco::DirectoryIterator it{full_path}; it != end; ++it)
|
||||||
|
@ -396,7 +418,7 @@ void MergeTreeData::clearOldTemporaryDirectories()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (tmp_dir.isDirectory() && tmp_dir.getLastModified().epochTime() + 86400 < time(0))
|
if (tmp_dir.isDirectory() && isOldPartDirectory(tmp_dir, current_time - settings.temporary_directories_lifetime))
|
||||||
{
|
{
|
||||||
LOG_WARNING(log, "Removing temporary directory " << full_path << it.name());
|
LOG_WARNING(log, "Removing temporary directory " << full_path << it.name());
|
||||||
Poco::File(full_path + it.name()).remove(true);
|
Poco::File(full_path + it.name()).remove(true);
|
||||||
|
|
Loading…
Reference in New Issue