diff --git a/src/Storages/StorageDistributed.cpp b/src/Storages/StorageDistributed.cpp index 22d51929bd0..804cd99ae19 100644 --- a/src/Storages/StorageDistributed.cpp +++ b/src/Storages/StorageDistributed.cpp @@ -768,6 +768,14 @@ std::vector StorageDistributed::getD return statuses; } +std::optional StorageDistributed::totalBytes(const Settings &) const +{ + UInt64 total_bytes = 0; + for (const auto & status : getDirectoryMonitorsStatuses()) + total_bytes += status.bytes_count; + return total_bytes; +} + size_t StorageDistributed::getShardCount() const { return getCluster()->getShardCount(); diff --git a/src/Storages/StorageDistributed.h b/src/Storages/StorageDistributed.h index bd5bd4f8186..0a1ec5f4503 100644 --- a/src/Storages/StorageDistributed.h +++ b/src/Storages/StorageDistributed.h @@ -77,6 +77,7 @@ public: unsigned /*num_streams*/) override; bool supportsParallelInsert() const override { return true; } + std::optional totalBytes(const Settings &) const override; BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override; diff --git a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference index 12af231d18c..ea105b0679c 100644 --- a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference +++ b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference @@ -45,3 +45,7 @@ Check total_bytes/total_rows for Set Check total_bytes/total_rows for Join 10240 50 10240 100 +Check total_bytes/total_rows for Distributed +0 \N +629 \N +0 \N diff --git a/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql b/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql index 862e3693f0e..7a774cc7cab 100644 --- a/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql +++ b/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql @@ -126,3 +126,20 @@ SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tab INSERT INTO check_system_tables SELECT number+50 FROM numbers(50); SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; DROP TABLE check_system_tables; + +SELECT 'Check total_bytes/total_rows for Distributed'; +-- metrics updated only after distributed_directory_monitor_sleep_time_ms +SET distributed_directory_monitor_sleep_time_ms=10; +CREATE TABLE check_system_tables_null (key Int) Engine=Null(); +CREATE TABLE check_system_tables AS check_system_tables_null Engine=Distributed(test_shard_localhost, currentDatabase(), check_system_tables_null); +SYSTEM STOP DISTRIBUTED SENDS check_system_tables; +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +INSERT INTO check_system_tables SELECT * FROM numbers(1) SETTINGS prefer_localhost_replica=0; +-- 1 second should guarantee metrics update +-- XXX: but this is kind of quirk, way more better will be account this metrics without any delays. +SELECT sleep(1) FORMAT Null; +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +SYSTEM FLUSH DISTRIBUTED check_system_tables; +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +DROP TABLE check_system_tables_null; +DROP TABLE check_system_tables;