From 69ac8451fbcd5b6f1dc55d98994fb9dca9757d82 Mon Sep 17 00:00:00 2001 From: Yoshiyuki Asaba Date: Fri, 22 Jun 2007 10:15:26 +0000 Subject: [PATCH] * support online recovery on pgpoolAdmin. * support to edit new pgpool.conf parameters. --- command.php | 7 ++++++- common.php | 7 ++++++- definePgpoolConfParam.php | 15 +++++++++++++ lang/en.lang.php | 5 +++++ lang/ja.lang.php | 5 +++++ nodeStatus.php | 38 ++++++++++++++++----------------- pgconfig.php | 31 +++++++++++++++++++++++++-- status.php | 11 ++++++++++ templates/nodeStatus.tpl | 2 ++ templates/pgconfig.tpl | 44 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 141 insertions(+), 24 deletions(-) diff --git a/command.php b/command.php index 5b3bccf..d1e7aea 100644 --- a/command.php +++ b/command.php @@ -53,7 +53,7 @@ function execPcp($command, $num='') { $param = readPcpInfo(); $param['hostname'] = _PGPOOL2_PCP_HOSTNAME; - + $args = " " . $param['pcp_timeout'] . " " . $param['hostname'] . " " . $param['pcp_port'] . " ". $_SESSION[SESSION_LOGIN_USER] . " " . $_SESSION[SESSION_LOGIN_USER_PASSWORD] . " " . $num; switch ($command) { @@ -109,6 +109,11 @@ function execPcp($command, $num='') { $ret = exec($cmd, $output, $return_var); break; + case 'PCP_RECOVERY_NODE': + $cmd = _PGPOOL2_PCP_DIR . '/pcp_recovery_node' . $args; + $ret = exec($cmd, $output, $return_var); + break; + default: return array($pspStatus[1] => $pspStatus[1]); } diff --git a/common.php b/common.php index f252c12..5be2d02 100644 --- a/common.php +++ b/common.php @@ -360,6 +360,10 @@ function readConfigParams($paramList = FALSE) { $num = str_replace('backend_weight', '', $key); $configParam['backend_weight'][$num] = $value; } + else if(preg_match("/^backend_data_directory/", $key)) { + $num = str_replace('backend_data_directory', '', $key); + $configParam['backend_data_directory'][$num] = ereg_replace("'", "", $value); + } else { $configParam[$key] = ereg_replace("'", "", $value); } @@ -374,7 +378,8 @@ function readConfigParams($paramList = FALSE) { include('definePgpoolConfParam.php'); if(!preg_match("/^backend_hostname/", $key) && !preg_match("/^backend_port/", $key) - && !preg_match("/^backend_weight/", $key)) { + && !preg_match("/^backend_weight/", $key) + && !preg_match("/^backend_data_directory/", $key)) { $results[$key] = $pgpoolConfigParam[$key]['default']; } } diff --git a/definePgpoolConfParam.php b/definePgpoolConfParam.php index fb62ee0..56007f6 100644 --- a/definePgpoolConfParam.php +++ b/definePgpoolConfParam.php @@ -226,10 +226,25 @@ $pgpoolConfigBackendParam[$key]['default'] ='5432'; $pgpoolConfigBackendParam[$key]['min'] = 1024; $pgpoolConfigBackendParam[$key]['max'] = 65535; +$key = 'backend_data_directory'; +$pgpoolConfigBackendParam[$key]['type'] ='C'; +$pgpoolConfigBackendParam[$key]['default'] =''; +$pgpoolConfigBackendParam[$key]['regexp'] = "$dirreg"; + $key = 'backend_weight'; $pgpoolConfigBackendParam[$key]['type'] ='F'; $pgpoolConfigBackendParam[$key]['default'] ='1'; $pgpoolConfigBackendParam[$key]['min'] = 0.0; $pgpoolConfigBackendParam[$key]['max'] = 1.0; +$key = 'recovery_user'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] ='nodoby'; +$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z_\.\-]+$"; + +$key = 'recovery_password'; +$pgpoolConfigParam[$key]['type'] ='C'; +$pgpoolConfigParam[$key]['default'] =''; +$pgpoolConfigParam[$key]['regexp'] = "^[0-9a-zA-Z_\.\-]+$"; + ?> diff --git a/lang/en.lang.php b/lang/en.lang.php index aaab5f0..1a86e70 100644 --- a/lang/en.lang.php +++ b/lang/en.lang.php @@ -30,6 +30,7 @@ $message = array( 'descBackend_port' => 'The port number where real PostgreSQL server is running on', 'descBackend_socket_dir' => 'The socket directory PostgreSQL could connect', 'descBackend_weight' => 'Load balance weight when pgpool is running in the state of load balance mode', + 'descBackend_data_directory' => 'PostgreSQL database directory', 'descChild_life_time' => 'Life of a idle child process in seconds', 'descChild_max_connections' => 'If child_max_connections connections were received, child exits', 'descConnection_cache' => 'If true, cache connections to PostgreSQL', @@ -54,6 +55,8 @@ $message = array( 'descPgpool2_hostname' => 'Pgpool2 server name where running on', 'descPort' => 'The port number where pgpool is running on', 'descPrint_timestamp' => 'If true timestamp is added to each log line', + 'descRecovery_user' => 'PostgreSQL user name for online recovery', + 'descRecovery_password' => 'PostgreSQL user password for online recovery', 'descReplication_mode' => 'Set this true if you are going to use replication functionality', 'descReplication_stop_on_mismatch' => 'Stop replication mode on data mismatch between master and secondary', 'descReplication_strict' => 'If true, pgpool will wait for the completion of the master query before sending a query to the secondary server', @@ -186,6 +189,7 @@ $message = array( 'strRestartOption' => 'pgpool Restart Option', 'strRestartPgpool' => 'Restart pgpool', 'strReturn' => 'Return', + 'strRecovery' => 'Recovery', 'strSchemaName' => 'Schema Name', 'strSearch' => 'Search', 'strSecondaryServer' => 'Secondary Server', @@ -224,6 +228,7 @@ $message = array( 'e1009' => 'No found pcp.conf.', 'e1010' => 'pcp_attach_node command error occurred.', 'e1011' => 'No found log ifle.', + 'e1012' => 'pcp_recovery_node command error occurred.', 'e2001' => 'Database connection error occurred.', 'e2002' => 'The error occurred when SELECT was executed', 'e2003' => 'No found pgpool.conf.', diff --git a/lang/ja.lang.php b/lang/ja.lang.php index 305311e..eeeb213 100644 --- a/lang/ja.lang.php +++ b/lang/ja.lang.php @@ -30,6 +30,7 @@ $message = array( 'descBackend_port' => 'PostgreSQLサーバのポート番号', 'descBackend_socket_dir' => 'PostgreSQLサーバのUnix domain socketのディレクトリ', 'descBackend_weight' => 'ロードバランスモード時のSELECTを振り分ける「重み」の定義', + 'descBackend_data_directory' => 'PostgreSQLサーバのデータベースディレクトリ', 'descChild_life_time' => 'pgpoolの子プロセスの寿命', 'descChild_max_connections' => '各pgpool子プロセスが終了するまでの接続回数', 'descConnection_cache' => 'コネクションをキャッシュ', @@ -54,6 +55,8 @@ $message = array( 'descPgpool2_hostname' => 'pgpool2 が動作しているホスト名', 'descPort' => 'pgpoolがコネクションを受け付けるポート番号', 'descPrint_timestamp' => 'pgpoolのログにタイムスタンプを追加', + 'descRecovery_user' => 'リカバリを行うためのPostgreSQLユーザ', + 'descRecovery_password' => 'リカバリを行うためのPostgreSQLユーザパスワード', 'descReplication_mode' => 'レプリケーションモードの有効化', 'descReplication_stop_on_mismatch' => 'trueを指定するとマスタとセカンダリの間でデータの不一致があった場合に強制的に縮退運転', 'descReplication_strict' => 'masterの問い合わせ処理の完了を待ってからsecondaryの処理', @@ -186,6 +189,7 @@ $message = array( 'strRestartOption' => 'pgpool再起動オプション', 'strRestartPgpool' => 'pgpool再起動', 'strReturn' => '復帰', + 'strRecovery' => 'リカバリ', 'strSchemaName' => 'スキーマ名', 'strSearch' => '検索', 'strSecondaryServer' => 'セカンダリサーバ', @@ -227,6 +231,7 @@ $message = array( 'e1009' => '指定したpcp.confが見つかりません', 'e1010' => 'pcp_attach_nodeコマンドでエラーが発生しました', 'e1011' => 'ログファイルが見つかりません', + 'e1012' => 'pcp_recovery_nodeコマンドでエラーが発生しました', 'e2001' => 'データベースに接続できません', 'e2002' => 'レコード取得時にエラーが発生しました', 'e2003' => 'pgpool.confが見つかりません', diff --git a/nodeStatus.php b/nodeStatus.php index 5f8b476..48ce7f5 100644 --- a/nodeStatus.php +++ b/nodeStatus.php @@ -67,27 +67,25 @@ for($i=0; $i<$nodeCount; $i++) { array_push($nodeInfo[$i], 'none'); } else { switch($nodeInfo[$i][2]) { - case 1: - case 2: - if($isReplicationMode || $isMasterSlaveMode) { - array_push($nodeInfo[$i], 'disconnect'); - } else { - array_push($nodeInfo[$i], 'none'); + case 1: + case 2: + if($isReplicationMode || $isMasterSlaveMode) { + array_push($nodeInfo[$i], 'disconnect'); + } else { + array_push($nodeInfo[$i], 'none'); + } + break; + case 3: + if($isReplicationMode || $isMasterSlaveMode) { + if(NodeActive($i)) { + array_push($nodeInfo[$i], 'return'); + } else { + array_push($nodeInfo[$i], 'recovery'); } - break; - case 3: - if(NodeActive($i)) { - if($isReplicationMode || $isMasterSlaveMode) { - array_push($nodeInfo[$i], 'return'); - } else { - array_push($nodeInfo[$i], 'none'); - } - break; - } - else { - array_push($nodeInfo[$i], 'none'); - } - break; + } else { + array_push($nodeInfo[$i], 'none'); + } + break; } } } diff --git a/pgconfig.php b/pgconfig.php index 4b959b3..2a6edd3 100644 --- a/pgconfig.php +++ b/pgconfig.php @@ -69,6 +69,11 @@ if($action == 'add') { } else { $configValue['backend_weight'] = array(); } + if(isset($_POST['backend_data_directory'])) { + $configValue['backend_data_directory'] = $_POST['backend_data_directory']; + } else { + $configValue['backend_data_directory'] = array(); + } $tpl->assign('params', $configValue); $tpl->assign('isAdd', true); @@ -96,10 +101,14 @@ if($action == 'add') { if(isset($_POST['backend_weight'])) { $configValue['backend_weight'] = $_POST['backend_weight']; } + if(isset($_POST['backend_data_directory'])) { + $configValue['backend_data_directory'] = $_POST['backend_data_directory']; + } array_pop($configValue['backend_hostname']); array_pop($configValue['backend_port']); array_pop($configValue['backend_weight']); + array_pop($configValue['backend_data_directory']); $tpl->assign('params', $configValue); $tpl->assign('isAdd', false); $tpl->display('pgconfig.tpl'); @@ -159,6 +168,7 @@ switch( $action ) { $hostname = $configValue['backend_hostname'][$i]; $port = $configValue['backend_port'][$i]; $weight = $configValue['backend_weight'][$i]; + $data_directory = $configValue['backend_data_directory'][$i]; $result = FALSE; $result = checkString ($hostname, @@ -184,6 +194,15 @@ switch( $action ) { } else { $error['backend_weight'][$i] = FALSE; } + + // check backend_data_directory + $result = checkString ($data_directory, + $pgpoolConfigBackendParam['backend_data_directory']['regexp']); + if(!$result) { + $error['backend_data_directory'][$i] = TRUE; + } else { + $error['backend_data_directory'][$i] = FALSE; + } } } @@ -192,7 +211,8 @@ switch( $action ) { foreach($error as $key => $value) { if(preg_match("/^backend_hostname/", $key) || preg_match("/^backend_port/", $key) - || preg_match("/^backend_weight/", $key)) { + || preg_match("/^backend_weight/", $key) + || preg_match("/^backend_data_directory/", $key)) { for($i=0; $i < count($value); $i++) { if($value[$i] == TRUE) { $isError = TRUE; @@ -373,7 +393,8 @@ function writeConfigFile($configValue, $pgpoolConfigParam) $key = trim($key); if(!preg_match("/^backend_hostname/", $key) && !preg_match("/^backend_port/", $key) - && !preg_match("/^backend_weight/", $key) ) { + && !preg_match("/^backend_weight/", $key) + && !preg_match("/^backend_data_directory/", $key)) { $removeBackendConfigFile[] = $line; } } else { @@ -417,6 +438,9 @@ function writeConfigFile($configValue, $pgpoolConfigParam) $line = "backend_weight$i = " . $configValue['backend_weight'][$i] . "\n"; $configFile[] = $line; + + $line = "backend_data_directory$i = '" . $configValue['backend_data_directory'][$i] . "'\n"; + $configFile[] = $line; } } @@ -443,6 +467,9 @@ function deleteBackendHost($num, &$configValue) unset($configValue['backend_weight'][$num]); $configValue['backend_weight'] = array_values($configValue['backend_weight']); + + unset($configValue['backend_data_directory'][$num]); + $configValue['backend_data_directory'] = array_values($configValue['backend_data_directory']); } diff --git a/status.php b/status.php index 837ec98..4cb971b 100644 --- a/status.php +++ b/status.php @@ -201,6 +201,17 @@ switch ($action) { } break; + case 'recovery': + $ret = execPcp('PCP_RECOVERY_NODE', $nodeNumber); + if(!array_key_exists('SUCCESS', $ret)) { + $errorCode = 'e1012'; + $tpl->assign('errorCode', $errorCode); + $tpl->display('error.tpl'); + exit(); + } + break; + + case 'detach': $ret = execPcp('PCP_DETACH_NODE', $nodeNumber); if(!array_key_exists('SUCCESS', $ret)) { diff --git a/templates/nodeStatus.tpl b/templates/nodeStatus.tpl index 2390dc8..b3126c4 100644 --- a/templates/nodeStatus.tpl +++ b/templates/nodeStatus.tpl @@ -43,6 +43,8 @@ {elseif $nodeInfo[num][4] == 'return'} + {elseif $nodeInfo[num][4] == 'recovery'} + {/if} diff --git a/templates/pgconfig.tpl b/templates/pgconfig.tpl index 04a0c3a..08d8b00 100644 --- a/templates/pgconfig.tpl +++ b/templates/pgconfig.tpl @@ -72,6 +72,7 @@ function cancelNode() {
  • Logging
  • Replication
  • Health Check
  • +
  • Online Recovery
  • System Database
  • Others
  • @@ -249,6 +250,15 @@ function cancelNode() { {/if} + {if $error.backend_data_directory[num] != null} + +
    backend_data_directory{$smarty.section.num.index|escape} (string) + {else} + +
    backend_data_directory{$smarty.section.num.index|escape} (string) + {/if} + + {/section} {if $isAdd == true} @@ -463,6 +473,40 @@ function cancelNode() { +

    Online Recovery

    + + + + + + + + + + + + + + {if $error.recovery_user != null} + + {else} + + {/if} + + + {if $error.recovery_password != null} + + {else} + + {/if} + + + +
    {$message.strParameter|escape}{$message.strValue|escape}
    +
    health_check_timeout (integer)
    +
    health_check_timeout (integer)
    +
    recovery_password (string)
    +
    recovery_password (string)

    System Database

    -- 2.39.5