本章說明使用資料服務開發程式庫 (DSDL) 實作的範例資源類型 SUNW.xfnts。此資料服務以 C 寫入。基礎應用程式是 X 字型伺服器,一種基於 TCP/IP 的服務。附錄 CDSDL 資源類型程式碼清單範例包含 SUNW.xfnts 資源類型中每種方法的完整程式碼。
本章涵蓋下列主題:
X 字型伺服器是基於 TCP/IP 的服務,為其用戶端提供字型檔案服務。用戶端連接至伺服器要求字型集,伺服器便從磁碟中讀取字型檔案,然後將其提供給用戶端。X 字型伺服器常駐程式由 /usr/openwin/bin/xfs 中的伺服器二進位檔組成。通常,常駐程式從 inetd 啟動。然而,對於目前的範例,假定 /etc/inetd.conf 檔案中的正確項目已停用 (例如,透過使用 fsadmin-d 指令),從而使常駐程式在 Sun Cluster 軟體的唯一控制下。
依預設,X 字型伺服器從檔案 /usr/openwin/lib/X11/fontserver.cfg 中讀取其配置資訊。此檔案中的目錄項目包含字型目錄清單,這些字型目錄可用於常駐程式以用於提供服務。叢集管理員可以在叢集檔案系統中尋找字型目錄。此位置透過維護系統上字型資料庫的單一副本來最佳化 Sun Cluster 上 X 字型伺服器的使用。如果叢集管理員想要變更位置,必須將 fontserver.cfg 編輯為反映字型目錄的新路徑。
為了便於配置,叢集管理員也可將配置檔案本身置於叢集檔案系統中。xfs 常駐程式提供覆寫此檔案的預設內建位置的指令行引數。SUNW.xfnts 資源類型使用以下指令啟動在 Sun Cluster 軟體控制下的常駐程式。
/usr/openwin/bin/xfs -config location-of-configuration-file/fontserver.cfg \ -port port-number
在 SUNW.xfnts 資源類型實作中,您可以使用 Confdir_list 特性管理 fontserver.cfg 配置檔案的位置。
xfs 伺服器常駐程式偵聽的 TCP 連接埠號碼通常為 “fs” 連接埠,在 /etc/services 檔案中定義為 7100。然而,叢集管理員使用 xfs 指令包含的 -port 選項可讓叢集管理員覆寫預設設定。
您可以使用 SUNW.xfnts 資源類型中的 Port_list 特性來設定預設值並讓叢集管理員使用 xfs 指令以使用 -port 選項。在 RTR 檔案中,此特性的預設值定義為 7100/tcp。在 SUNW.xfnts Start 方法中,您可將 Port_list 傳送至 xfs 指令行上的 -port 選項。因此,此資源類型的使用者不需要指定連接埠號碼 (連接埠預設為 7100/tcp)。當叢集管理員配置資源類型時,可為 Port_list 特性指定一個其他值。
本小節說明 SUNW.xfnts RTR 檔案中的數個關鍵特性。此節未說明該檔案中每個特性的用途。如需相關說明,請參閱設定資源特性和資源類型特性。
Confdir_list 延伸特性可識別配置目錄 (或目錄清單),如下所示︰
{
PROPERTY = Confdir_list;
EXTENSION;
STRINGARRAY;
TUNABLE = AT_CREATION;
DESCRIPTION = "The Configuration Directory Path(s)";
}
Confdir_list 特性不指定預設值。建立資源時,叢集管理員必須指定一個目錄名稱。由於可調性限制為 AT_CREATION,因此,無法在之後變更此值。
Port_list 特性可識別伺服器常駐程式偵聽的連接埠,如下所示︰
{
PROPERTY = Port_list;
DEFAULT = 7100/tcp;
TUNABLE = ANYTIME;
}
由於特性宣告了預設值,因此,在建立資源時,叢集管理員可指定一個新值或接受預設值。由於可調性限制為 AT_CREATION,因此,任何人均無法在之後變更此值。
RMAPI 函數以 scha_ 開始。
DSDL 函數以 scds_ 開始。
回呼方法以 xfnts_ 開始。
使用者寫入的函數以 svc_ 開始。
DSDL 要求在方法開始時每個回呼方法均呼叫 scds_initialize() 函數。此函數執行下列作業︰
檢查並處理架構傳送至資料服務方法的指令行引數 (argc 和 argv)。此方法無需處理任何附加指令行引數。
設定內部資料結構,以供 DSDL 中的其他函數使用。
初始化記錄環境。
驗證故障監視器的探測設定。
使用 scds_close() 函數收回由 scds_initialize() 配置的資源。
當包含資料服務資源的資源群組在節點上處於線上狀態時,或當啟用資源時,RGM 將在該叢集節點上執行 Start 方法。在 SUNW.xfnts 資源類型範例中,xfnts_start 方法將在該節點上啟動 xfs 常駐程式。
xfnts_start 方法呼叫 scds_pmf_start() 以啟動 PMF 下的常駐程式。PMF 將提供自動的失敗通知和重新啟動功能,以及與故障監視器整合。
xfnts_start 中的第一個呼叫是呼叫 scds_initialize(),其可執行某些必需的事務性工作函數。scds_initialize() 函數和 scds_initialize(3HA) 線上手冊包含更多資訊。
在 xfnts_start 方法嘗試啟動 X 字型伺服器之前,該方法將呼叫 svc_validate() 以確定正確的配置位於適當的位置以支援 xfs 常駐程式。
rc = svc_validate(scds_handle);
if (rc != 0) {
scds_syslog(LOG_ERR,
"Failed to validate configuration.");
return (rc);
}
請參閱xfnts_validate 方法,以取得詳細資訊。
xfnts_start 方法將呼叫 svc_start() 方法 (在 xfnts.c 檔案中定義) 以啟動 xfs 常駐程式。本節說明 svc_start()。
用於啟動 xfs 常駐程式的指令如下所示︰
# xfs -config config-directory/fontserver.cfg -port port-number |
Confdir_list 延伸特性識別 config-directory 時,Port_list 系統特性識別 port-number。當叢集管理員配置資料服務時,將為這些特性提供特定值。
xfnts_start 方法宣告這些特性為字串陣列。xfnts_start 方法透過使用 scds_get_ext_confdir_list() 和 scds_get_port_list() 函數取得叢集管理員設定的值。 這些函數在 scds_property_functions(3HA) 線上手冊中說明。
scha_str_array_t *confdirs;
scds_port_list_t *portlist;
scha_err_t err;
/* get the configuration directory from the confdir_list property */
confdirs = scds_get_ext_confdir_list(scds_handle);
(void) sprintf(xfnts_conf, "%s/fontserver.cfg", confdirs->str_array[0]);
/* obtain the port to be used by XFS from the Port_list property */
err = scds_get_port_list(scds_handle, &portlist);
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Could not access property Port_list.");
return (1);
}
請注意,confdirs 變數指向陣列的第一個元素 (0)。
xfnts_start 方法使用 sprintf() 以形成 xfs 的指令行。
/* Construct the command to start the xfs daemon. */
(void) sprintf(cmd,
"/usr/openwin/bin/xfs -config %s -port %d 2>/dev/null",
xfnts_conf, portlist->ports[0].port);
請注意,輸出重新導向至 /dev/null 以抑制由常駐程式產生的訊息。
xfnts_start 方法將 xfs 指令行傳送至 scds_pmf_start() 以啟動在 PMF 控制下的資料服務。
scds_syslog(LOG_INFO, "Issuing a start request.");
err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_SVC,
SCDS_PMF_SINGLE_INSTANCE, cmd, -1);
if (err == SCHA_ERR_NOERR) {
scds_syslog(LOG_INFO,
"Start command completed successfully.");
} else {
scds_syslog(LOG_ERR,
"Failed to start HA-XFS ");
}
請注意以下有關對 scds_pmf_start() 呼叫的幾點內容︰
SCDS_PMF_TYPE_SVC 引數將要啟動的程式識別為資料服務應用程式。此方法也可啟動故障監視器或某些其他應用程式類型。
SCDS_PMF_SINGLE_INSTANCE 引數將其識別為單一實例資源。
cmd 引數為之前產生的指令行。
最終引數 -1,指定子監視層級。-1 值指定 PMF 監視所有子程序和原始程序。
傳回之前,svc_pmf_start() 將釋放為 portlist 結構配置的記憶體。
scds_free_port_list(portlist); return (err);
即使 svc_start() 成功傳回,基礎應用程式可能也會無法啟動。因此,svc_start() 必須探測應用程式,以驗證該應用程式在傳回成功訊息之前已在執行。探測必須考慮到,由於應用程式需要花費一些時間來啟動,因此其不會立即可用。svc_start() 方法呼叫 svc_wait() (在 xfnts.c 檔案中定義) 以確定應用程式正在執行。
/* Wait for the service to start up fully */
scds_syslog_debug(DBG_LEVEL_HIGH,
"Calling svc_wait to verify that service has started.");
rc = svc_wait(scds_handle);
scds_syslog_debug(DBG_LEVEL_HIGH,
"Returned from svc_wait");
if (rc == 0) {
scds_syslog(LOG_INFO, "Successfully started the service.");
} else {
scds_syslog(LOG_ERR, "Failed to start the service.");
}
svc_wait() 函數呼叫 scds_get_netaddr_list() 以取得探測應用程式所需的網路位址資源。
/* obtain the network resource to use for probing */
if (scds_get_netaddr_list(scds_handle, &netaddr)) {
scds_syslog(LOG_ERR,
"No network address resources found in resource group.");
return (1);
}
/* Return an error if there are no network resources */
if (netaddr == NULL || netaddr->num_netaddrs == 0) {
scds_syslog(LOG_ERR,
"No network address resource in resource group.");
return (1);
}
svc_wait() 函數取得 Start_timeout 和 Stop_timeout 值。
svc_start_timeout = scds_get_rs_start_timeout(scds_handle) probe_timeout = scds_get_ext_probe_timeout(scds_handle)
若要計算伺服器用來啟動的時間,svc_wait() 將呼叫 scds_svc_wait(),並傳送一個相當於 Start_timeout 值百分之三的逾時值。svc_wait() 函數呼叫 svc_probe() 函數以驗證應用程式已啟動。svc_probe() 方法在指定通訊埠上建立與伺服器的簡單套接字連接。如果無法連接至連接埠,svc_probe() 將傳回一個為 100 的值,表示完全失敗。如果連接成功,但無法中斷與連接埠的連接,則 svc_probe() 將傳回一個為 50 的值。
svc_probe() 失敗或部分失敗時,svc_wait() 將以逾時值 5 呼叫 scds_svc_wait()。scds_svc_wait() 方法會將探測頻率限定為每五秒一次。此方法也將計算嘗試啟動服務的次數。如果嘗試的次數超出此期間 (由資源的 Retry_interval 特性指定) 內資源的 Retry_count 特性的值,則 scds_svc_wait() 函數傳回失敗。在此情況下,svc_start() 函數也將傳回故障。
#define SVC_CONNECT_TIMEOUT_PCT 95
#define SVC_WAIT_PCT 3
if (scds_svc_wait(scds_handle, (svc_start_timeout * SVC_WAIT_PCT)/100)
!= SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR, "Service failed to start.");
return (1);
}
do {
/*
* probe the data service on the IP address of the
* network resource and the portname
*/
rc = svc_probe(scds_handle,
netaddr->netaddrs[0].hostname,
netaddr->netaddrs[0].port_proto.port, probe_timeout);
if (rc == SCHA_ERR_NOERR) {
/* Success. Free up resources and return */
scds_free_netaddr_list(netaddr);
return (0);
}
/* Call scds_svc_wait() so that if service fails too
if (scds_svc_wait(scds_handle, SVC_WAIT_TIME)
!= SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR, "Service failed to start.");
return (1);
}
/* Rely on RGM to timeout and terminate the program */
} while (1);
結束之前,xfnts_start 方法將呼叫 scds_close(),以收回由 scds_initialize() 配置的資源。scds_initialize() 函數 和 scds_close(3HA) 線上手冊包含更多資訊。
由於 xfnts_start 方法使用 scds_pmf_start() 來啟動 PMF 下的服務,因此 xfnts_stop 將使用 scds_pmf_stop() 來停止服務。
xfnts_stop 中的第一個呼叫是呼叫 scds_initialize(),其可執行某些必需的事務性工作函數。scds_initialize() 函數和 scds_initialize(3HA) 線上手冊包含更多資訊。
xfnts_stop 方法呼叫 svc_stop() 方法 (在 xfnts.c 檔案中定義),如下所示︰
scds_syslog(LOG_ERR, "Issuing a stop request.");
err = scds_pmf_stop(scds_handle,
SCDS_PMF_TYPE_SVC, SCDS_PMF_SINGLE_INSTANCE, SIGTERM,
scds_get_rs_stop_timeout(scds_handle));
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to stop HA-XFS.");
return (1);
}
scds_syslog(LOG_INFO,
"Successfully stopped HA-XFS.");
return (SCHA_ERR_NOERR); /* Successfully stopped */
請注意以下關於 svc_stop() 中對 scds_pmf_stop() 函數呼叫的幾點內容︰
SCDS_PMF_TYPE_SVC 引數將要停止的程式識別為資料服務應用程式。此方法也可停止故障監視器或某些其他應用程式類型。
SCDS_PMF_SINGLE_INSTANCE 引數識別訊號。
SIGTERM 引數識別要用來停止資源實例的訊號。如果此訊號無法停止實例,scds_pmf_stop() 將發送 SIGKILL 來停止該實例,如果失敗,它將傳回逾時錯誤。請參閱 scds_pmf_stop(3HA) 線上手冊,以取得詳細資訊。
逾時值為資源之 Stop_timeout 特性的值。
結束之前,xfnts_stop 方法將呼叫 scds_close(),以收回由 scds_initialize() 配置的資源。scds_initialize() 函數 和 scds_close(3HA) 線上手冊包含更多資訊。
在資源於節點上啟動之後,RGM 將在節點上呼叫 Monitor_start 方法以啟動故障監視器。xfnts_monitor_start 方法使用 scds_pmf_start() 以啟動 PMF 下的監視器常駐程式。
xfnts_monitor_start 中的第一個呼叫是呼叫 scds_initialize(),其可執行某些必需的事務性工作函數。scds_initialize() 函數和 scds_initialize(3HA) 線上手冊包含更多資訊。
xfnts_monitor_start 方法將呼叫 mon_start 方法 (在 xfnts.c 檔案中定義),如下所示︰
scds_syslog_debug(DBG_LEVEL_HIGH,
"Calling Monitor_start method for resource <%s>.",
scds_get_resource_name(scds_handle));
/* Call scds_pmf_start and pass the name of the probe. */
err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_MON,
SCDS_PMF_SINGLE_INSTANCE, "xfnts_probe", 0);
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to start fault monitor.");
return (1);
}
scds_syslog(LOG_INFO,
"Started the fault monitor.");
return (SCHA_ERR_NOERR); /* Successfully started Monitor */
}
請注意以下關於 svc_mon_start() 中對 scds_pmf_start() 函數呼叫的幾點內容︰
SCDS_PMF_TYPE_MON 引數將要啟動的程式識別為故障監視器。此方法也可啟動資料服務或某些其他應用程式類型。
SCDS_PMF_SINGLE_INSTANCE 引數將其識別為單一實例資源。
xfnts_probe 引數識別要啟動的監視器常駐程式。假定監視器常駐程式位於與其他回呼程式相同的目錄中。
最終引數 0,指定子監視層級。在此類情況下,此值將指定 PMF 僅監視監視器常駐程式。
結束之前,xfnts_monitor_start 方法將呼叫 scds_close(),以收回由 scds_initialize() 配置的資源。scds_initialize() 函數 和 scds_close(3HA) 線上手冊包含更多資訊。
由於 xfnts_monitor_start 方法使用 scds_pmf_start() 來啟動 PMF 下的監視器常駐程式,因此,xfnts_monitor_stop 將使用 scds_pmf_stop() 來停止監視器常駐程式。
xfnts_monitor_stop 中的第一個呼叫是呼叫 scds_initialize(),其可執行某些必需的事務性工作函數。scds_initialize() 函數和 scds_initialize(3HA) 線上手冊包含更多資訊。
xfnts_monitor_stop() 方法呼叫 mon_stop 方法 (在 xfnts.c 檔案中定義),如下所示︰
scds_syslog_debug(DBG_LEVEL_HIGH,
"Calling scds_pmf_stop method");
err = scds_pmf_stop(scds_handle, SCDS_PMF_TYPE_MON,
SCDS_PMF_SINGLE_INSTANCE, SIGKILL,
scds_get_rs_monitor_stop_timeout(scds_handle));
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to stop fault monitor.");
return (1);
}
scds_syslog(LOG_INFO,
"Stopped the fault monitor.");
return (SCHA_ERR_NOERR); /* Successfully stopped monitor */
}
請注意以下關於 svc_mon_stop() 中對 scds_pmf_stop() 函數呼叫的幾點內容︰
SCDS_PMF_TYPE_MON 引數將要停止的程式識別為故障監視器。此方法也可停止資料服務或某些其他應用程式類型。
SCDS_PMF_SINGLE_INSTANCE 引數將其識別為單一實例資源。
SIGKILL 引數識別要用來停止資源實例的訊號。如果此訊號無法停止實例,scds_pmf_stop() 將傳回逾時錯誤。請參閱 scds_pmf_stop(3HA) 線上手冊,以取得詳細資訊。
逾時值即為資源的 Monitor_stop_timeout 特性。
結束之前,xfnts_monitor_stop 方法將呼叫 scds_close(),以收回由 scds_initialize() 配置的資源。scds_initialize() 函數 和 scds_close(3HA) 線上手冊包含更多資訊。
每當故障監視器嘗試將包含資源的資源群組容錯移轉至其他節點時,RGM 將呼叫 Monitor_check 方法。 xfnts_monitor_check 方法將呼叫 svc_validate() 方法以驗證正確的配置位於適當的位置以支援 xfs 常駐程式。請參閱xfnts_validate 方法,以取得詳細資訊。xfnts_monitor_check 的程式碼如下所示︰
/* Process the arguments passed by RGM and initialize syslog */
if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR)
{
scds_syslog(LOG_ERR, "Failed to initialize the handle.");
return (1);
}
rc = svc_validate(scds_handle);
scds_syslog_debug(DBG_LEVEL_HIGH,
"monitor_check method "
"was called and returned <%d>.", rc);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of validate method run as part of monitor check */
return (rc);
}
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 資源的網路位址資源,如下所示︰
/* Get the ip addresses available for this resource */
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);
}
/* Return an error if there are no network resources */
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 (;;) {
/*
* sleep for a duration of thorough_probe_interval between
* successive probes.
*/
(void) scds_fm_sleep(scds_handle,
scds_get_rs_thorough_probe_interval(scds_handle));
xfnts_probe 方法將實作以下迴路︰
for (ip = 0; ip < netaddr->num_netaddrs; ip++) {
/*
* Grab the hostname and port on which the
* health has to be monitored.
*/
hostname = netaddr->netaddrs[ip].hostname;
port = netaddr->netaddrs[ip].port_proto.port;
/*
* HA-XFS supports only one port and
* hence obtain the port value from the
* first entry in the array of ports.
*/
ht1 = gethrtime(); /* Latch probe start time */
scds_syslog(LOG_INFO, "Probing the service on port: %d.", port);
probe_result =
svc_probe(scds_handle, hostname, port, timeout);
/*
* Update service probe history,
* take action if necessary.
* Latch probe end time.
*/
ht2 = gethrtime();
/* Convert to milliseconds */
dt = (ulong_t)((ht2 - ht1) / 1e6);
/*
* Compute failure history and take
* action if needed
*/
(void) scds_fm_action(scds_handle,
probe_result, (long)dt);
} /* Each net resource */
} /* Keep probing forever */
svc_probe() 函數實施探測邏輯。svc_probe() 的傳回值傳送至 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_count 特性的值,則在 Retry_interval 指定的時間內容錯移轉資料服務。
例如,假定探測可以連接至 xfs 伺服器,但無法中斷連接。這指示該伺服器正在執行,但可能掛起或恰好在進行暫時載入。中斷連接失敗會將部分失敗 (50) 傳送至 scds_fm_action()。此值低於重新啟動資料服務的臨界值,但該值保留在故障歷史中。
如果在下一個探測期間,伺服器中斷連接再次失敗,則一個為 50 的值會增加至 scds_fm_action() 保持的失敗歷程記錄中。現在,累計的失敗值為 100,因此,scds_fm_action() 將重新啟動資料服務。
當建立資源時並且當叢集管理員更新資源的特性或其包含的群組時,RGM 將呼叫 Validate 方法。在套用建立或更新之前,RGM 將呼叫 Validate,並且此方法在任何節點上的故障結束碼均將導致取消建立或取消更新。
僅當叢集管理員變更資源或資源群組特性時,或當監視器設定 Status 和 Status_msg 資源特性時,RGM 才呼叫 Validate。當 RGM 設定特性時,RGM 不呼叫 Validate。
每當 PROBE 方法嘗試容錯移轉資料服務至新節點時,Monitor_check 方法也將明確地呼叫 Validate 方法。
RGM 使用附加引數對傳送至其他方法的引數 (包含正在更新的特性和值) 呼叫 Validate。在 xfnts_validate 開始時對 scds_handle 的呼叫剖析 RGM 傳送至 xfnts_validate 的所有引數並將資訊儲存在 scds_initialize() 中。xfnts_validate 呼叫的子常式使用此資訊。
xfnts_validate 方法呼叫 svc_validate(),以驗證以下情況︰
已經為資源設定了 Confdir_list 特性,該特性定義單一目錄。
scha_str_array_t *confdirs;
confdirs = scds_get_ext_confdir_list(scds_handle);
/* Return error if there is no confdir_list extension property */
if (confdirs == NULL || confdirs->array_cnt != 1) {
scds_syslog(LOG_ERR,
"Property Confdir_list is not set properly.");
return (1); /* Validation failure */
}
Confdir_list 指定的目錄包含 fontserver.cfg 檔案。
(void) sprintf(xfnts_conf, "%s/fontserver.cfg", confdirs->str_array[0]);
if (stat(xfnts_conf, &statbuf) != 0) {
/*
* suppress lint error because errno.h prototype
* is missing void arg
*/
scds_syslog(LOG_ERR,
"Failed to access file <%s> : <%s>",
xfnts_conf, strerror(errno)); /*lint !e746 */
return (1);
}
在叢集節點上可以存取伺服器常駐程式二進位檔。
if (stat("/usr/openwin/bin/xfs", &statbuf) != 0) {
scds_syslog(LOG_ERR,
"Cannot access XFS binary : <%s> ", strerror(errno));
return (1);
}
Port_list 特性指定單一連接埠。
scds_port_list_t *portlist;
err = scds_get_port_list(scds_handle, &portlist);
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Could not access property Port_list: %s.",
scds_error_string(err));
return (1); /* Validation Failure */
}
#ifdef TEST
if (portlist->num_ports != 1) {
scds_syslog(LOG_ERR,
"Property Port_list must have only one value.");
scds_free_port_list(portlist);
return (1); /* Validation Failure */
}
#endif
包含資料服務的資源群組也包含至少一個網路位址資源。
scds_net_resource_list_t *snrlp;
if ((err = scds_get_rs_hostnames(scds_handle, &snrlp))
!= SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"No network address resource in resource group: %s.",
scds_error_string(err));
return (1); /* Validation Failure */
}
/* Return an error if there are no network address resources */
if (snrlp == NULL || snrlp->num_netresources == 0) {
scds_syslog(LOG_ERR,
"No network address resource in resource group.");
rc = 1;
goto finished;
}
在傳回之前,svc_validate() 將釋放所有分配的資源。
finished: scds_free_net_list(snrlp); scds_free_port_list(portlist); return (rc); /* return result of validation */
結束之前,xfnts_validate 方法將呼叫 scds_close(),以收回由 scds_initialize() 配置的資源。scds_initialize() 函數 和 scds_close(3HA) 線上手冊包含更多資訊。
RGM 呼叫 Update 方法以通知正在執行的資源其特性已變更。可以為 xfnts 資料服務變更的唯一特性關係到故障監視器。因此,每當更新特性時,xfnts_update 方法將呼叫 scds_pmf_restart_fm() 以啟動故障監視器。
/* check if the Fault monitor is already running and if so stop
* and restart it. The second parameter to scds_pmf_restart_fm()
* uniquely identifies the instance of the fault monitor that needs
* to be restarted.
*/
scds_syslog(LOG_INFO, "Restarting the fault monitor.");
result = scds_pmf_restart_fm(scds_handle, 0);
if (result != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to restart fault monitor.");
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
return (1);
}
scds_syslog(LOG_INFO,
"Completed successfully.");
如果有多個實例,scds_pmf_restart_fm() 的第二個引數會將故障監視器的實例唯一識別為將要重新啟動。範例中的值 0 表示僅有一個故障監視器的實例。