リソースがノード上で起動したあと、RGM は、PROBE メソッドを直接呼び出すのではなく、Monitor_start メソッドを呼び出してモニターを起動します。xfnts_monitor_start メソッドは PMF の制御下で障害モニターを起動します。xfnts_monitor_stop メソッドは障害モニターを停止します。
SUNW.xfnts 障害モニターは、次の処理を実行します。
単純な TCP ベースのサービス (xfs など) を検査するために特別に設計されたユーティリティーを使用して、定期的に xfs サーバーデーモンの状態を監視します。
(Retry_count と Retry_interval プロパティーを使用して) ある期間内にアプリケーションが遭遇した問題を追跡し、アプリケーションが完全に失敗した場合に、データサービスを再起動するか、フェイルオーバーするかどうかを決定します。scds_fm_action() と scds_fm_sleep() 関数は、この追跡および決定機構の組み込みサポートを提供します。
scds_fm_action() を使用して、フェイルオーバーまたは再起動の決定を実装します。
リソースの状態を更新して、管理ツールや GUI で利用できるようにします。
xfonts_probe メソッドはループを実装します。ループを実装する前に、xfonts_probe は次の処理を行います。
次に示すように、xfnts リソース用のネットワークアドレスリソースを取得します。
/* 当該リソース用に利用できる IP アドレスを取得する。 */ if (scds_get_netaddr_list(scds_handle, &netaddr)) { scds_syslog(LOG_ERR, "No network address resource in resource group."); scds_close(&scds_handle); return (1); } /* ネットワークリソースが存在しない場合、エラーを戻す。 */ if (netaddr == NULL || netaddr->num_netaddrs == 0) { scds_syslog(LOG_ERR, "No network address resource in resource group."); return (1); }
scds_fm_sleep() を呼び出し、タイムアウト値として Thorough_probe_interval の値を渡します。次に示すように、検証を実行する間、検証機能は Thorough_probe_interval で指定された期間、休眠状態になります。
timeout = scds_get_ext_probe_timeout(scds_handle); for (;;) { /* * 連続する検証の間、thorough_probe_interval で指定された期間、 * 休眠状態になる。 */ (void) scds_fm_sleep(scds_handle, scds_get_rs_thorough_probe_interval(scds_handle));
xfnts_probe メソッドは次のようなループを実装します。
for (ip = 0; ip < netaddr->num_netaddrs; ip++) { /* * 状態を監視するホスト名と * ポートを取得する。 */ hostname = netaddr->netaddrs[ip].hostname; port = netaddr->netaddrs[ip].port_proto.port; /* * HA-XFS がサポートするポートは 1 つだけなので、 * ポート値はポートの配列の最初の * エントリから取得する。 */ ht1 = gethrtime(); /* 検証開始時間を取得する。 */ scds_syslog(LOG_INFO, "Probing the service on port: %d.", port); probe_result = svc_probe(scds_handle, hostname, port, timeout); /* * サービス検証履歴を更新し、 * 必要に応じて、アクションを行う。 * 検証終了時間を取得する。 */ ht2 = gethrtime(); /* ミリ秒に変換する。 */ dt = (ulong_t)((ht2 - ht1) / 1e6); /* * 障害の履歴を計算し、必要に応じて * アクションを実行する。 */ (void) scds_fm_action(scds_handle, probe_result, (long)dt); } /* ネットワークリソースごとに */ } /* 検証を永続的に繰り返す。 */
svc_probe() 関数は検証ロジックを実装します。svc_probe() からの戻り値は scds_fm_action() に渡されます。そして scds_fm_action() は、アプリケーションを再起動するか、リソースグループをフェイルオーバーするか、あるいは何もしないかを決定します。
svc_probe() 関数は、scds_fm_tcp_connect() を呼び出すことによって、指定されたポートとの単純ソケット接続を確立します。接続に失敗した場合、svc_probe() は 100 の値を戻して、致命的な障害であることを示します。接続には成功したが、切断に失敗した場合、svc_probe() は 50 の値を戻して、部分的な障害であることを示します。接続と切断の両方に成功した場合、svc_probe() は 0 の値を戻して、成功したことを示します。
次に、svc_probe() のコードを示します。
int svc_probe(scds_handle_t scds_handle, char *hostname, int port, int timeout) { int rc; hrtime_t t1, t2; int sock; char testcmd[2048]; int time_used, time_remaining; time_t connect_timeout; /* * probe the data service by doing a socket connection to the port * specified in the port_list property to the host that is * serving the XFS data service. If the XFS service which is configured * to listen on the specified port, replies to the connection, then * the probe is successful. Else we will wait for a time period set * in probe_timeout property before concluding that the probe failed. */ /* * Use the SVC_CONNECT_TIMEOUT_PCT percentage of timeout * to connect to the port */ connect_timeout = (SVC_CONNECT_TIMEOUT_PCT * timeout)/100; t1 = (hrtime_t)(gethrtime()/1E9); /* * the probe makes a connection to the specified hostname and port. * The connection is timed for 95% of the actual probe_timeout. */ rc = scds_fm_tcp_connect(scds_handle, &sock, hostname, port, connect_timeout); if (rc) { scds_syslog(LOG_ERR, "Failed to connect to port <%d> of resource <%s>.", port, scds_get_resource_name(scds_handle)); /* this is a complete failure */ return (SCDS_PROBE_COMPLETE_FAILURE); } t2 = (hrtime_t)(gethrtime()/1E9); /* * Compute the actual time it took to connect. This should be less than * or equal to connect_timeout, the time allocated to connect. * If the connect uses all the time that is allocated for it, * then the remaining value from the probe_timeout that is passed to * this function will be used as disconnect timeout. Otherwise, the * the remaining time from the connect call will also be added to * the disconnect timeout. * */ time_used = (int)(t2 - t1); /* * Use the remaining time(timeout - time_took_to_connect) to disconnect */ time_remaining = timeout - (int)time_used; /* * If all the time is used up, use a small hardcoded timeout * to still try to disconnect. This will avoid the fd leak. */ if (time_remaining <= 0) { scds_syslog_debug(DBG_LEVEL_LOW, "svc_probe used entire timeout of " "%d seconds during connect operation and exceeded the " "timeout by %d seconds. Attempting disconnect with timeout" " %d ", connect_timeout, abs(time_used), SVC_DISCONNECT_TIMEOUT_SECONDS); time_remaining = SVC_DISCONNECT_TIMEOUT_SECONDS; } /* * Return partial failure in case of disconnection failure. * Reason: The connect call is successful, which means * the application is alive. A disconnection failure * could happen due to a hung application or heavy load. * If it is the later case, don't declare the application * as dead by returning complete failure. Instead, declare * it as partial failure. If this situation persists, the * disconnect call will fail again and the application will be * restarted. */ rc = scds_fm_tcp_disconnect(scds_handle, sock, time_remaining); if (rc != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, "Failed to disconnect to port %d of resource %s.", port, scds_get_resource_name(scds_handle)); /* this is a partial failure */ return (SCDS_PROBE_COMPLETE_FAILURE/2); } t2 = (hrtime_t)(gethrtime()/1E9); time_used = (int)(t2 - t1); time_remaining = timeout - time_used; /* * If there is no time left, don't do the full test with * fsinfo. Return SCDS_PROBE_COMPLETE_FAILURE/2 * instead. This will make sure that if this timeout * persists, server will be restarted. */ if (time_remaining <= 0) { scds_syslog(LOG_ERR, "Probe timed out."); return (SCDS_PROBE_COMPLETE_FAILURE/2); } /* * The connection and disconnection to port is successful, * Run the fsinfo command to perform a full check of * server health. * Redirect stdout, otherwise the output from fsinfo * ends up on the console. */ (void) sprintf(testcmd, "/usr/openwin/bin/fsinfo -server %s:%d > /dev/null", hostname, port); scds_syslog_debug(DBG_LEVEL_HIGH, "Checking the server status with %s.", testcmd); if (scds_timerun(scds_handle, testcmd, time_remaining, SIGKILL, &rc) != SCHA_ERR_NOERR || rc != 0) { scds_syslog(LOG_ERR, "Failed to check server status with command <%s>", testcmd); return (SCDS_PROBE_COMPLETE_FAILURE/2); } return (0); }
svc_probe() は終了時に、成功 (0)、部分的な障害 (50)、または致命的な障害 (100) を示す値を戻します。xfnts_probe メソッドはこの値を scds_fm_action() に渡します。
xfnts_probe メソッドは scds_fm_action() を呼び出して、行うべきアクションを決定します。scds_fm_action() のロジックは次のとおりです。
Retry_interval プロパティーの値の期間中に、障害の履歴を累積します。
累積した障害が 100 に到達した場合 (完全な障害)、データサービスを再起動します。Retry_interval を超えた場合、障害の履歴をリセットします。
Retry_interval で指定された期間中に、再起動の回数が Retry_count プロパティーを上回った場合、データサービスをフェイルオーバーします。
たとえば、検証機能が xfs サーバーに正常に接続したが、切断に失敗したものと想定します。これは、サーバーは動作しているが、ハングしていたり、一時的に過負荷状態になっている可能性を示しています。切断に失敗すると、scds_fm_action() に部分的な障害 (50) が送信されます。この値は、データサービスを再起動するしきい値を下回っていますが、値は障害の履歴に記録されます。
次回の検証でもサーバーが切断に失敗した場合、scds_fm_action() が保持している障害の履歴に値 50 が再度追加されます。累積した障害の履歴が 100 になるので、scds_fm_action() はデータサービスを再起動します。