Skip to content

Commit

Permalink
Cluster drop old Partitions - example
Browse files Browse the repository at this point in the history
  • Loading branch information
isublimity committed Aug 25, 2017
1 parent 5cbd12c commit bc69cfa
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,72 @@ file_put_contents($fileName,\ClickHouseDB\FormatLine::TSV($row)."\n",FILE_APPEND

```

### Cluster drop old Partitions

Example code :

```php
class my
{
/**
* @return \ClickHouseDB\Cluster
*/
public function getClickHouseCluster()
{
return $this->_cluster;
}
public function msg($text)
{
echo $text."\n";
}
private function cleanTable($dbt)
{

$sizes=$this->getClickHouseCluster()->getSizeTable($dbt);
$this->msg("Clean table : $dbt,size = ".$this->humanFileSize($sizes));

// split string "DB.TABLE"
list($db,$table)=explode('.',$dbt);

// Get Master node for table
$nodes=$this->getClickHouseCluster()->getMasterNodeForTable($dbt);
foreach ($nodes as $node)
{
$client=$this->getClickHouseCluster()->client($node);

$size=$client->database($db)->tableSize($table);

$this->msg("$node \t {$size['size']} \t {$size['min_date']} \t {$size['max_date']}");

$client->dropOldPartitions($table,30,30);
}


}
public function clean()
{
$this->msg("clean");

$this->getClickHouseCluster()->setScanTimeOut(2.5); // 2500 ms
$this->getClickHouseCluster()->setSoftCheck(true);
if (!$this->getClickHouseCluster()->isReplicasIsOk())
{
throw new Exception('Replica state is bad , error='.$this->getClickHouseCluster()->getError());
}


$this->cleanTable('model.history_full_model_sharded');


$this->cleanTable('model.history_model_result_sharded');


}
}

```


### Debug & Verbose

```php
Expand Down

0 comments on commit bc69cfa

Please sign in to comment.