Merge pull request #54506 from azat/system.detached_parts-modification_time

Add modification_time into system.detached_parts
This commit is contained in:
Alexey Milovidov 2023-09-12 04:53:59 +03:00 committed by GitHub
commit e9daff6c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeNullable.h>
#include <Storages/IStorage.h>
#include <Storages/MergeTree/DataPartStorageOnDiskFull.h>
@ -230,6 +231,19 @@ private:
size_t bytes_on_disk = parts_sizes.at(p_id - begin).load();
new_columns[res_index++]->insert(bytes_on_disk);
}
if (columns_mask[src_index++])
{
Poco::Timestamp modification_time{};
try
{
modification_time = p.disk->getLastModified(fs::path(current_info.data->getRelativeDataPath()) / MergeTreeData::DETACHED_DIR_NAME / p.dir_name);
}
catch (const fs::filesystem_error &)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
new_columns[res_index++]->insert(static_cast<UInt64>(modification_time.epochTime()));
}
if (columns_mask[src_index++])
new_columns[res_index++]->insert(p.disk->getName());
if (columns_mask[src_index++])
@ -260,12 +274,13 @@ StorageSystemDetachedParts::StorageSystemDetachedParts(const StorageID & table_i
{"partition_id", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())},
{"name", std::make_shared<DataTypeString>()},
{"bytes_on_disk", std::make_shared<DataTypeUInt64>()},
{"modification_time",std::make_shared<DataTypeDateTime>()},
{"disk", std::make_shared<DataTypeString>()},
{"path", std::make_shared<DataTypeString>()},
{"reason", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())},
{"min_block_number", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>())},
{"max_block_number", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>())},
{"level", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt32>())}
{"level", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt32>())},
}});
setInMemoryMetadata(storage_metadata);
}

View File

@ -431,7 +431,7 @@ def test_system_detached_parts(drop_detached_parts_table):
)
res = q(
"select system.detached_parts.* except (bytes_on_disk, `path`) from system.detached_parts where table like 'sdp_%' order by table, name"
"select system.detached_parts.* except (bytes_on_disk, `path`, modification_time) from system.detached_parts where table like 'sdp_%' order by table, name"
)
assert (
res == "default\tsdp_0\tall\tall_1_1_0\tdefault\t\t1\t1\t0\n"

View File

@ -18,7 +18,7 @@ ALTER TABLE not_partitioned DETACH PARTITION ID 'all';
SELECT 'Sum after DETACH PARTITION:';
SELECT sum(x) FROM not_partitioned;
SELECT 'system.detached_parts after DETACH PARTITION:';
SELECT system.detached_parts.* EXCEPT (bytes_on_disk, `path`, disk) FROM system.detached_parts WHERE database = currentDatabase() AND table = 'not_partitioned';
SELECT system.detached_parts.* EXCEPT (bytes_on_disk, `path`, disk, modification_time) FROM system.detached_parts WHERE database = currentDatabase() AND table = 'not_partitioned';
DROP TABLE not_partitioned;

View File

@ -145,6 +145,7 @@ CREATE TABLE system.detached_parts
`partition_id` Nullable(String),
`name` String,
`bytes_on_disk` UInt64,
`modification_time` DateTime,
`disk` String,
`path` String,
`reason` Nullable(String),

View File

@ -0,0 +1,2 @@
after detach 1
after detach 1

View File

@ -0,0 +1,16 @@
set mutations_sync=1;
{% for id, settings in [
("wide", "min_bytes_for_wide_part=0, min_rows_for_wide_part=0"),
("compact", "min_bytes_for_wide_part=1000, min_rows_for_wide_part=100"),
]
%}
drop table if exists data_{{ id }};
create table data_{{ id }} (key Int) engine=MergeTree() order by tuple() settings {{ settings }};
insert into data_{{ id }} values (1);
select 'before detach', now()-modification_time < 10 from system.detached_parts where database = currentDatabase() and table = 'data_{{ id }}';
alter table data_{{ id }} detach partition all;
select 'after detach', now()-modification_time < 10 from system.detached_parts where database = currentDatabase() and table = 'data_{{ id }}';
{% endfor %}