1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
dbnode_check.php
См. документацию.
1<?php
3
5{
6 const OK = 1;
7 const WARNING = 0;
8 const ERROR = -1;
9
10 public function MainNodeCommon($arMasterNode)
11 {
12 if ($arMasterNode['ID'] == 1)
13 {
14 global $DB;
15 }
16 else
17 {
18 $DB = CDatabase::GetDBNodeConnection($arMasterNode['ID'], true);
19 }
20
21 $result = [];
22
23 $is_ok = CCluster::checkForServers(1);
24 $result['server_count'] = [
26 'MESSAGE' => GetMessage('CLUSTER_SERVER_COUNT_CHECK'),
27 'WIZ_REC' => '',
28 ];
29
30 $is_ok = !file_exists($_SERVER['DOCUMENT_ROOT'] . BX_PERSONAL_ROOT . '/php_interface/after_connect.php');
31 $result['after_connect'] = [
33 'MESSAGE' => GetMessage('CLU_AFTER_CONNECT_MSG'),
34 'WIZ_REC' => GetMessage('CLU_AFTER_CONNECT_WIZREC'),
35 ];
36
37 $is_ok = !file_exists($_SERVER['DOCUMENT_ROOT'] . BX_PERSONAL_ROOT . '/php_interface/after_connect_d7.php');
38 $result['after_connect_d7'] = [
40 'MESSAGE' => GetMessage('CLU_AFTER_CONNECT_D7_MSG'),
41 'WIZ_REC' => GetMessage('CLU_AFTER_CONNECT_WIZREC'),
42 ];
43
44 $arVariables = static::GetServerVariables($DB, [
45 'character_set_server' => '',
46 'character_set_database' => '',
47 'character_set_connection' => '',
48 'character_set_client' => '',
49 ], 'character_set%');
50 $is_ok = $arVariables['character_set_server'] !== ''
51 && $arVariables['character_set_server'] === $arVariables['character_set_database']
52 && $arVariables['character_set_database'] === $arVariables['character_set_connection']
53 && $arVariables['character_set_connection'] === $arVariables['character_set_client']
54 ;
55 $is_ok = $is_ok || (defined('BX_CLUSTER_SKIP_CHARSET_CHECK') && constant('BX_CLUSTER_SKIP_CHARSET_CHECK') === true);
56 $result['charset'] = [
58 'MESSAGE' => GetMessage('CLU_CHARSET_MSG'),
59 'WIZ_REC' => GetMessage('CLU_CHARSET_WIZREC', [
60 '#character_set_server#' => $arVariables['character_set_server'],
61 '#character_set_database#' => $arVariables['character_set_database'],
62 '#character_set_connection#' => $arVariables['character_set_connection'],
63 '#character_set_client#' => $arVariables['character_set_client'],
64 ]),
65 ];
66
67 $arVariables = static::GetServerVariables($DB, [
68 'collation_server' => '',
69 'collation_database' => '',
70 'collation_connection' => '',
71 ], 'collation%');
72 $is_ok = $arVariables['collation_server'] !== ''
73 && $arVariables['collation_server'] === $arVariables['collation_database']
74 && $arVariables['collation_database'] === $arVariables['collation_connection']
75 ;
76 $is_ok = $is_ok || (defined('BX_CLUSTER_SKIP_CHARSET_CHECK') && constant('BX_CLUSTER_SKIP_CHARSET_CHECK') === true);
77 $result['collation'] = [
79 'MESSAGE' => GetMessage('CLU_COLLATION_MSG'),
80 'WIZ_REC' => GetMessage('CLU_COLLATION_WIZREC', [
81 '#collation_server#' => $arVariables['collation_server'],
82 '#collation_database#' => $arVariables['collation_database'],
83 '#collation_connection#' => $arVariables['collation_connection'],
84 ]),
85 ];
86
87 return $result;
88 }
89
90 public function MainNodeForReplication($arMasterNode)
91 {
92 if ($arMasterNode['ID'] == 1)
93 {
94 global $DB;
95 }
96 else
97 {
98 $DB = CDatabase::GetDBNodeConnection($arMasterNode['ID'], true);
99 }
100
101 $result = [];
102
103 $server_id = $this->GetServerVariable($DB, 'server_id');
104 $is_ok = $server_id > 0;
105 $result['server_id'] = [
107 'MESSAGE' => GetMessage('CLU_SERVER_ID_MSG', ['#server-id#' => $server_id]),
108 'WIZ_REC' => GetMessage('CLU_SERVER_ID_WIZREC'),
109 ];
110
111 $log_bin = $this->GetServerVariable($DB, 'log_bin');
112 $is_ok = $log_bin === 'ON';
113 $result['log_bin'] = [
115 'MESSAGE' => GetMessage('CLU_LOG_BIN_MSG', ['#log-bin#' => $log_bin]),
116 'WIZ_REC' => GetMessage('CLU_LOG_BIN_WIZREC'),
117 ];
118
119 $skip_networking = $this->GetServerVariable($DB, 'skip_networking');
120 $is_ok = $skip_networking === 'OFF';
121 $result['skip_networking'] = [
123 'MESSAGE' => GetMessage('CLU_SKIP_NETWORKING_MSG', ['#skip-networking#' => $skip_networking]),
124 'WIZ_REC' => GetMessage('CLU_SKIP_NETWORKING_WIZREC'),
125 ];
126
127 $innodb_flush_log_at_trx_commit = $this->GetServerVariable($DB, 'innodb_flush_log_at_trx_commit');
128 $is_ok = $innodb_flush_log_at_trx_commit === '1';
129 $result['innodb_flush_log_at_trx_commit'] = [
131 'MESSAGE' => GetMessage('CLU_FLUSH_ON_COMMIT_MSG', ['#innodb_flush_log_at_trx_commit#' => $innodb_flush_log_at_trx_commit]),
132 'WIZ_REC' => '',
133 ];
134
135 $sync_binlog = $this->GetServerVariable($DB, 'sync_binlog');
136 $is_ok = $sync_binlog === '1';
137 $result['sync_binlog'] = [
139 'MESSAGE' => GetMessage('CLU_SYNC_BINLOG_MSG', ['#sync_binlog#' => $sync_binlog]),
140 'WIZ_REC' => '',
141 ];
142
143 $master_version = $this->GetServerVariable($DB, 'version');
144 $isSuperRequred = version_compare($master_version, '8.0') < 0;
145
146 $privileges = [];
147 $rs = $DB->Query('SHOW GRANTS FOR CURRENT_USER');
148 while ($ar = $rs->Fetch())
149 {
150 $privilege = array_pop($ar);
151 if (preg_match('/^GRANT (.+?) ON/', $privilege, $match))
152 {
153 $privileges = array_merge($privileges, array_map('trim', explode(',', $match[1])));
154 }
155 }
156
157 $grantList = [];
158 if ($isSuperRequred && !in_array('SUPER', $privileges, true))
159 {
160 $grantList[] = 'SUPER';
161 }
162 if (!in_array('REPLICATION CLIENT', $privileges, true))
163 {
164 $grantList[] = 'REPLICATION CLIENT';
165 }
166 if (!$isSuperRequred && !in_array('REPLICATION_SLAVE_ADMIN', $privileges, true))
167 {
168 $grantList[] = 'REPLICATION_SLAVE_ADMIN';
169 }
170
171 $result['privilege'] = [
172 'IS_OK' => $grantList ? CClusterDBNodeCheck::ERROR : CClusterDBNodeCheck::OK,
173 'MESSAGE' => GetMessage('CLU_SLAVE_PRIVILEGE_MSG'),
174 'WIZ_REC' => ($grantList ? GetMessage('CLU_MASTER_STATUS_WIZREC', [
175 '#sql#' => 'GRANT ' . implode(', ', $grantList) . " on *.* to '" . $DB->DBLogin . "'@'%';",
176 ]) : ''),
177 ];
178
179 $DatabaseName = $DB->DBName;
180 $is_ok = false;
181 $rsBinLogs = $DB->Query('show master status', true, '', ['fixed_connection' => true]);
182 if (!$rsBinLogs)
183 {
184 $result['master_status'] = [
186 'MESSAGE' => GetMessage('CLU_MASTER_STATUS_MSG'),
187 'WIZ_REC' => GetMessage('CLU_MASTER_STATUS_WIZREC', ['#sql#' => "GRANT REPLICATION CLIENT on *.* to '" . $DB->DBLogin . "'@'%';"]),
188 ];
189 }
190 else
191 {
192 if ($ar = $rsBinLogs->Fetch())
193 {
194 $Binlog_Do_DB = implode(',', array_keys(array_flip(explode(',', $ar['Binlog_Do_DB']))));
195 if ($Binlog_Do_DB === $DatabaseName)
196 {
197 $is_ok = true;
198 }
199 }
200 if ($rsBinLogs->Fetch())
201 {
202 $is_ok = false;
203 }
204
205 $result['binlog_do_db'] = [
207 'MESSAGE' => GetMessage('CLU_SYNC_BINLOGDODB_MSG'),
208 'WIZ_REC' => GetMessage('CLU_SYNC_BINLOGDODB_WIZREC', ['#database#' => $DatabaseName]),
209 ];
210 }
211
212 return $result;
213 }
214
215 public function MainNodeForSlave()
216 {
217 global $DB;
218 $result = [];
219
220 $arMasters = [];
222 [
223 'ID' => 'ASC',
224 ],
225 [
226 '=ROLE_ID' => ['MAIN', 'MASTER'],
227 ]
228 );
229 while ($arData = $rsData->Fetch())
230 {
231 $arMasters[$arData['ID']] = $arData;
232 }
233
234 foreach ($arMasters as $node_id => $arNode)
235 {
236 if ($node_id == 1)
237 {
238 $nodeDB = $DB;
239 }
240 else
241 {
242 $nodeDB = CDatabase::GetDBNodeConnection($node_id, true);
243 }
244 $arMasters[$node_id]['DB'] = $nodeDB;
245 }
246
247 $auto_increment_increment = count($arMasters) + 1;
248 $bIncIsOK = true;
249 foreach ($arMasters as $node_id => $arNode)
250 {
251 $inc = $this->GetServerVariable($arNode['DB'], 'auto_increment_increment');
252 if ($inc != $auto_increment_increment)
253 {
254 $bIncIsOK = false;
255 $result[$node_id . '_auto_increment_increment'] = [
257 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_ERR_MSG', ['#node_id#' => $node_id, '#value#' => $auto_increment_increment, '#current#' => $inc]),
258 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_WIZREC', ['#value#' => $auto_increment_increment]),
259 ];
260 }
261 }
262 if ($bIncIsOK)
263 {
264 $result['_auto_increment_increment'] = [
265 'IS_OK' => CClusterDBNodeCheck::OK,
266 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_OK_MSG', ['#value#' => $auto_increment_increment]),
267 'WIZ_REC' => '',
268 ];
269 }
270
271 $auto_increment_offset = [];
272 $bIncIsOK = true;
273 foreach ($arMasters as $node_id => $arNode)
274 {
275 $offset = $this->GetServerVariable($arNode['DB'], 'auto_increment_offset');
276 $mod = $offset % $auto_increment_increment;
277 if (array_key_exists($mod, $auto_increment_offset))
278 {
279 $bIncIsOK = false;
280 $result[$node_id . '_auto_increment_offset'] = [
282 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_ERR_MSG', ['#node_id#' => $node_id, '#current#' => $offset]),
283 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_WIZREC', ['#current#' => $offset]),
284 ];
285 }
286 else
287 {
288 $auto_increment_offset[$mod] = $node_id;
289 }
290 }
291 if ($bIncIsOK)
292 {
293 $result['_auto_increment_offset'] = [
294 'IS_OK' => CClusterDBNodeCheck::OK,
295 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_OK_MSG', ['#value#' => $auto_increment_increment]),
296 'WIZ_REC' => '',
297 ];
298 }
299
300 $bRelayIsOK = true;
301 foreach ($arMasters as $node_id => $arNode)
302 {
303 $relay_log = $this->GetServerVariable($arNode['DB'], 'relay_log');
304 if ($relay_log == '')
305 {
306 $bRelayIsOK = false;
307 $result[$node_id . '_relay_log'] = [
309 'MESSAGE' => GetMessage('CLU_RELAY_LOG_ERR_MSG', ['#node_id#' => $node_id, '#relay-log#' => $relay_log]),
310 'WIZ_REC' => GetMessage('CLU_RELAY_LOG_WIZREC'),
311 ];
312 }
313 }
314 if ($bRelayIsOK)
315 {
316 $result['_relay_log'] = [
317 'IS_OK' => CClusterDBNodeCheck::OK,
318 'MESSAGE' => GetMessage('CLU_RELAY_LOG_OK_MSG'),
319 'WIZ_REC' => '',
320 ];
321 }
322
323 $bSlaveUpdatesIsOK = true;
324 foreach ($arMasters as $node_id => $arNode)
325 {
326 $log_slave_updates = $this->GetServerVariable($arNode['DB'], 'log_slave_updates');
327 if ($log_slave_updates !== 'ON')
328 {
329 $bSlaveUpdatesIsOK = false;
330 $result[$node_id . '_log_slave_updates'] = [
332 'MESSAGE' => GetMessage('CLU_LOG_SLAVE_UPDATES_MSG', ['#node_id#' => $node_id, '#log-slave-updates#' => $log_slave_updates]),
333 'WIZ_REC' => GetMessage('CLU_LOG_SLAVE_UPDATES_WIZREC', ['#value#' => 1]),
334 ];
335 }
336 }
337 if ($bSlaveUpdatesIsOK)
338 {
339 $result['_log_slave_updates'] = [
340 'IS_OK' => CClusterDBNodeCheck::OK,
341 'MESSAGE' => GetMessage('CLU_LOG_SLAVE_UPDATES_OK_MSG'),
342 'WIZ_REC' => '',
343 ];
344 }
345
346 return $result;
347 }
348
349 public function SlaveNodeIsReplicationRunning($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false)
350 {
351 $node_id = 'v99';
352 CClusterDBNode::GetByID($node_id, [
353 'ACTIVE' => 'Y',
354 'STATUS' => 'ONLINE',
355 'DB_HOST' => $db_host,
356 'DB_NAME' => $db_name,
357 'DB_LOGIN' => $db_login,
358 'DB_PASSWORD' => $db_password,
359 ]);
360
361 try
362 {
363 ob_start();
364 $nodeDB = CDatabase::GetDBNodeConnection($node_id, true);
365 $error = ob_get_contents();
366 ob_end_clean();
367 }
368 catch (\Bitrix\Main\DB\ConnectionException $e)
369 {
370 $nodeDB = false;
371 $error = $e->getMessage();
372 }
373
374 if (is_object($nodeDB))
375 {
376 //Check if replication is runnung
377 $rs = $nodeDB->Query('show slave status', true, '', ['fixed_connection' => true]);
378 $ar = $rs ? $rs->Fetch() : false;
379
380 if ($ar && $ar['Slave_IO_State'] <> '')
381 {
382 if ($ar['Master_Host'] == $master_host && $ar['Master_Port'] == $master_port)
383 {
384 return $nodeDB;
385 }
386 else
387 {
388 return GetMessage('CLU_RUNNING_SLAVE');
389 }
390 }
391 else
392 {
393 return false;
394 }
395 }
396 else
397 {
398 return $error;
399 }
400 }
401
402 public function SlaveNodeConnection($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false, $master_id = 1)
403 {
404 global $DB;
405
406 $node_id = 'v99';
407 CClusterDBNode::GetByID($node_id, [
408 'ACTIVE' => 'Y',
409 'STATUS' => 'ONLINE',
410 'DB_HOST' => $db_host,
411 'DB_NAME' => $db_name,
412 'DB_LOGIN' => $db_login,
413 'DB_PASSWORD' => $db_password,
414 ]);
415
416 try
417 {
418 ob_start();
419 $nodeDB = CDatabase::GetDBNodeConnection($node_id, true);
420 $error = ob_get_contents();
421 ob_end_clean();
422 }
423 catch (\Bitrix\Main\DB\ConnectionException $e)
424 {
425 $nodeDB = false;
426 $error = $e->getMessage();
427 }
428
429 if (is_object($nodeDB))
430 {
431 //Test if this connection is not the same as master
432 $bSkipSecondTest = false;
433 //1. Make sure that no replication is runnung
434 $rs = $nodeDB->Query('show slave status', true, '', ['fixed_connection' => true]);
435 $ar = $rs ? $rs->Fetch() : false;
436 if ($ar)
437 {
438 if ($ar['Slave_IO_State'] <> '')
439 {
440 if ($ar['Master_Host'] != $master_host || $ar['Master_Port'] != $master_port)
441 {
442 return GetMessage('CLU_RUNNING_SLAVE');
443 }
444 else
445 {
446 $bSkipSecondTest = true; //The replication is OK
447 }
448 }
449 }
450 //2. Check if b_cluster_dbnode exists on node
451 if ($nodeDB->TableExists('b_cluster_dbnode') && !$bSkipSecondTest)
452 {
453 //2.1 Generate uniq id
454 $uniqid = md5(mt_rand());
455 $DB->Query("UPDATE b_cluster_dbnode SET UNIQID='" . $uniqid . "' WHERE ID=1", false, '', ['fixed_connection' => true]);
456 $rs = $nodeDB->Query('SELECT UNIQID FROM b_cluster_dbnode WHERE ID=1', true);
457 if ($rs)
458 {
459 if ($ar = $rs->Fetch())
460 {
461 if ($ar['UNIQID'] == $uniqid)
462 {
463 return GetMessage('CLU_SAME_DATABASE');
464 }
465 }
466 }
467 }
468 //3. Check master connect
469 if ($master_host !== false && $master_port !== false)
470 {
471 $node_id = 'v98';
472 if ($master_id == 1)
473 {
474 CClusterDBNode::GetByID($node_id, [
475 'ACTIVE' => 'Y',
476 'STATUS' => 'ONLINE',
477 'DB_HOST' => $master_host . ':' . $master_port,
478 'DB_NAME' => $DB->DBName,
479 'DB_LOGIN' => $DB->DBLogin,
480 'DB_PASSWORD' => $DB->DBPassword,
481 ]);
482 }
483 else
484 {
485 $node_id = $master_id;
486 }
487
488 ob_start();
489 $masterDB = CDatabase::GetDBNodeConnection($node_id, true);
490 $error = ob_get_contents();
491 ob_end_clean();
492 if (is_object($masterDB))
493 {
494 //3.1 Check if b_cluster_dbnode is the same as on master
495 if (!$masterDB->TableExists('b_cluster_dbnode'))
496 {
497 return GetMessage('CLU_NOT_MASTER');
498 }
499
500 //3.2 Generate uniq id
501 $uniqid = md5(mt_rand());
502 $DB->Query("UPDATE b_cluster_dbnode SET UNIQID='" . $uniqid . "' WHERE ID=1", false, '', ['fixed_connection' => true]);
503
504 $Seconds_Behind_Master = 1;
505 $rs = $masterDB->Query('SHOW SLAVE STATUS');
506 if ($ar = $rs->Fetch())
507 {
508 if ($ar['Seconds_Behind_Master'] > 0)
509 {
510 $Seconds_Behind_Master += $ar['Seconds_Behind_Master'];
511 }
512 }
513 sleep($Seconds_Behind_Master);
514
515 $rs = $masterDB->Query('SELECT UNIQID FROM b_cluster_dbnode WHERE ID=1', true, '', ['fixed_connection' => true]);
516 if (!$rs)
517 {
518 return GetMessage('CLU_NOT_MASTER');
519 }
520
521 $ar = $rs->Fetch();
522 if (!$ar)
523 {
524 return GetMessage('CLU_NOT_MASTER');
525 }
526
527 if ($ar['UNIQID'] != $uniqid)
528 {
529 return GetMessage('CLU_NOT_MASTER');
530 }
531 }
532 else
533 {
534 return GetMessage('CLU_MASTER_CONNECT_ERROR') . $error;
535 }
536 }
537
538 return $nodeDB;
539 }
540 else
541 {
542 return $error;
543 }
544 }
545
546 public function SlaveNodeCommon($nodeDB)
547 {
548 $result = [];
549
550 global $DB;
551 $main_character_set_server = $this->GetServerVariable($DB, 'character_set_server');
552 $main_collation_server = $this->GetServerVariable($DB, 'collation_server');
553
554 $arCharset = static::GetServerVariables($nodeDB, [
555 'character_set_server' => '',
556 'character_set_database' => '',
557 'character_set_connection' => '',
558 'character_set_client' => '',
559 ], 'character_set%');
560
561 $arCollation = static::GetServerVariables($nodeDB, [
562 'collation_server' => '',
563 'collation_database' => '',
564 'collation_connection' => '',
565 ], 'collation%');
566
567 $is_ok = $main_character_set_server === $arCharset['character_set_server']
568 && $main_collation_server === $arCollation['collation_server']
569 ;
570 $is_ok = $is_ok || (defined('BX_CLUSTER_SKIP_CHARSET_CHECK') && constant('BX_CLUSTER_SKIP_CHARSET_CHECK') === true);
571 $result['master_charset'] = [
573 'MESSAGE' => GetMessage('CLU_MASTER_CHARSET_MSG'),
574 'WIZ_REC' => GetMessage('CLU_MASTER_CHARSET_WIZREC', [
575 '#character_set_server#' => $arCharset['character_set_server'],
576 '#collation_server#' => $arCollation['collation_server'],
577 ]),
578 ];
579
580 $is_ok = $arCharset['character_set_server'] !== ''
581 && $arCharset['character_set_server'] === $arCharset['character_set_database']
582 && $arCharset['character_set_database'] === $arCharset['character_set_connection']
583 && $arCharset['character_set_connection'] === $arCharset['character_set_client']
584 ;
585 $is_ok = $is_ok || (defined('BX_CLUSTER_SKIP_CHARSET_CHECK') && constant('BX_CLUSTER_SKIP_CHARSET_CHECK') === true);
586 $result['charset'] = [
588 'MESSAGE' => GetMessage('CLU_CHARSET_MSG'),
589 'WIZ_REC' => GetMessage('CLU_CHARSET_WIZREC', [
590 '#character_set_server#' => $arCharset['character_set_server'],
591 '#character_set_database#' => $arCharset['character_set_database'],
592 '#character_set_connection#' => $arCharset['character_set_connection'],
593 '#character_set_client#' => $arCharset['character_set_client'],
594 ]),
595 ];
596
597 $is_ok = $arCollation['collation_server'] !== ''
598 && $arCollation['collation_server'] === $arCollation['collation_database']
599 && $arCollation['collation_database'] === $arCollation['collation_connection']
600 ;
601 $is_ok = $is_ok || (defined('BX_CLUSTER_SKIP_CHARSET_CHECK') && constant('BX_CLUSTER_SKIP_CHARSET_CHECK') === true);
602 $result['collation'] = [
604 'MESSAGE' => GetMessage('CLU_COLLATION_MSG'),
605 'WIZ_REC' => GetMessage('CLU_COLLATION_WIZREC', [
606 '#collation_server#' => $arCollation['collation_server'],
607 '#collation_database#' => $arCollation['collation_database'],
608 '#collation_connection#' => $arCollation['collation_connection'],
609 ]),
610 ];
611
612 $arTestSQL = [
613 0 => 'drop table b_cluster_test',
614 'sql_create' => 'create table b_cluster_test(column1 int)',
615 'sql_insert' => 'insert into b_cluster_test (column1) values (1)',
616 'sql_select' => 'select * from b_cluster_test',
617 'sql_update' => 'update b_cluster_test set column1=2 where column1=1',
618 'sql_delete' => 'delete from b_cluster_test where column1=2',
619 'sql_drop' => 'drop table b_cluster_test',
620 ];
621 $is_ok = true;
622 $sql_erorrs_list = '';
623 foreach ($arTestSQL as $id => $sql)
624 {
625 $res = $nodeDB->Query($sql, true);
626 if (!$res && $id !== 0)
627 {
628 $is_ok = false;
629 $sql_erorrs_list .= '<br />&nbsp;' . $sql . ': ' . $nodeDB->db_Error . "\n";
630 }
631 }
632 $result['sql'] = [
634 'MESSAGE' => GetMessage('CLU_SQL_MSG'),
635 'WIZ_REC' => GetMessage('CLU_SQL_WIZREC', [
636 '#sql_erorrs_list#' => $sql_erorrs_list,
637 ]),
638 ];
639
640 $required_version = '5.0.0';
641 $slave_version = $this->GetServerVariable($nodeDB, 'version');
642 $is_ok = version_compare($required_version, $slave_version) <= 0;
643 $result['version'] = [
645 'MESSAGE' => GetMessage('CLU_SLAVE_VERSION_MSG', [
646 '#slave-version#' => $slave_version,
647 '#required-version#' => $required_version,
648 ]),
649 'WIZ_REC' => GetMessage('CLU_VERSION_WIZREC'),
650 ];
651
652 return $result;
653 }
654
655 public function SlaveNodeForReplication($nodeDB)
656 {
657 global $DB;
658
659 $result = [];
660
661 $main_server_id = intval($this->GetServerVariable($DB, 'server_id'));
662 $node_server_id = intval($this->GetServerVariable($nodeDB, 'server_id'));
663 $is_ok = $node_server_id > 0 && $main_server_id != $node_server_id;
664 if ($is_ok)
665 {
666 $rsNodes = CClusterDBNode::GetList([], [
667 '=SERVER_ID' => $node_server_id,
668 '!=MASTER_ID' => false,
669 ]);
670 $is_ok2 = !is_array($rsNodes->Fetch());
671 }
672 else
673 {
674 $is_ok2 = true;
675 }
676
677 $result['server_id'] = [
678 'IS_OK' => $is_ok && $is_ok2 ? CClusterDBNodeCheck::OK : CClusterDBNodeCheck::ERROR,
679 'MESSAGE' => GetMessage('CLU_SERVER_ID_MSG', ['#server-id#' => $node_server_id]),
680 'WIZ_REC' => ($is_ok ? '' : GetMessage('CLU_SERVER_ID_WIZREC1')) . ' '
681 . ($is_ok2 ? '' : GetMessage('CLU_SERVER_ID_WIZREC2')) . ' '
682 . GetMessage('CLU_SERVER_ID_WIZREC')
683 ,
684 ];
685
686 $master_max_allowed_packet = $this->GetServerVariable($DB, 'max_allowed_packet');
687 $slave_max_allowed_packet = $this->GetServerVariable($nodeDB, 'max_allowed_packet');
688 $is_ok = $slave_max_allowed_packet >= $master_max_allowed_packet;
689 $result['max_allowed_packet'] = [
691 'MESSAGE' => GetMessage('CLU_MAX_ALLOWED_PACKET_MSG'),
692 'WIZ_REC' => GetMessage('CLU_MAX_ALLOWED_PACKET_WIZREC'),
693 ];
694
695 $master_version = $this->GetServerVariable($DB, 'version');
696 $slave_version = $this->GetServerVariable($nodeDB, 'version');
697 $is_ok = version_compare($master_version, $slave_version) <= 0;
698 $result['slave_version'] = [
700 'MESSAGE' => GetMessage('CLU_VERSION_MSG', [
701 '#slave-version#' => $slave_version,
702 '#master-version#' => $master_version,
703 ]),
704 'WIZ_REC' => GetMessage('CLU_VERSION_WIZREC'),
705 ];
706
707 $relay_log = $this->GetServerVariable($nodeDB, 'relay_log');
708 $is_ok = $relay_log <> '';
709 $result['relay_log'] = [
711 'MESSAGE' => GetMessage('CLU_SLAVE_RELAY_LOG_MSG'),
712 'WIZ_REC' => GetMessage('CLU_RELAY_LOG_WIZREC'),
713 ];
714
715 $isSuperRequred = version_compare($slave_version, '8.0') < 0;
716
717 $privileges = [];
718 $rs = $nodeDB->Query('SHOW GRANTS FOR CURRENT_USER');
719 while ($ar = $rs->Fetch())
720 {
721 $privilege = array_pop($ar);
722 if (preg_match('/^GRANT (.+?) ON/', $privilege, $match))
723 {
724 $privileges = array_merge($privileges, array_map('trim', explode(',', $match[1])));
725 }
726 }
727
728 $grantList = [];
729 if ($isSuperRequred && !in_array('SUPER', $privileges, true))
730 {
731 $grantList[] = 'SUPER';
732 }
733 if (!in_array('REPLICATION CLIENT', $privileges, true))
734 {
735 $grantList[] = 'REPLICATION CLIENT';
736 }
737 if (!in_array('REPLICATION SLAVE', $privileges, true))
738 {
739 $grantList[] = 'REPLICATION SLAVE';
740 }
741 if (!$isSuperRequred && !in_array('REPLICATION_SLAVE_ADMIN', $privileges, true))
742 {
743 $grantList[] = 'REPLICATION_SLAVE_ADMIN';
744 }
745
746 $result['privilege'] = [
747 'IS_OK' => $grantList ? CClusterDBNodeCheck::ERROR : CClusterDBNodeCheck::OK,
748 'MESSAGE' => GetMessage('CLU_SLAVE_PRIVILEGE_MSG'),
749 'WIZ_REC' => ($grantList ? GetMessage('CLU_MASTER_STATUS_WIZREC', [
750 '#sql#' => 'GRANT ' . implode(', ', $grantList) . " on *.* to '" . $nodeDB->DBLogin . "'@'%';",
751 ]) : ''),
752 ];
753
754 return $result;
755 }
756
757 public function SlaveNodeForMaster($nodeDB)
758 {
759 global $DB;
760 $result = [];
761
762 $arMasters = [];
763
765 [
766 'ID' => 'ASC',
767 ],
768 [
769 '=ROLE_ID' => ['MAIN', 'MASTER'],
770 ]
771 );
772 while ($arData = $rsData->Fetch())
773 {
774 $arMasters[$arData['ID']] = $arData;
775 }
776
777 $arMasters['v99'] = [];//virtual connection must be alredy setup
778
779 foreach ($arMasters as $node_id => $arNode)
780 {
781 if ($node_id == 1)
782 {
783 $nodeDB = $DB;
784 }
785 else
786 {
787 $nodeDB = CDatabase::GetDBNodeConnection($node_id, true);
788 }
789 $arMasters[$node_id]['DB'] = $nodeDB;
790 }
791
792 $auto_increment_increment = count($arMasters);
793 $bIncIsOK = true;
794 foreach ($arMasters as $node_id => $arNode)
795 {
796 $inc = $this->GetServerVariable($arNode['DB'], 'auto_increment_increment');
797 if ($inc != $auto_increment_increment)
798 {
799 $bIncIsOK = false;
800 if ($node_id == 'v99')
801 {
802 $result[$node_id . '_auto_increment_increment'] = [
804 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_NODE_ERR_MSG', ['#value#' => $auto_increment_increment, '#current#' => $inc]),
805 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_WIZREC', ['#value#' => $auto_increment_increment]),
806 ];
807 }
808 else
809 {
810 $result[$node_id . '_auto_increment_increment'] = [
812 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_ERR_MSG', ['#node_id#' => $node_id, '#value#' => $auto_increment_increment, '#current#' => $inc]),
813 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_WIZREC', ['#value#' => $auto_increment_increment]),
814 ];
815 }
816 }
817 }
818 if ($bIncIsOK)
819 {
820 $result['_auto_increment_increment'] = [
821 'IS_OK' => CClusterDBNodeCheck::OK,
822 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_INCREMENT_OK_MSG', ['#value#' => $auto_increment_increment]),
823 'WIZ_REC' => '',
824 ];
825 }
826
827 $auto_increment_offset = [];
828 $bIncIsOK = true;
829 foreach ($arMasters as $node_id => $arNode)
830 {
831 $offset = $this->GetServerVariable($arNode['DB'], 'auto_increment_offset');
832 $mod = $offset % $auto_increment_increment;
833
834 if (array_key_exists($mod, $auto_increment_offset))
835 {
836 $bIncIsOK = false;
837 if ($node_id == 'v99')
838 {
839 $result[$node_id . '_auto_increment_offset'] = [
841 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_NODE_ERR_MSG', ['#current#' => $offset]),
842 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_WIZREC', ['#current#' => $offset]),
843 ];
844 }
845 else
846 {
847 $result[$node_id . '_auto_increment_offset'] = [
849 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_ERR_MSG', ['#node_id#' => $node_id, '#current#' => $offset]),
850 'WIZ_REC' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_WIZREC', ['#current#' => $offset]),
851 ];
852 }
853 }
854 else
855 {
856 $auto_increment_offset[$mod] = $node_id;
857 }
858 }
859 if ($bIncIsOK)
860 {
861 $result['_auto_increment_offset'] = [
862 'IS_OK' => CClusterDBNodeCheck::OK,
863 'MESSAGE' => GetMessage('CLU_AUTO_INCREMENT_OFFSET_OK_MSG', ['#value#' => $auto_increment_increment]),
864 'WIZ_REC' => '',
865 ];
866 }
867
868 $bRelayIsOK = true;
869 foreach ($arMasters as $node_id => $arNode)
870 {
871 $relay_log = $this->GetServerVariable($arNode['DB'], 'relay_log');
872 if ($relay_log == '')
873 {
874 $bIncIsOK = false;
875 $result[$node_id . '_relay_log'] = [
877 'MESSAGE' => GetMessage('CLU_RELAY_LOG_ERR_MSG', ['#node_id#' => $node_id, '#relay-log#' => $relay_log]),
878 'WIZ_REC' => GetMessage('CLU_RELAY_LOG_WIZREC'),
879 ];
880 }
881 }
882 if ($bRelayIsOK)
883 {
884 $result['_relay_log'] = [
885 'IS_OK' => CClusterDBNodeCheck::OK,
886 'MESSAGE' => GetMessage('CLU_RELAY_LOG_OK_MSG', ['#value#' => $auto_increment_increment]),
887 'WIZ_REC' => '',
888 ];
889 }
890
891 $log_bin = $this->GetServerVariable($nodeDB, 'log_bin');
892 $is_ok = $log_bin === 'ON';
893 $result['log_bin'] = [
895 'MESSAGE' => GetMessage('CLU_LOG_BIN_NODE_MSG', ['#log-bin#' => $log_bin]),
896 'WIZ_REC' => GetMessage('CLU_LOG_BIN_WIZREC'),
897 ];
898
899 $skip_networking = $this->GetServerVariable($nodeDB, 'skip_networking');
900 $is_ok = $skip_networking === 'OFF';
901 $result['skip_networking'] = [
903 'MESSAGE' => GetMessage('CLU_SKIP_NETWORKING_NODE_MSG', ['#skip-networking#' => $skip_networking]),
904 'WIZ_REC' => GetMessage('CLU_SKIP_NETWORKING_WIZREC'),
905 ];
906
907 $innodb_flush_log_at_trx_commit = $this->GetServerVariable($nodeDB, 'innodb_flush_log_at_trx_commit');
908 //if($innodb_flush_log_at_trx_commit !== '1')
909 {
910 $is_ok = $innodb_flush_log_at_trx_commit === '1';
911 $result['innodb_flush_log_at_trx_commit'] = [
913 'MESSAGE' => GetMessage('CLU_FLUSH_ON_COMMIT_MSG', ['#innodb_flush_log_at_trx_commit#' => $innodb_flush_log_at_trx_commit]),
914 'WIZ_REC' => '',
915 ];
916 }
917
918 $sync_binlog = $this->GetServerVariable($nodeDB, 'sync_binlog');
919 //if($sync_binlog !== '1')
920 {
921 $is_ok = $sync_binlog === '1';
922 $result['sync_binlog'] = [
924 'MESSAGE' => GetMessage('CLU_SYNC_BINLOG_MSG', ['#sync_binlog#' => $sync_binlog]),
925 'WIZ_REC' => '',
926 ];
927 }
928
929 $DatabaseName = $DB->DBName;
930 $is_ok = false;
931 $rsBinLogs = $nodeDB->Query('show master status', true, '', ['fixed_connection' => true]);
932 if (!$rsBinLogs)
933 {
934 $result['master_status'] = [
936 'MESSAGE' => GetMessage('CLU_MASTER_STATUS_MSG'),
937 'WIZ_REC' => GetMessage('CLU_MASTER_STATUS_WIZREC', ['#sql#' => "GRANT REPLICATION CLIENT on *.* to '" . $nodeDB->DBLogin . "'@'%';"]),
938 ];
939 }
940 else
941 {
942 if ($ar = $rsBinLogs->Fetch())
943 {
944 $Binlog_Do_DB = implode(',', array_keys(array_flip(explode(',', $ar['Binlog_Do_DB']))));
945 if ($Binlog_Do_DB === $DatabaseName)
946 {
947 $is_ok = true;
948 }
949 }
950 if ($rsBinLogs->Fetch())
951 {
952 $is_ok = false;
953 }
954
955 $result['binlog_do_db'] = [
957 'MESSAGE' => GetMessage('CLU_SYNC_BINLOGDODB_MSG'),
958 'WIZ_REC' => GetMessage('CLU_SYNC_BINLOGDODB_WIZREC', ['#database#' => $DatabaseName]),
959 ];
960 }
961
962 return $result;
963 }
964
965 public static function GetServerVariables($DB, $arVariables, $db_mask)
966 {
967 if ($db_mask)
968 {
969 $where = " like '" . $DB->ForSql($db_mask) . "'";
970 }
971 else
972 {
973 $where = '';
974 }
975
976 $rs = $DB->Query('show variables ' . $where, false, '', ['fixed_connection' => true]);
977 while ($ar = $rs->Fetch())
978 {
979 if (array_key_exists($ar['Variable_name'], $arVariables))
980 {
981 $arVariables[$ar['Variable_name']] = $ar['Value'];
982 }
983 }
984
985 return $arVariables;
986 }
987
988 public function GetServerVariable($DB, $var_name)
989 {
990 $arResult = CClusterDBNodeCheck::GetServerVariables($DB, [$var_name => ''], $var_name);
991 return $arResult[$var_name];
992 }
993}
$arResult
Определения generate_coupon.php:16
static GetList($arOrder=false, $arFilter=false, $arSelect=false)
Определения dbnode.php:284
static GetByID($node_id, $arVirtNode=false)
Определения dbnode.php:79
MainNodeForReplication($arMasterNode)
Определения dbnode_check.php:90
static GetServerVariables($DB, $arVariables, $db_mask)
Определения dbnode_check.php:965
GetServerVariable($DB, $var_name)
Определения dbnode_check.php:988
const OK
Определения dbnode_check.php:6
SlaveNodeForMaster($nodeDB)
Определения dbnode_check.php:757
SlaveNodeForReplication($nodeDB)
Определения dbnode_check.php:655
MainNodeForSlave()
Определения dbnode_check.php:215
const ERROR
Определения dbnode_check.php:8
SlaveNodeCommon($nodeDB)
Определения dbnode_check.php:546
SlaveNodeIsReplicationRunning($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false)
Определения dbnode_check.php:349
SlaveNodeConnection($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false, $master_id=1)
Определения dbnode_check.php:402
const WARNING
Определения dbnode_check.php:7
MainNodeCommon($arMasterNode)
Определения dbnode_check.php:10
static checkForServers($toBeAddedCount=0)
Определения include.php:34
if($childrenCount<=0) $mod
Определения sync.php:11
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$ar
Определения options.php:199
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$error
Определения subscription_card_product.php:20
$rs
Определения action.php:82
if(file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log") &&is_file($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log") &&is_readable($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log")) $rsData
Определения update_log.php:102