Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding experimental replicated function to clickhouse #40 #41

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ POSTGRES_MIGRATIONS_PATH=./fixtures/postgres

CLICKHOUSE_DSN=clickhouse://default:@clickhouse:9000/default?compress=true&debug=false
CLICKHOUSE_MIGRATIONS_PATH=./fixtures/clickhouse
CLICKHOUSE_CLUSTER_DSN1=clickhouse://default:@clickhouse1:9000,clickhouse2:9000/default?compress=true&debug=false
CLICKHOUSE_CLUSTER_DSN2=clickhouse://default:@clickhouse2:9000/default?compress=true&debug=false
CLICKHOUSE_CLUSTER_DSN=clickhouse://default:@clickhouse1:9000,clickhouse2:9000/default?compress=true&debug=false
CLICKHOUSE_CLUSTER_R_DSN=clickhouse://default:@clickhouse-r-1:9000,clickhouse-r-2:9000/default?compress=true&debug=false&allow_experimental_database_replicated=1
CLICKHOUSE_CLUSTER_NAME=test_cluster
CLICKHOUSE_CLUSTER_MIGRATIONS_PATH=./fixtures/clickhouse_cluster
CLICKHOUSE_CLUSTER_R_MIGRATIONS_PATH=./fixtures/clickhouse_cluster_replicated

MYSQL_DSN=mysql://docker:docker@tcp(mysql:3306)/docker
MYSQL_ROOT_PASSWORD=docker-pw
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ gen-mocks-dry-run: install-mockery ## Run mockery --dry-run=true

start:
@docker-compose -f "docker-compose.yml" -f "docker-compose.dev.yml" up -d

