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 return [];
13 }
14
15 public function MainNodeForReplication($arMasterNode)
16 {
17 return [];
18 }
19
20 public function MainNodeForSlave()
21 {
22 return [];
23 }
24
25 public function SlaveNodeIsReplicationRunning($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false)
26 {
27 return false;
28 }
29
30 public function SlaveNodeConnection($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false, $master_id = 1)
31 {
32 global $DB;
33
34 $node_id = 'v99';
35 CClusterDBNode::GetByID($node_id, [
36 'ACTIVE' => 'Y',
37 'STATUS' => 'ONLINE',
38 'DB_HOST' => $db_host,
39 'DB_NAME' => $db_name,
40 'DB_LOGIN' => $db_login,
41 'DB_PASSWORD' => $db_password,
42 ]);
43
44 try
45 {
46 ob_start();
47 $nodeDB = CDatabase::GetDBNodeConnection($node_id, true);
48 $error = ob_get_contents();
49 ob_end_clean();
50 }
51 catch (\Bitrix\Main\DB\ConnectionException $e)
52 {
53 $nodeDB = false;
54 $error = $e->getMessage();
55 }
56
57 if (is_object($nodeDB))
58 {
59 //Test if this connection is not the same as master
60 $bSkipSecondTest = false;
61 //1. Make sure that no replication is runnung
62 $rs = $nodeDB->Query('select CLIENT_ADDR,STATE,REPLAY_LAG,SYNC_STATE,REPLY_TIME from bx_cluster_stat_replication()', true, '', ['fixed_connection' => true]);
63 $ar = $rs ? $rs->Fetch() : false;
64 if ($ar)
65 {
66 return GetMessage('CLU_RUNNING_SLAVE');
67 }
68 //2. Check if b_cluster_dbnode exists on node
69 if ($nodeDB->TableExists('b_cluster_dbnode') && !$bSkipSecondTest)
70 {
71 //2.1 Generate uniq id
72 $uniqid = md5(mt_rand());
73 $DB->Query("UPDATE b_cluster_dbnode SET UNIQID='" . $uniqid . "' WHERE ID=1", false, '', ['fixed_connection' => true]);
74 $rs = $nodeDB->Query('SELECT UNIQID FROM b_cluster_dbnode WHERE ID=1', true);
75 if ($rs)
76 {
77 if ($ar = $rs->Fetch())
78 {
79 if ($ar['UNIQID'] == $uniqid)
80 {
81 return GetMessage('CLU_SAME_DATABASE');
82 }
83 }
84 }
85 }
86
87 return $nodeDB;
88 }
89 else
90 {
91 return $error;
92 }
93 }
94
95 public function SlaveNodeCommon($nodeDB)
96 {
97 return [];
98 }
99
100 public function SlaveNodeForReplication($nodeDB)
101 {
102 return [];
103 }
104
105 public function SlaveNodeForMaster($nodeDB)
106 {
107 return [];
108 }
109
110 public static function GetServerVariables($DB, $arVariables, $db_mask)
111 {
112 return $arVariables;
113 }
114
115 public function GetServerVariable($DB, $var_name)
116 {
117 $arResult = CClusterDBNodeCheck::GetServerVariables($DB, [$var_name => ''], $var_name);
118 return $arResult[$var_name];
119 }
120}
$arResult
Определения generate_coupon.php:16
static GetByID($node_id, $arVirtNode=false)
Определения dbnode.php:79
MainNodeForReplication($arMasterNode)
Определения dbnode_check.php:15
static GetServerVariables($DB, $arVariables, $db_mask)
Определения dbnode_check.php:110
GetServerVariable($DB, $var_name)
Определения dbnode_check.php:115
const OK
Определения dbnode_check.php:6
SlaveNodeForMaster($nodeDB)
Определения dbnode_check.php:105
SlaveNodeForReplication($nodeDB)
Определения dbnode_check.php:100
MainNodeForSlave()
Определения dbnode_check.php:20
const ERROR
Определения dbnode_check.php:8
SlaveNodeCommon($nodeDB)
Определения dbnode_check.php:95
SlaveNodeIsReplicationRunning($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false)
Определения dbnode_check.php:25
SlaveNodeConnection($db_host, $db_name, $db_login, $db_password, $master_host=false, $master_port=false, $master_id=1)
Определения dbnode_check.php:30
const WARNING
Определения dbnode_check.php:7
MainNodeCommon($arMasterNode)
Определения dbnode_check.php:10
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
$error
Определения subscription_card_product.php:20
$rs
Определения action.php:82