@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @var int |
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(); |
@@ -360,22 +360,22 @@ discard block |
||
360 | 360 | /** |
361 | 361 | * @return Client |
362 | 362 | */ |
363 | - public function clientLike($cluster,$ip_addr_like) |
|
363 | + public function clientLike($cluster, $ip_addr_like) |
|
364 | 364 | { |
365 | - $nodes_check=$this->nodes; |
|
366 | - $nodes=$this->getClusterNodes($cluster); |
|
367 | - $list_ips_need=explode(';',$ip_addr_like); |
|
368 | - $find=false; |
|
369 | - foreach($list_ips_need as $like) |
|
365 | + $nodes_check = $this->nodes; |
|
366 | + $nodes = $this->getClusterNodes($cluster); |
|
367 | + $list_ips_need = explode(';', $ip_addr_like); |
|
368 | + $find = false; |
|
369 | + foreach ($list_ips_need as $like) |
|
370 | 370 | { |
371 | 371 | foreach ($nodes as $node) |
372 | 372 | { |
373 | 373 | |
374 | - if (stripos($node,$like)!==false) |
|
374 | + if (stripos($node, $like) !== false) |
|
375 | 375 | { |
376 | - if (in_array($node,$nodes_check)) |
|
376 | + if (in_array($node, $nodes_check)) |
|
377 | 377 | { |
378 | - $find=$node; |
|
378 | + $find = $node; |
|
379 | 379 | } |
380 | 380 | else |
381 | 381 | { |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | } |
388 | 388 | if ($find) break; |
389 | 389 | } |
390 | - if (!$find){ |
|
391 | - $find=$nodes[0]; |
|
390 | + if (!$find) { |
|
391 | + $find = $nodes[0]; |
|
392 | 392 | } |
393 | 393 | return $this->client($find); |
394 | 394 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return array |
464 | 464 | */ |
465 | - public function getTables($resultDetail=false) |
|
465 | + public function getTables($resultDetail = false) |
|
466 | 466 | { |
467 | 467 | $this->connect(); |
468 | - $list=[]; |
|
468 | + $list = []; |
|
469 | 469 | foreach ($this->tables as $db_name=>$tables) |
470 | 470 | { |
471 | 471 | foreach ($tables as $table_name=>$nodes) |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | |
474 | 474 | if ($resultDetail) |
475 | 475 | { |
476 | - $list[$db_name.'.'.$table_name]=$nodes; |
|
476 | + $list[$db_name . '.' . $table_name] = $nodes; |
|
477 | 477 | } |
478 | 478 | else |
479 | 479 | { |
480 | - $list[$db_name.'.'.$table_name]=array_keys($nodes); |
|
480 | + $list[$db_name . '.' . $table_name] = array_keys($nodes); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | } |
@@ -493,24 +493,24 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function getSizeTable($database_table) |
495 | 495 | { |
496 | - $list=[]; |
|
497 | - $nodes=$this->getNodesByTable($database_table); |
|
496 | + $list = []; |
|
497 | + $nodes = $this->getNodesByTable($database_table); |
|
498 | 498 | // scan need node`s |
499 | 499 | foreach ($nodes as $node) |
500 | 500 | { |
501 | 501 | if (empty($this->_table_size_cache[$node])) |
502 | 502 | { |
503 | - $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true); |
|
503 | + $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - $sizes=[]; |
|
507 | + $sizes = []; |
|
508 | 508 | foreach ($this->_table_size_cache as $node=>$rows) |
509 | 509 | { |
510 | 510 | foreach ($rows as $row) |
511 | 511 | { |
512 | - $sizes[$row['database'].'.'.$row['table']][$node]=$row; |
|
513 | - @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes']; |
|
512 | + $sizes[$row['database'] . '.' . $row['table']][$node] = $row; |
|
513 | + @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes']; |
|
514 | 514 | |
515 | 515 | |
516 | 516 | |
@@ -531,17 +531,17 @@ discard block |
||
531 | 531 | * @param $database_table |
532 | 532 | * @return array |
533 | 533 | */ |
534 | - public function truncateTable($database_table,$timeOut=2000) |
|
534 | + public function truncateTable($database_table, $timeOut = 2000) |
|
535 | 535 | { |
536 | - $out=[]; |
|
537 | - list($db,$table)=explode('.',$database_table); |
|
538 | - $nodes=$this->getMasterNodeForTable($database_table); |
|
536 | + $out = []; |
|
537 | + list($db, $table) = explode('.', $database_table); |
|
538 | + $nodes = $this->getMasterNodeForTable($database_table); |
|
539 | 539 | // scan need node`s |
540 | 540 | foreach ($nodes as $node) |
541 | 541 | { |
542 | - $def=$this->client($node)->getTimeout(); |
|
542 | + $def = $this->client($node)->getTimeout(); |
|
543 | 543 | $this->client($node)->database($db)->setTimeout($timeOut); |
544 | - $out[$node]=$this->client($node)->truncateTable($table); |
|
544 | + $out[$node] = $this->client($node)->truncateTable($table); |
|
545 | 545 | $this->client($node)->setTimeout($def); |
546 | 546 | } |
547 | 547 | return $out; |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | */ |
556 | 556 | public function getMasterNodeForTable($database_table) |
557 | 557 | { |
558 | - $list=$this->getTables(true); |
|
558 | + $list = $this->getTables(true); |
|
559 | 559 | |
560 | 560 | if (empty($list[$database_table])) return []; |
561 | 561 | |
562 | 562 | |
563 | - $result=[]; |
|
563 | + $result = []; |
|
564 | 564 | foreach ($list[$database_table] as $node=>$row) |
565 | 565 | { |
566 | - if ($row['is_leader']) $result[]=$node; |
|
566 | + if ($row['is_leader']) $result[] = $node; |
|
567 | 567 | } |
568 | 568 | return $result; |
569 | 569 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | public function getNodesByTable($database_table) |
577 | 577 | { |
578 | - $list=$this->getTables(); |
|
578 | + $list = $this->getTables(); |
|
579 | 579 | if (empty($list[$database_table])) { |
580 | 580 | throw new QueryException('Not find :' . $database_table); |
581 | 581 | } |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | */ |
17 | 17 | private $settings = []; |
18 | 18 | |
19 | - private $_ReadOnlyUser=false; |
|
19 | + private $_ReadOnlyUser = false; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var bool |
23 | 23 | */ |
24 | - private $_isHttps=false; |
|
24 | + private $_isHttps = false; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Settings constructor. |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | - public function https($flag=true) |
|
119 | + public function https($flag = true) |
|
120 | 120 | { |
121 | 121 | $this->set('https', $flag); |
122 | 122 | return $this; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function setReadOnlyUser($flag) |
203 | 203 | { |
204 | - $this->_ReadOnlyUser=$flag; |
|
204 | + $this->_ReadOnlyUser = $flag; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -57,14 +57,14 @@ |
||
57 | 57 | [time(), 'CLICKS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
58 | 58 | [time(), 'CLICKS', 1, 1237, '192.168.1.13', 'Moscow', 'user_13', ''], |
59 | 59 | [time(), 'CLICKS', 1, 1237, '192.168.1.14', 'Moscow', 'user_14', ''], |
60 | - [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
61 | - [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
62 | - |
|
63 | - [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
64 | - [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
65 | - [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
66 | - [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
67 | - [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
60 | + [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
61 | + [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
62 | + |
|
63 | + [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
64 | + [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
65 | + [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
66 | + [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
67 | + [time(), 'VIEWS', 1, 1237, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
68 | 68 | ], |
69 | 69 | ['event_time', 'event_type', 'site_id', 'article_id', 'ip', 'city', 'user_uuid', 'referer'] |
70 | 70 | ); |
@@ -56,14 +56,14 @@ |
||
56 | 56 | [time(), 'CLICKS', 1, 1237, '192.168.1.13', 'Moscow', 'user_13', ''], |
57 | 57 | [time(), 'CLICKS', 1, 1237, '192.168.1.14', 'Moscow', 'user_14', ''], |
58 | 58 | |
59 | - [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
60 | - [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
61 | - |
|
62 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
63 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
64 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
65 | - [time(), 'VIEWS', 1, 28, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
66 | - [time(), 'VIEWS', 1, 26, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
59 | + [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
60 | + [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
61 | + |
|
62 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
63 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
64 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
65 | + [time(), 'VIEWS', 1, 28, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
66 | + [time(), 'VIEWS', 1, 26, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
67 | 67 | ], |
68 | 68 | ['event_time', 'event_type', 'site_id', 'article_id', 'ip', 'city', 'user_uuid', 'referer'] |
69 | 69 | ); |