@@ -476,6 +476,72 @@ file_put_contents($fileName,\ClickHouseDB\FormatLine::TSV($row)."\n",FILE_APPEND
476
476
477
477
```
478
478
479
+ ### Cluster drop old Partitions
480
+
481
+ Example code :
482
+
483
+ ``` php
484
+ class my
485
+ {
486
+ /**
487
+ * @return \ClickHouseDB\Cluster
488
+ */
489
+ public function getClickHouseCluster()
490
+ {
491
+ return $this->_cluster;
492
+ }
493
+ public function msg($text)
494
+ {
495
+ echo $text."\n";
496
+ }
497
+ private function cleanTable($dbt)
498
+ {
499
+
500
+ $sizes=$this->getClickHouseCluster()->getSizeTable($dbt);
501
+ $this->msg("Clean table : $dbt,size = ".$this->humanFileSize($sizes));
502
+
503
+ // split string "DB.TABLE"
504
+ list($db,$table)=explode('.',$dbt);
505
+
506
+ // Get Master node for table
507
+ $nodes=$this->getClickHouseCluster()->getMasterNodeForTable($dbt);
508
+ foreach ($nodes as $node)
509
+ {
510
+ $client=$this->getClickHouseCluster()->client($node);
511
+
512
+ $size=$client->database($db)->tableSize($table);
513
+
514
+ $this->msg("$node \t {$size['size']} \t {$size['min_date']} \t {$size['max_date']}");
515
+
516
+ $client->dropOldPartitions($table,30,30);
517
+ }
518
+
519
+
520
+ }
521
+ public function clean()
522
+ {
523
+ $this->msg("clean");
524
+
525
+ $this->getClickHouseCluster()->setScanTimeOut(2.5); // 2500 ms
526
+ $this->getClickHouseCluster()->setSoftCheck(true);
527
+ if (!$this->getClickHouseCluster()->isReplicasIsOk())
528
+ {
529
+ throw new Exception('Replica state is bad , error='.$this->getClickHouseCluster()->getError());
530
+ }
531
+
532
+
533
+ $this->cleanTable('model.history_full_model_sharded');
534
+
535
+
536
+ $this->cleanTable('model.history_model_result_sharded');
537
+
538
+
539
+ }
540
+ }
541
+
542
+ ```
543
+
544
+
479
545
### Debug & Verbose
480
546
481
547
``` php
0 commit comments