stop:
@docker-compose -f "docker-compose.yml" down --remove-orphans
8 changes: 8 additions & 0 deletions cmd/db-migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ func flags(options *migrator.Options) []cli.Flag {
Usage: "Cluster name for history of migrates",
Destination: &options.ClusterName,
},
&cli.BoolFlag{
Name: "migrationReplicated",
Sources: cli.EnvVars("MIGRATION_REPLICATED"),
Aliases: []string{"cr"},
Value: false,
Usage: "Using replicated experimental function to clickhouse for history table of migrates",
Destination: &options.Replicated,
},
&cli.BoolFlag{
Name: "compact",
Sources: cli.EnvVars("COMPACT"),
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ services:
ports:
- 9000:9000
- 8123:8123
clickhouse-r-1:
ports:
- 19000:9000
- 18123:8123
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ services:
- clickhouse
- clickhouse1
- clickhouse2
- clickhouse-r-1
- clickhouse-r-2
- postgres
- mysql
links:
- clickhouse
- clickhouse1
- clickhouse2
- clickhouse-r-1
- clickhouse-r-2
- postgres
- mysql
volumes:
Expand Down Expand Up @@ -62,3 +66,27 @@ services:
- "./docker/volume/clickhouse-cluster/config/clickhouse2:/etc/clickhouse-server/config.d/"
depends_on:
- clickhouse-keeper

clickhouse-keeper-r:
image: clickhouse/clickhouse-keeper:23.11-alpine
restart: on-failure
volumes:
- "./docker/volume/clickhouse-cluster-replicated/config/keeper1/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml"

clickhouse-r-1:
image: clickhouse/clickhouse-server:23.11-alpine
restart: on-failure
volumes:
- "./docker/volume/clickhouse-cluster-replicated/config/clickhouse1:/etc/clickhouse-server/config.d/"
- "./docker/volume/clickhouse-cluster-replicated/config/clickhouse1/users.xml:/etc/clickhouse-server/users.d/users.xml"
depends_on:
- clickhouse-keeper-r

clickhouse-r-2:
image: clickhouse/clickhouse-server:23.11-alpine
restart: on-failure
volumes:
- "./docker/volume/clickhouse-cluster-replicated/config/clickhouse2:/etc/clickhouse-server/config.d/"
- "./docker/volume/clickhouse-cluster-replicated/config/clickhouse2/users.xml:/etc/clickhouse-server/users.d/users.xml"
depends_on:
- clickhouse-keeper-r
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<clickhouse>
<logger>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
<http_port>8123</http_port>
<tcp_port>9000</tcp_port>

<distributed_ddl>
<path>/clickhouse/task_queue/ddl</path>
</distributed_ddl>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<clickhouse>
<distributed_ddl>
<path>/clickhouse/task_queue/ddl</path>
</distributed_ddl>
<macros>
<shard>01</shard>
<replica>clickhouse1</replica>
<cluster>test_cluster</cluster>
</macros>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<clickhouse>
<remote_servers>
<test_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>clickhouse1</host>
<port>9000</port>
</replica>
<replica>
<host>clickhouse2</host>
<port>9000</port>
</replica>
</shard>
</test_cluster>
</remote_servers>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<clickhouse>
<zookeeper>
<node>
<host>clickhouse-keeper-r</host>
<port>9181</port>
</node>
</zookeeper>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<clickhouse>
<profiles>
<default>
<allow_experimental_database_replicated>1</allow_experimental_database_replicated>
<distributed_ddl_output_mode>null_status_on_timeout</distributed_ddl_output_mode>
</default>
</profiles>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<clickhouse>
<logger>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
<http_port>8123</http_port>
<tcp_port>9000</tcp_port>

<distributed_ddl>
<path>/clickhouse/task_queue/ddl</path>
</distributed_ddl>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<clickhouse>
<distributed_ddl>
<path>/clickhouse/task_queue/ddl</path>
</distributed_ddl>
<macros>
<shard>01</shard>
<replica>clickhouse2</replica>
<cluster>test_cluster</cluster>
</macros>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<clickhouse>
<remote_servers>
<test_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>clickhouse1</host>
<port>9000</port>
</replica>
<replica>
<host>clickhouse2</host>
<port>9000</port>
</replica>
</shard>
</test_cluster>
</remote_servers>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<clickhouse>
<zookeeper>
<node>
<host>clickhouse-keeper-r</host>
<port>9181</port>
</node>
</zookeeper>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<clickhouse>
<profiles>
<default>
<allow_experimental_database_replicated>1</allow_experimental_database_replicated>
<distributed_ddl_output_mode>null_status_on_timeout</distributed_ddl_output_mode>
</default>
</profiles>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<clickhouse replace="true">
<logger>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
<keeper_server>
<tcp_port>9181</tcp_port>
<server_id>1</server_id>
<log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
<coordination_settings>
<operation_timeout_ms>10000</operation_timeout_ms>
<session_timeout_ms>30000</session_timeout_ms>
<raft_logs_level>information</raft_logs_level>
</coordination_settings>
<raft_configuration>
<server>
<id>1</id>
<hostname>clickhouse-keeper-r</hostname>
<port>9234</port>
</server>
</raft_configuration>
</keeper_server>
</clickhouse>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<clickhouse>
<logger>
<level>debug</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<clickhouse>
<logger>
<level>debug</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<clickhouse replace="true">
<logger>
<level>information</level>
<log>/var/log/clickhouse-keeper/clickhouse-keeper.log</log>
<errorlog>/var/log/clickhouse-keeper/clickhouse-keeper.err.log</errorlog>
<size>1000M</size>
<level>error</level>
<console>1</console>
<size>10M</size>
<count>3</count>
</logger>
<listen_host>0.0.0.0</listen_host>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DROP TABLE test ON CLUSTER test_cluster;
DROP TABLE raw.test ON CLUSTER test_cluster;
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CREATE TABLE test ON CLUSTER test_cluster (
CREATE DATABASE IF NOT EXISTS raw ON CLUSTER test_cluster;

CREATE TABLE raw.test ON CLUSTER test_cluster (
time DateTime DEFAULT now(),
value UInt32

)
ENGINE = ReplicatedMergeTree (
'/clickhouse/tables/{shard}/test_cluster_test',
'/clickhouse/tables/{shard}/raw_test_cluster_test',
'{replica}'
)
PARTITION BY toYYYYMM(time)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE test ON CLUSTER test_cluster
ALTER TABLE raw.test ON CLUSTER test_cluster
DROP COLUMN text;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALTER TABLE test ON CLUSTER test_cluster
ALTER TABLE raw.test ON CLUSTER test_cluster
ADD COLUMN text String;

INSERT INTO test (value, text) VALUES (1, 'Hello');
INSERT INTO raw.test (value, text) VALUES (1, 'Hello');
Original file line number Diff line number Diff line change
@@ -1 +1 @@
INSERT INTO test2 (time) VALUES (now());
INSERT INTO raw.test2 (time) VALUES (now());
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE raw.test NO DELAY;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE DATABASE IF NOT EXISTS raw
ENGINE = Replicated('/clickhouse/databases/{shard}/raw', '{shard}', '{replica}');

CREATE TABLE IF NOT EXISTS raw.test (
time DateTime DEFAULT now(),
value UInt32
)
ENGINE = ReplicatedMergeTree (
'/clickhouse/tables/{shard}/raw_test_cluster_test',
'{replica}'
)
PARTITION BY toYYYYMM(time)
ORDER BY (time, value);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE raw.test DROP COLUMN text;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE raw.test ADD COLUMN text String;

INSERT INTO raw.test (value, text) VALUES (1, 'Hello');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO raw.test2 (time) VALUES (now());
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestMigrateService_ClickHouseCluster_UpDown(t *testing.T) {

func createClickhouse1ClusterMigrator() (*Service, error) {
return New(&Options{
DSN: os.Getenv("CLICKHOUSE_CLUSTER_DSN1"),
DSN: os.Getenv("CLICKHOUSE_CLUSTER_DSN"),
Directory: os.Getenv("CLICKHOUSE_CLUSTER_MIGRATIONS_PATH"),
TableName: "migration",
ClusterName: os.Getenv("CLICKHOUSE_CLUSTER_NAME"),
Expand Down
Loading
Loading