이 장에서는 DSDL과 함께 구현되는 샘플 자원 유형 SUNW.xfnts에 대해 설명합니다. 데이터 서비스는 C로 작성되며 기본 응용 프로그램은 TCP/IP 기반 서비스인 X Font Server입니다.
X Font Server는 클라이언트에 글꼴 파일을 제공하는 간단한 TCP/IP 기반 서비스입니다. 클라이언트는 글꼴 집합을 요청하기 위해 서버에 연결하며 서버는 디스크에서 글꼴 파일을 읽어 클라이언트에 제공합니다. X Font Server 데몬은 서버 이진 /usr/openwin/bin/xfs로 구성됩니다. 데몬은 대개 inetd에서 시작됩니다. 그러나 현재 샘플의 경우 /etc/inetd.conf 파일에서 해당 항목이 fsadmin -d 명령 등에 의해 비활성화되어 데몬이 Sun Cluster의 제어만을 받는 것으로 가정합니다.
기본적으로 X Font Server는 /usr/openwin/lib/X11/fontserver.cfg 파일에서 구성 정보를 읽습니다. 이 파일의 카탈로그 항목에는 데몬에서 제공할 수 있는 글꼴 디렉토리 목록이 포함되어 있습니다. 클러스터 관리자는 전역 파일 시스템에서 글꼴 디렉토리를 찾아 시스템에서 글꼴 데이터베이스의 단일 복사본을 유지 관리함으로써 Sun Cluster에서의 X Font Server 사용을 최적화할 수 있습니다. 이러한 경우에 관리자는 fontserver.cfg를 편집하여 글꼴 데이터베이스의 새 경로를 반영해야 합니다.
관리자는 또한 구성이 용이하도록 구성 파일 자체를 전역 파일 시스템에 둘 수 있습니다. xfs 데몬은 이 파일의 기본 제공 위치를 무시하는 명령줄 인자를 제공합니다. SUNW.xfnts 자원 유형은 다음 명령을 사용하여 Sun Cluster 제어 하에서 데몬을 시작합니다.
/usr/openwin/bin/xfs -config <location_of_cfg_file>/fontserver.cfg \ -port <portnumber> |
SUNW.xfnts 자원 유형 구현에서 Confdir_list 등록 정보를 사용하여 fontserver.cfg 구성 파일의 위치를 관리할 수 있습니다.
xfs server 데몬이 수신하는 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 등록 정보에 대한 다른 값을 지정하여 다른 포트를 지정할 수 있는 옵션이 있습니다.
다음 규칙을 염두에 두고 다양한 샘플 코드를 식별할 수 있습니다.
RMAPI 함수는 scha_로 시작합니다.
DSDL 함수는 scds_로 시작합니다.
콜백 메소드는 xfnts_로 시작합니다.
사용자가 작성한 함수는 svc_로 시작합니다.
이 절에서는 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 = AT_CREATION;
}
이 등록 정보에서 기본값을 선언하므로 클러스터 관리자는 자원을 만들 때 새 값을 지정할지 아니면 기본값을 그대로 사용할지 선택할 수 있습니다. 조정 기능이 AT_CREATION으로 제한되므로 이 값을 나중에 변경할 수 없습니다.
DSDL은 각 콜백 메소드가 메소드의 시작 부분에서 scds_initialize(3HA) 함수를 호출할 것을 요구합니다. 이 함수는 다음 작업을 수행합니다.
해당 프레임워크에서 데이터 서비스 메소드로 전달되는 명령줄 인자(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) 설명서 페이지 참조).
X Font Server의 시작을 시도하기 전에 xfnts_start 메소드는 다음과 같이 svc_validate()를 호출하여 xfs 데몬을 지원하기 위한 적절한 구성이 있는지 확인합니다(자세한 내용은 xfnts_validate 메소드 참조).
rc = svc_validate(scds_handle);
if (rc != 0) {
scds_syslog(LOG_ERR,
"Failed to validate configuration.");
return (rc);
}
xfnts_start 메소드는 xfnts.c에 정의된 svc_start() 메소드를 호출하여 xfs 데몬을 시작합니다. 이 절에서는 svc_start()에 대해 설명합니다.
xfs 데몬을 시작하기 위한 명령은 다음과 같습니다.
xfs -config config_directory/fontserver.cfg -port port_number |
Confdir_list 확장 등록 정보는 config_directory를 식별하며 Port_list 시스템 등록 정보는 port_number를 식별합니다. 클러스터 관리자는 데이터 서비스를 구성할 때 이러한 등록 정보에 대한 특정 값을 제공합니다.
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() 메소드는 다음과 같이 xfnts.c에 정의된 svc_wait()를 호출하여 응용 프로그램이 실행 중인지 확인합니다.
/* 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(3HA)를 호출합니다.
/* 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 값의 3%에 해당하는 시간 초과값을 전달합니다. 그런 다음 svc_wait()는 svc_probe()를 호출하여 응용 프로그램이 시작되었는지 확인합니다. svc_probe() 메소드는 지정된 포트에서 서버에 대한 간단한 소켓 연결을 설정합니다. 포트에 연결하는 데 실패할 경우 svc_probe()는 완전한 실패를 나타내는 값 100을 반환합니다. 연결이 설정되었지만 포트에 대한 연결을 끊는 데 실패한 경우 svc_probe()는 값 50을 반환합니다.
svc_probe()의 실패 또는 부분 실패 시 svc_wait()는 시간 초과값이 5인 scds_svc_wait()를 호출합니다. scds_svc_wait() 메소드는 검사 빈도를 5초 간격으로 제한합니다. 또한 이 메소드는 서비스 시작을 시도한 횟수를 계산합니다. 시도 횟수가 자원의 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 메소드는 다음과 같이 xfnts.c에 정의된 svc_stop() 메소드를 호출합니다.
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 메소드는 다음과 같이 xfnts.c에 정의된 mon_start 메소드를 호출합니다.
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은 자식 모니터 수준을 지정하며 이 경우에는 모니터 데몬만 모니터합니다.
종료하기 전에 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() 메소드는 다음과 같이 xfnts.c에 정의된 mon_stop 메소드를 호출합니다.
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 오류 모니터는 다음 작업을 수행합니다.
xfs와 같은 간단한 TCP 기반 서비스를 검사하도록 특수하게 설계된 유틸리티를 사용하여 xfs 서버 데몬의 상태를 정기적으로 모니터합니다.
Retry_count 및 Retry_interval 등록 정보를 사용하여 시간 창 내에서 응용 프로그램에 발생하는 문제를 추적하고 완전한 응용 프로그램 실패가 발생할 경우 데이터 서비스를 다시 시작할지 아니면 페일오버할지 결정합니다. scds_fm_action() 및 scds_fm_sleep() 함수는 이 추적 및 결정 기법을 기본적으로 지원합니다.
scds_fm_action()을 사용하여 페일오버 또는 재시작 결정을 구현합니다.
자원 상태를 업데이트하여 관리 도구 및 그래픽 사용자 인터페이스에서 사용할 수 있게 만듭니다.
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() 함수는 검사 논리를 구현합니다. scds_fm_action()에 svc_probe()의 반환값이 전달됩니다. 여기에서 응용 프로그램을 다시 시작할지, 자원 그룹을 페일오버할지, 아니면 아무 작업도 수행하지 않을지가 결정됩니다.
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()은 데이터 서비스를 다시 시작합니다.
자원이 만들어질 때와 관리 작업에 의해 자원이나 자원을 포함한 그룹의 등록 정보가 업데이트될 때 RGM은 Validate 메소드를 호출합니다. RGM은 작성 또는 업데이트가 적용되기 전에 Validate를 호출하며 임의의 노드에서 이 메소드가 실패 종료 코드를 반환할 경우 작성 또는 업데이트가 취소됩니다.
RGM에서 등록 정보를 설정하거나 모니터가 Status 및 Status_msg 자원 등록 정보를 설정할 때가 아니라 관리 작업을 통해 자원 또는 그룹 등록 정보가 변경될 경우에만 RGM은 Validate를 호출합니다.
Monitor_check 메소드는 또한 PROBE 메소드가 데이터 서비스를 새 노드로 페일오버하려고 시도할 때마다 Validate 메소드를 명시적으로 호출합니다.
RGM은 업데이트할 등록 정보 및 값을 비롯하여 다른 메소드에 전달되는 항목에 대한 추가 인자와 함께 Validate를 호출합니다. xfnts_validate의 시작 부분에서 scds_initialize() 호출은 RGM이 xfnts_validate에 전달한 모든 인자를 구문 분석하고 scds_handle 매개 변수에 정보를 저장합니다. 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은 오류 모니터의 인스턴스가 하나만 있다는 것을 나타냅니다.