Skip to content

Commit

Permalink
add column zookeeper_name in system.replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
cangyin committed Apr 25, 2023
1 parent 5ca15fc commit 623c8db
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Storages/MergeTree/ReplicatedTableStatus.h
Expand Up @@ -16,6 +16,7 @@ struct ReplicatedTableStatus

ReplicatedMergeTreeQueue::Status queue;
UInt32 parts_to_check;
String zookeeper_name;
String zookeeper_path;
String replica_name;
String replica_path;
Expand Down
1 change: 1 addition & 0 deletions src/Storages/StorageReplicatedMergeTree.cpp
Expand Up @@ -5966,6 +5966,7 @@ void StorageReplicatedMergeTree::getStatus(ReplicatedTableStatus & res, bool wit
/// NOTE: consider convert to UInt64
res.parts_to_check = static_cast<UInt32>(part_check_thread.size());

res.zookeeper_name = zookeeper_name;
res.zookeeper_path = zookeeper_path;
res.replica_name = replica_name;
res.replica_path = replica_path;
Expand Down
2 changes: 2 additions & 0 deletions src/Storages/System/StorageSystemReplicas.cpp
Expand Up @@ -39,6 +39,7 @@ StorageSystemReplicas::StorageSystemReplicas(const StorageID & table_id_)
{ "is_session_expired", std::make_shared<DataTypeUInt8>() },
{ "future_parts", std::make_shared<DataTypeUInt32>() },
{ "parts_to_check", std::make_shared<DataTypeUInt32>() },
{ "zookeeper_name", std::make_shared<DataTypeString>() },
{ "zookeeper_path", std::make_shared<DataTypeString>() },
{ "replica_name", std::make_shared<DataTypeString>() },
{ "replica_path", std::make_shared<DataTypeString>() },
Expand Down Expand Up @@ -194,6 +195,7 @@ Pipe StorageSystemReplicas::read(
res_columns[col_num++]->insert(status.is_session_expired);
res_columns[col_num++]->insert(status.queue.future_parts);
res_columns[col_num++]->insert(status.parts_to_check);
res_columns[col_num++]->insert(status.zookeeper_name);
res_columns[col_num++]->insert(status.zookeeper_path);
res_columns[col_num++]->insert(status.replica_name);
res_columns[col_num++]->insert(status.replica_path);
Expand Down
Expand Up @@ -850,6 +850,7 @@ CREATE TABLE system.replicas
`is_session_expired` UInt8,
`future_parts` UInt32,
`parts_to_check` UInt32,
`zookeeper_name` String,
`zookeeper_path` String,
`replica_name` String,
`replica_path` String,
Expand Down
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02723_zookeeper_name.reference
@@ -0,0 +1,4 @@
Create Tables
Insert Data
"t1","default",1
"t2","default",1
23 changes: 23 additions & 0 deletions tests/queries/0_stateless/02723_zookeeper_name.sql
@@ -0,0 +1,23 @@
-- Tags: zookeeper, replica

SELECT 'Create Tables';
CREATE TABLE t1(k UInt32, v UInt32) ENGINE ReplicatedMergeTree('/clickhouse/tables/{database}/test_02723/zookeeper_name/t1', '1') ORDER BY k;

CREATE TABLE t2(k UInt32, v UInt32) ENGINE ReplicatedMergeTree('/clickhouse/tables/{database}/test_02723/zookeeper_name/t2', '1') ORDER BY k;

SELECT 'Insert Data';

INSERT INTO t1 SELECT * FROM generateRandom('k UInt32, v UInt32') LIMIT 1;
INSERT INTO t2 SELECT * FROM generateRandom('k UInt32, v UInt32') LIMIT 1;

SELECT
table,zookeeper_name,count()
FROM system.replicas
INNER JOIN system.parts USING (database, table)
WHERE database = currentDatabase()
GROUP BY
table,zookeeper_name
FORMAT CSV;

DROP TABLE t1;
DROP TABLE t2;

0 comments on commit 623c8db

Please sign in to comment.