@@ -503,7 +503,7 @@ |
||
| 503 | 503 | */ |
| 504 | 504 | public function getSizeTable($database_table) |
| 505 | 505 | { |
| 506 | - $nodes=$this->getNodesByTable($database_table); |
|
| 506 | + $nodes=$this->getNodesByTable($database_table); |
|
| 507 | 507 | // scan need node`s |
| 508 | 508 | foreach ($nodes as $node) |
| 509 | 509 | { |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * @var int|float |
| 44 | 44 | */ |
| 45 | - private $scanTimeOut=10; |
|
| 45 | + private $scanTimeOut = 10; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @var array |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @var array |
| 79 | 79 | */ |
| 80 | - private $_table_size_cache=[]; |
|
| 80 | + private $_table_size_cache = []; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Cluster constructor. |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | // @todo : rewrite total_replicas=1 если кластер без реплики , нужно проверять какой класте и сколько в нем реплик |
| 193 | 193 | // if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);} |
| 194 | - if ($this->softCheck ) |
|
| 194 | + if ($this->softCheck) |
|
| 195 | 195 | { |
| 196 | 196 | if (!$ok) break; |
| 197 | 197 | continue; |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $statementsClusters[$node]->getRequest()->setDnsCache(0)->timeOut($this->scanTimeOut)->connectTimeOut($this->scanTimeOut); |
| 263 | 263 | } |
| 264 | 264 | $this->defaultClient()->executeAsync(); |
| 265 | - $tables=[]; |
|
| 265 | + $tables = []; |
|
| 266 | 266 | |
| 267 | 267 | foreach ($this->nodes as $node) { |
| 268 | 268 | |
@@ -270,16 +270,16 @@ discard block |
||
| 270 | 270 | try { |
| 271 | 271 | $r = $statementsReplicas[$node]->rows(); |
| 272 | 272 | foreach ($r as $row) { |
| 273 | - $tables[$row['database']][$row['table']][$node] =$row; |
|
| 273 | + $tables[$row['database']][$row['table']][$node] = $row; |
|
| 274 | 274 | } |
| 275 | 275 | $result['replicas'][$node] = $r; |
| 276 | - } catch (\Exception $E) { |
|
| 276 | + }catch (\Exception $E) { |
|
| 277 | 277 | $result['replicas'][$node] = false; |
| 278 | 278 | $badNodes[$node] = $E->getMessage(); |
| 279 | 279 | $this->error[] = 'statementsReplicas:' . $E->getMessage(); |
| 280 | 280 | } |
| 281 | 281 | // --------------------------------------------------------------------------------------------------- |
| 282 | - $hosts=[]; |
|
| 282 | + $hosts = []; |
|
| 283 | 283 | |
| 284 | 284 | try { |
| 285 | 285 | $c = $statementsClusters[$node]->rows(); |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | ]; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - } catch (\Exception $E) { |
|
| 298 | + }catch (\Exception $E) { |
|
| 299 | 299 | $result['clusters'][$node] = false; |
| 300 | 300 | |
| 301 | 301 | $this->error[] = 'clusters:' . $E->getMessage(); |
@@ -363,22 +363,22 @@ discard block |
||
| 363 | 363 | * @return Client |
| 364 | 364 | * @throws Exception\TransportException |
| 365 | 365 | */ |
| 366 | - public function clientLike($cluster,$ip_addr_like) |
|
| 366 | + public function clientLike($cluster, $ip_addr_like) |
|
| 367 | 367 | { |
| 368 | - $nodes_check=$this->nodes; |
|
| 369 | - $nodes=$this->getClusterNodes($cluster); |
|
| 370 | - $list_ips_need=explode(';',$ip_addr_like); |
|
| 371 | - $find=false; |
|
| 372 | - foreach($list_ips_need as $like) |
|
| 368 | + $nodes_check = $this->nodes; |
|
| 369 | + $nodes = $this->getClusterNodes($cluster); |
|
| 370 | + $list_ips_need = explode(';', $ip_addr_like); |
|
| 371 | + $find = false; |
|
| 372 | + foreach ($list_ips_need as $like) |
|
| 373 | 373 | { |
| 374 | 374 | foreach ($nodes as $node) |
| 375 | 375 | { |
| 376 | 376 | |
| 377 | - if (stripos($node,$like)!==false) |
|
| 377 | + if (stripos($node, $like) !== false) |
|
| 378 | 378 | { |
| 379 | - if (in_array($node,$nodes_check)) |
|
| 379 | + if (in_array($node, $nodes_check)) |
|
| 380 | 380 | { |
| 381 | - $find=$node; |
|
| 381 | + $find = $node; |
|
| 382 | 382 | } |
| 383 | 383 | else |
| 384 | 384 | { |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | if ($find) break; |
| 392 | 392 | } |
| 393 | - if (!$find){ |
|
| 394 | - $find=$nodes[0]; |
|
| 393 | + if (!$find) { |
|
| 394 | + $find = $nodes[0]; |
|
| 395 | 395 | } |
| 396 | 396 | return $this->client($find); |
| 397 | 397 | } |
@@ -471,10 +471,10 @@ discard block |
||
| 471 | 471 | * @return array |
| 472 | 472 | * @throws Exception\TransportException |
| 473 | 473 | */ |
| 474 | - public function getTables($resultDetail=false) |
|
| 474 | + public function getTables($resultDetail = false) |
|
| 475 | 475 | { |
| 476 | 476 | $this->connect(); |
| 477 | - $list=[]; |
|
| 477 | + $list = []; |
|
| 478 | 478 | foreach ($this->tables as $db_name=>$tables) |
| 479 | 479 | { |
| 480 | 480 | foreach ($tables as $table_name=>$nodes) |
@@ -482,11 +482,11 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | if ($resultDetail) |
| 484 | 484 | { |
| 485 | - $list[$db_name.'.'.$table_name]=$nodes; |
|
| 485 | + $list[$db_name . '.' . $table_name] = $nodes; |
|
| 486 | 486 | } |
| 487 | 487 | else |
| 488 | 488 | { |
| 489 | - $list[$db_name.'.'.$table_name]=array_keys($nodes); |
|
| 489 | + $list[$db_name . '.' . $table_name] = array_keys($nodes); |
|
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | } |
@@ -503,23 +503,23 @@ discard block |
||
| 503 | 503 | */ |
| 504 | 504 | public function getSizeTable($database_table) |
| 505 | 505 | { |
| 506 | - $nodes=$this->getNodesByTable($database_table); |
|
| 506 | + $nodes = $this->getNodesByTable($database_table); |
|
| 507 | 507 | // scan need node`s |
| 508 | 508 | foreach ($nodes as $node) |
| 509 | 509 | { |
| 510 | 510 | if (empty($this->_table_size_cache[$node])) |
| 511 | 511 | { |
| 512 | - $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true); |
|
| 512 | + $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true); |
|
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - $sizes=[]; |
|
| 516 | + $sizes = []; |
|
| 517 | 517 | foreach ($this->_table_size_cache as $node=>$rows) |
| 518 | 518 | { |
| 519 | 519 | foreach ($rows as $row) |
| 520 | 520 | { |
| 521 | - $sizes[$row['database'].'.'.$row['table']][$node]=$row; |
|
| 522 | - @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes']; |
|
| 521 | + $sizes[$row['database'] . '.' . $row['table']][$node] = $row; |
|
| 522 | + @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes']; |
|
| 523 | 523 | |
| 524 | 524 | |
| 525 | 525 | |
@@ -541,17 +541,17 @@ discard block |
||
| 541 | 541 | * @return array |
| 542 | 542 | * @throws Exception\TransportException |
| 543 | 543 | */ |
| 544 | - public function truncateTable($database_table,$timeOut=2000) |
|
| 544 | + public function truncateTable($database_table, $timeOut = 2000) |
|
| 545 | 545 | { |
| 546 | - $out=[]; |
|
| 547 | - list($db,$table)=explode('.',$database_table); |
|
| 548 | - $nodes=$this->getMasterNodeForTable($database_table); |
|
| 546 | + $out = []; |
|
| 547 | + list($db, $table) = explode('.', $database_table); |
|
| 548 | + $nodes = $this->getMasterNodeForTable($database_table); |
|
| 549 | 549 | // scan need node`s |
| 550 | 550 | foreach ($nodes as $node) |
| 551 | 551 | { |
| 552 | - $def=$this->client($node)->getTimeout(); |
|
| 552 | + $def = $this->client($node)->getTimeout(); |
|
| 553 | 553 | $this->client($node)->database($db)->setTimeout($timeOut); |
| 554 | - $out[$node]=$this->client($node)->truncateTable($table); |
|
| 554 | + $out[$node] = $this->client($node)->truncateTable($table); |
|
| 555 | 555 | $this->client($node)->setTimeout($def); |
| 556 | 556 | } |
| 557 | 557 | return $out; |
@@ -566,15 +566,15 @@ discard block |
||
| 566 | 566 | */ |
| 567 | 567 | public function getMasterNodeForTable($database_table) |
| 568 | 568 | { |
| 569 | - $list=$this->getTables(true); |
|
| 569 | + $list = $this->getTables(true); |
|
| 570 | 570 | |
| 571 | 571 | if (empty($list[$database_table])) return []; |
| 572 | 572 | |
| 573 | 573 | |
| 574 | - $result=[]; |
|
| 574 | + $result = []; |
|
| 575 | 575 | foreach ($list[$database_table] as $node=>$row) |
| 576 | 576 | { |
| 577 | - if ($row['is_leader']) $result[]=$node; |
|
| 577 | + if ($row['is_leader']) $result[] = $node; |
|
| 578 | 578 | } |
| 579 | 579 | return $result; |
| 580 | 580 | } |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function getNodesByTable($database_table) |
| 589 | 589 | { |
| 590 | - $list=$this->getTables(); |
|
| 590 | + $list = $this->getTables(); |
|
| 591 | 591 | if (empty($list[$database_table])) { |
| 592 | 592 | throw new QueryException('Not find :' . $database_table); |
| 593 | 593 | } |