Distributed: Implement totalBytes() (system.tables.total_bytes)

This commit is contained in:
Azat Khuzhin 2021-01-26 21:45:36 +03:00
parent 456cbaf747
commit ce09b7ff89
4 changed files with 30 additions and 0 deletions

View File

@ -768,6 +768,14 @@ std::vector<StorageDistributedDirectoryMonitor::Status> StorageDistributed::getD
return statuses;
}
std::optional<UInt64> 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();

View File

@ -77,6 +77,7 @@ public:
unsigned /*num_streams*/) override;
bool supportsParallelInsert() const override { return true; }
std::optional<UInt64> totalBytes(const Settings &) const override;
BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override;

View File

@ -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

View File

@ -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;