|
| 1 | +<?php |
| 2 | + |
| 3 | +include_once __DIR__ . '/../include.php'; |
| 4 | +include_once __DIR__ . '/lib_example.php'; |
| 5 | +// load production config |
| 6 | +$config = include_once __DIR__ . '/../../_clickhouse_config_product.php'; |
| 7 | + |
| 8 | + |
| 9 | +$cl = new ClickHouseDB\Cluster($config); |
| 10 | + |
| 11 | +$cl->setScanTimeOut(2.5); // 2500 ms |
| 12 | +if (!$cl->isReplicasIsOk()) |
| 13 | +{ |
| 14 | + throw new Exception('Replica state is bad , error='.$cl->getError()); |
| 15 | +} |
| 16 | +// |
| 17 | +$cluster_name='sharovara'; |
| 18 | +// |
| 19 | +echo "> $cluster_name , count shard = ".$cl->getClusterCountShard($cluster_name)." ; count replica = ".$cl->getClusterCountReplica($cluster_name)."\n"; |
| 20 | + |
| 21 | + |
| 22 | +// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 23 | +$mclq=new ClickHouseDB\Cluster\Migration($cluster_name); |
| 24 | +$mclq->setAutoSplitQuerty(';;'); |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +$mclq->addSqlUpdate(" |
| 30 | +
|
| 31 | +DROP DATABASE IF EXISTS shara |
| 32 | +
|
| 33 | +;; |
| 34 | +
|
| 35 | +CREATE DATABASE IF NOT EXISTS shara |
| 36 | +
|
| 37 | +;; |
| 38 | +
|
| 39 | +DROP TABLE IF EXISTS shara.adpreview_body_views_sharded |
| 40 | +
|
| 41 | +;; |
| 42 | +
|
| 43 | +DROP TABLE IF EXISTS shara.adpreview_body_views |
| 44 | +;; |
| 45 | +
|
| 46 | +CREATE TABLE IF NOT EXISTS shara.adpreview_body_views_sharded ( |
| 47 | + event_date Date DEFAULT toDate(event_time), |
| 48 | + event_time DateTime DEFAULT now(), |
| 49 | + body_id Int32, |
| 50 | + site_id Int32, |
| 51 | + views Int32 |
| 52 | +) ENGINE = ReplicatedSummingMergeTree('/clickhouse/tables/{sharovara_replica}/shara/adpreview_body_views_sharded', '{replica}', event_date, (event_date, event_time, body_id, site_id), 8192) |
| 53 | +;; |
| 54 | +CREATE TABLE IF NOT EXISTS |
| 55 | +shara.adpreview_body_views AS shara.adpreview_body_views_sharded |
| 56 | +ENGINE = Distributed(sharovara, shara, adpreview_body_views_sharded , rand()) |
| 57 | +"); |
| 58 | + |
| 59 | +// откат |
| 60 | +$mclq->addSqlDowngrade(' |
| 61 | +
|
| 62 | +DROP TABLE IF EXISTS shara.adpreview_body_views |
| 63 | +
|
| 64 | +;; |
| 65 | +
|
| 66 | +DROP TABLE IF EXISTS shara.adpreview_body_views_sharded |
| 67 | +;; |
| 68 | +DROP DATABASE IF EXISTS shara |
| 69 | +
|
| 70 | +'); |
| 71 | + |
| 72 | +echo "Start:sendMigration\n"; |
| 73 | +if (!$cl->sendMigration($mclq,true)) |
| 74 | +{ |
| 75 | + throw new Exception('sendMigration is bad , error='.$cl->getError()); |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +echo "\n----\nEND\n"; |
| 80 | +// ---------------------------------------------------------------------- |
| 81 | + |
0 commit comments