pgpool2.git / summary / log / commit / refs

commit    07c767dc0dd71d959efd97772ccc07b4f40a81e0
Author:   Muhammad Usama <m.usama@gmail.com>
Date:     Mon Dec 07 15:22:06 2015 +0000

    code cleanup for watchdog.


doc/pgpool-en.html | 3 +- src/include/watchdog/watchdog.h | 25 +- src/include/watchdog/wd_ipc_commands.h | 2 +- src/include/watchdog/wd_ipc_defines.h | 18 +- src/main/pgpool_main.c | 2 +- src/tools/pcp/pcp_frontend_client.c | 4 +- src/watchdog/watchdog.c | 228 +------------------ src/watchdog/wd_commands.c | 132 +++++------ src/watchdog/wd_escalation.c | 44 ++-- src/watchdog/wd_interlock.c | 150 ------------ src/watchdog/wd_lifecheck.c | 15 +- src/watchdog/wd_list.c | 403 --------------------------------- src/watchdog/wd_ping.c | 1 - 13 files changed, 113 insertions(+), 914 deletions(-) diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html index b3d9a16c9..7ffa1d086 100644 --- a/doc/pgpool-en.html +++ b/doc/pgpool-en.html @@ -4534,12 +4534,11 @@ string and the socket file is placed in the pgpool-II <a href="#WD_IPC_SOCKET_DI <h3 id="Watchdog_IPC_command_packet_format">Watchdog IPC command packet format</h3> <dl> <p> -The watchdog IPC command packet consists of four fields. Below table details the message fields and description +The watchdog IPC command packet consists of three fields. Below table details the message fields and description </p> <table border> <tr class="header"><th>Field</th> <th>Type</th> <th>Description</th></tr> <tr><th>TYPE</th> <td>BYTE1</td> <td>Command Type</td></tr> - <tr><th>ACTION</th> <td>INT32 Network byte order</td> <td>Command Action. Currently only DEFAULT(0) is supported</td></tr> <tr><th>LENGTH</th> <td>INT32 Network byte order</td> <td>The length of data to follow</td></tr> <tr><th>DATA</th> <td>DATA in JSON format</td> <td>Command data in JSON format</td></tr> </table> diff --git a/src/include/watchdog/watchdog.h b/src/include/watchdog/watchdog.h index bf0169f77..0132d31ac 100644 --- a/src/include/watchdog/watchdog.h +++ b/src/include/watchdog/watchdog.h @@ -87,32 +87,27 @@ typedef enum { typedef struct SocketConnection { - int sock; - struct timeval tv; - char addr[48]; - WD_SOCK_STATE sock_state; + int sock; /* socket descriptor */ + struct timeval tv; /* connect time of socket */ + char addr[48]; /* ip address of socket connection*/ + WD_SOCK_STATE sock_state; /* current state of socket */ }SocketConnection; typedef struct WatchdogNode { WD_STATES state; struct timeval tv; /* startup time value */ - char nodeName[WD_MAX_HOST_NAMELEN]; + char nodeName[WD_MAX_HOST_NAMELEN]; /* name of this node */ char hostname[WD_MAX_HOST_NAMELEN]; /* host name */ int wd_port; /* watchdog port */ int pgpool_port; /* pgpool port */ int wd_priority; /* watchdog priority */ char delegate_ip[WD_MAX_HOST_NAMELEN]; /* delegate IP */ - char** resolved_ips; - int delegate_ip_flag; /* delegate IP flag */ - unsigned int lastCommandID; - struct timeval hb_last_recv_time; /* recv time */ - int private_id; - SocketConnection server_socket; - SocketConnection client_socket; - bool is_connectable; /* true if any of the socket is connected */ - bool is_lock_holder; /* lock holder flag */ - bool in_interlocking; /* interlocking is in progress */ + int private_id; /* ID assigned to this node + * This id is consumed locally + */ + SocketConnection server_socket; /* socket connections for this node initiated by remote */ + SocketConnection client_socket; /* socket connections for this node initiated by local*/ }WatchdogNode; extern pid_t initialize_watchdog(void); diff --git a/src/include/watchdog/wd_ipc_commands.h b/src/include/watchdog/wd_ipc_commands.h index f71bc1980..2e969c30e 100644 --- a/src/include/watchdog/wd_ipc_commands.h +++ b/src/include/watchdog/wd_ipc_commands.h @@ -64,7 +64,7 @@ extern WDFailoverCMDResults wd_send_failover_sync_command(WDFailoverCMDTypes cmd extern char* wd_get_watchdog_nodes(int nodeID); -extern WDIPCCmdResult* issue_command_to_watchdog(char type, WD_COMMAND_ACTIONS command_action,int timeout_sec, char* data, int data_len, bool blocking); +extern WDIPCCmdResult* issue_command_to_watchdog(char type, int timeout_sec, char* data, int data_len, bool blocking); /* wd_interlock.c */ diff --git a/src/include/watchdog/wd_ipc_defines.h b/src/include/watchdog/wd_ipc_defines.h index 4b7b12d42..2c3c6b661 100644 --- a/src/include/watchdog/wd_ipc_defines.h +++ b/src/include/watchdog/wd_ipc_defines.h @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2012 PgPool Global Development Group + * Copyright (c) 2003-2015 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -42,13 +42,6 @@ typedef enum WDFailoverCMDResults FAILOVER_RES_BLOCKED }WDFailoverCMDResults; -typedef enum { - WD_COMMAND_ACTION_DEFAULT = 0, - WD_COMMAND_ACTION_SEND_ALL, - WD_COMMAND_ACTION_SEND_MASTER, - WD_COMMAND_ACTION_LOCAL -} WD_COMMAND_ACTIONS; - /* IPC MESSAGES TYPES */ #define WD_REGISTER_FOR_NOTIFICATION '0' @@ -56,12 +49,9 @@ typedef enum { #define WD_GET_NODES_LIST_COMMAND '3' #define WD_NODES_LIST_DATA '4' -#define WD_TRY_COMMAND_LOCK '5' -#define WD_COMMAND_UNLOCK '6' - -#define WD_IPC_CMD_CLUSTER_IN_TRAN '7' -#define WD_IPC_CMD_RESULT_BAD '8' -#define WD_IPC_CMD_RESULT_OK '9' +#define WD_IPC_CMD_CLUSTER_IN_TRAN '5' +#define WD_IPC_CMD_RESULT_BAD '6' +#define WD_IPC_CMD_RESULT_OK '7' #define WD_FUNCTION_COMMAND 'f' #define WD_FAILOVER_CMD_SYNC_REQUEST 's' diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index ea766034f..6dbe16119 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -395,7 +395,7 @@ int PgpoolMain(bool discard_status, bool clear_memcache_oidmaps) if (ret > 0) /* Retries are exhausted, reset the counter */ { retrycnt = 0; - if (ret == 2) + if (ret == 2) /* 2 = failover done on node */ { health_check_node_id = 0; use_template_db = false; diff --git a/src/tools/pcp/pcp_frontend_client.c b/src/tools/pcp/pcp_frontend_client.c index a4ee713bf..018c80bfc 100644 --- a/src/tools/pcp/pcp_frontend_client.c +++ b/src/tools/pcp/pcp_frontend_client.c @@ -218,7 +218,7 @@ main(int argc, char **argv) { if (nodeID < 0) { - fprintf(stderr, "%s: Invalid watchdog-id \"%s\", must be a positive number\n",progname,optarg); + fprintf(stderr, "%s: Invalid watchdog-id \"%s\", must be a positive number or zero for a local watchdog node\n",progname,optarg); exit(0); } } @@ -287,7 +287,7 @@ main(int argc, char **argv) nodeID = atoi(argv[optind]); if (nodeID < 0 ) { - fprintf(stderr, "%s: Invalid watchdog-id \"%s\", must be a positive number\n",progname,optarg); + fprintf(stderr, "%s: Invalid watchdog-id \"%s\", must be a positive number or zero for local watchdog node\n",progname,optarg); exit(0); } } diff --git a/src/watchdog/watchdog.c b/src/watchdog/watchdog.c index 6fe57b00d..9492dfc12 100644 --- a/src/watchdog/watchdog.c +++ b/src/watchdog/watchdog.c @@ -131,7 +131,7 @@ char *wd_event_name[] = "NODE CONNECTION FOUND" }; -char *debug_states[] = { +char *wd_state_names[] = { "DEAD", "LOADING", "JOINING", @@ -175,7 +175,6 @@ typedef struct WDCommandNodeResult typedef struct WDIPCCommandData { - WD_COMMAND_ACTIONS command_action; MemoryContext memoryContext; int issueing_sock; char type; @@ -267,9 +266,6 @@ typedef struct wd_cluster List *wd_timer_commands; }wd_cluster; -int *escalation_status = NULL; /* Lives in shared memory */ - - volatile sig_atomic_t reload_config_signal = 0; static void check_config_reload(void); @@ -365,9 +361,7 @@ static WDIPCCommandData* get_wd_IPC_command_from_socket(int sock); static IPC_CMD_PREOCESS_RES process_IPC_command(WDIPCCommandData* IPCCommand); static IPC_CMD_PREOCESS_RES process_IPC_nodeStatusChange_command(WDIPCCommandData* IPCCommand); -static IPC_CMD_PREOCESS_RES process_IPC_lock_request(WDIPCCommandData *IPCCommand); static IPC_CMD_PREOCESS_RES process_IPC_nodeList_command(WDIPCCommandData* IPCCommand); -static IPC_CMD_PREOCESS_RES process_IPC_unlock_request(WDIPCCommandData *IPCCommand); static IPC_CMD_PREOCESS_RES process_IPC_replicate_variable(WDIPCCommandData* IPCCommand); static IPC_CMD_PREOCESS_RES process_IPC_failover_cmd_synchronise(WDIPCCommandData *IPCCommand); static IPC_CMD_PREOCESS_RES execute_replicate_command(WDIPCCommandData* ipcCommand); @@ -491,9 +485,6 @@ static void wd_cluster_initialize(void) (errmsg("watchdog remote node:%d on %s:%d",i,g_cluster.remoteNodes[i].hostname, g_cluster.remoteNodes[i].wd_port))); } - escalation_status = pool_shared_memory_create(sizeof(int)); - *escalation_status = 0; - g_cluster.masterNode = NULL; g_cluster.aliveNodeCount = 0; g_cluster.quorum_status = -1; @@ -1338,7 +1329,6 @@ static bool write_ipc_command_with_result_data(WDIPCCommandData* IPCCommand, cha static bool read_ipc_command_and_process(int sock, bool *remove_socket) { char type; - WD_COMMAND_ACTIONS command_action; IPC_CMD_PREOCESS_RES res; int data_len,ret; WDIPCCommandData* IPCCommand = NULL; @@ -1357,16 +1347,7 @@ static bool read_ipc_command_and_process(int sock, bool *remove_socket) errdetail("read from socket failed with error \"%s\"",strerror(errno)))); return false; } - /* Next is is command action */ - ret = socket_read(sock, &command_action, sizeof(int),0); - if (ret != sizeof(int)) - { - ereport(WARNING, - (errmsg("error reading from IPC socket"), - errdetail("read from socket failed with error \"%s\"",strerror(errno)))); - return false; - } - command_action = htonl(command_action); + /* We should have data length */ ret = socket_read(sock, &data_len, sizeof(int),0); if (ret != sizeof(int)) @@ -1390,7 +1371,6 @@ static bool read_ipc_command_and_process(int sock, bool *remove_socket) IPCCommand = palloc0(sizeof(WDIPCCommandData)); IPCCommand->issueing_sock = sock; - IPCCommand->command_action = command_action; IPCCommand->type = type; gettimeofday(&IPCCommand->issue_time, NULL); @@ -1446,14 +1426,6 @@ static IPC_CMD_PREOCESS_RES process_IPC_command(WDIPCCommandData* IPCCommand) return process_IPC_nodeStatusChange_command(IPCCommand); break; - case WD_TRY_COMMAND_LOCK: - return process_IPC_lock_request(IPCCommand); - break; - - case WD_COMMAND_UNLOCK: - process_IPC_unlock_request(IPCCommand); - break; - case WD_REGISTER_FOR_NOTIFICATION: /* Add this socket to the notify socket list*/ g_cluster.notify_clients = lappend_int(g_cluster.notify_clients, IPCCommand->issueing_sock); @@ -1576,7 +1548,7 @@ static bool fire_node_status_event(int nodeID, int nodeStatus) if (nodeStatus == WD_LIFECHECK_NODE_STATUS_DEAD) { ereport(DEBUG1, - (errmsg("Firing NODE STATUS EVENT: NODE(ID=%d) IS DEAD",nodeID))); + (errmsg("firing NODE STATUS EVENT: NODE(ID=%d) IS DEAD",nodeID))); if (wdNode == g_cluster.localNode) watchdog_state_machine(WD_EVENT_LOCAL_NODE_LOST, wdNode, NULL); @@ -1586,7 +1558,7 @@ static bool fire_node_status_event(int nodeID, int nodeStatus) else if (nodeStatus == WD_LIFECHECK_NODE_STATUS_ALIVE) { ereport(DEBUG1, - (errmsg("Firing NODE STATUS EVENT: NODE(ID=%d) IS ALIVE",nodeID))); + (errmsg("firing NODE STATUS EVENT: NODE(ID=%d) IS ALIVE",nodeID))); if (wdNode == g_cluster.localNode) watchdog_state_machine(WD_EVENT_LOCAL_NODE_FOUND, wdNode, NULL); @@ -1644,169 +1616,6 @@ static IPC_CMD_PREOCESS_RES process_IPC_replicate_variable(WDIPCCommandData* IPC return IPC_CMD_ERROR; } -static IPC_CMD_PREOCESS_RES process_IPC_unlock_request(WDIPCCommandData *IPCCommand) -{ - IPC_CMD_PREOCESS_RES ret = IPC_CMD_COMPLETE; - char res_type = WD_IPC_CMD_RESULT_OK; - /* - * if cluster or myself is not in stable state - * just return cluster in transaction - */ - IPCCommand->type = WD_INTERUNLOCKING_REQUEST; - - if (g_cluster.lockHolderNode == NULL) - { - /* There is no lock holder as per our records - * just ignore this request - */ - res_type = WD_IPC_CMD_RESULT_OK; - } - else if(g_cluster.lockHolderNode != g_cluster.localNode) - { - /* I am not the lockhoder node, so How can I unlock - * just return the error - */ - ret = WD_IPC_CMD_RESULT_BAD; - } - else if (get_local_node_state() == WD_STANDBY) - { - /* I am a standby node, and also the lock holder - * Just forward the request to coordinator */ - - WDPacketData *wdPacket = get_minimum_message(WD_INTERUNLOCKING_REQUEST,NULL); - /* save the command ID */ - IPCCommand->internal_command_id = wdPacket->command_id; - - if (send_message(g_cluster.masterNode, wdPacket) <= 0) - { - /* we have failed to send to master node, return lock failed */ - res_type = WD_IPC_CMD_RESULT_BAD; - } - else - { - /* - * we need to wait for the results from master/coordinator node - * do not reply back to ipc until we hear from master node - */ - - ret = IPC_CMD_PROCESSING; - } - /* whatever the case we need to resign ourself from lock - * holder - */ - pfree(wdPacket); - g_cluster.lockHolderNode = NULL; - } - else if (get_local_node_state() == WD_COORDINATOR) - { - /* - * If I am coordinator, Just process the request locally - */ - if (node_has_resigned_from_interlocking(g_cluster.localNode, NULL)) - { - res_type = WD_IPC_CMD_RESULT_OK; - } - else - { - res_type = WD_IPC_CMD_RESULT_BAD; - } - } - else /* we are not in any stable state at the moment */ - { - g_cluster.lockHolderNode = NULL; - res_type = WD_IPC_CMD_CLUSTER_IN_TRAN; - } - - if (ret == IPC_CMD_PROCESSING) - { - /* Do not reply back to requester, as we are - * still processing the results - */ - return ret; - } - if (write_ipc_command_with_result_data(IPCCommand, res_type, NULL, 0)) - { - /* - * This is the complete lifecycle of command. - * we are done with it - */ - ret = IPC_CMD_COMPLETE; - } - else - ret = IPC_CMD_ERROR; - - return ret; -} - - -static IPC_CMD_PREOCESS_RES process_IPC_lock_request(WDIPCCommandData *IPCCommand) -{ - char res_type = WD_IPC_CMD_RESULT_BAD; - /* - * if cluster or myself is not in stable state - * just return cluster in transaction - */ - ereport(LOG, - (errmsg("processing lock request from IPC socket"))); - - IPCCommand->type = WD_INTERLOCKING_REQUEST; - - if (get_local_node_state() == WD_STANDBY) - { - - /* I am a standby node, Just forward the request to coordinator */ - WDPacketData * wdPacket = get_minimum_message(WD_INTERLOCKING_REQUEST,NULL); - /* save the command ID */ - IPCCommand->internal_command_id = wdPacket->command_id; - - if (send_message(g_cluster.masterNode, wdPacket) <= 0) - { - ereport(LOG, - (errmsg("failed to process lock request from IPC socket"), - errdetail("failed to forward the request to master watchdog node \"%s\"",g_cluster.masterNode->nodeName))); - - /* we have failed to send to any node, return lock failed */ - res_type = WD_IPC_CMD_RESULT_BAD; - } - else - { - /* - * we need to wait for the result - */ - ereport(LOG, - (errmsg("lock request from IPC socket is forwarded to master watchdog node \"%s\"",g_cluster.masterNode->nodeName), - errdetail("waiting for the reply from master node..."))); - - return IPC_CMD_PROCESSING; - } - } - else if (get_local_node_state() == WD_COORDINATOR) - { - /* - * If I am coordinator, Just process the request locally - */ - if (node_has_requested_for_interlocking(g_cluster.localNode, NULL)) - { - res_type = WD_IPC_CMD_RESULT_OK; - } - else - res_type = WD_IPC_CMD_RESULT_BAD; - } - else /* we are not in any stable state at the moment */ - { - res_type = WD_IPC_CMD_CLUSTER_IN_TRAN; - } - - if (write_ipc_command_with_result_data(IPCCommand, res_type, NULL, 0)) - { - /* - * This is the complete lifecycle of command. - * we are done with it - */ - return IPC_CMD_COMPLETE; - } - return IPC_CMD_ERROR; -} static IPC_CMD_PREOCESS_RES process_IPC_failover_cmd_synchronise(WDIPCCommandData *IPCCommand) { @@ -2315,6 +2124,9 @@ static void wd_system_will_go_down(int code, Datum arg) close_socket_connection(&wdNode->client_socket); close_socket_connection(&wdNode->server_socket); } + /* close network monitoring socket */ + if (g_cluster.network_monitor_sock > 0) + close(g_cluster.network_monitor_sock); } static void close_socket_connection(SocketConnection* conn) @@ -3180,24 +2992,6 @@ static int update_connected_node_count(void) return g_cluster.aliveNodeCount; } -static void update_nodes_connection_status(void) -{ - int i; - for (i = 0; i< g_cluster.remoteNodeCount; i++) - { - bool conectable = false; - WatchdogNode* wdNode = &(g_cluster.remoteNodes[i]); - if (is_socket_connection_connected(&wdNode->client_socket)) - conectable = true; - else if (is_socket_connection_connected(&wdNode->server_socket)) - conectable = true; - if (wdNode->is_connectable && conectable) /* new and old status is same */ - continue; - wdNode->is_connectable = conectable; - watchdog_state_machine(wdNode->is_connectable?WD_EVENT_NODE_CON_FOUND:WD_EVENT_NODE_CON_LOST, wdNode, NULL); - } -} - static bool service_lost_connections(void) { @@ -3448,7 +3242,7 @@ static void cluster_in_stable_state(void) static int watchdog_state_machine(WD_EVENTS event, WatchdogNode* wdNode, WDPacketData* pkt) { ereport(DEBUG1, - (errmsg("STATE MACHINE INVOKED WITH EVENT = %s Current State = %s",wd_event_name[event], debug_states[get_local_node_state()]))); + (errmsg("STATE MACHINE INVOKED WITH EVENT = %s Current State = %s",wd_event_name[event], wd_state_names[get_local_node_state()]))); if (event == WD_EVENT_REMOTE_NODE_LOST) { @@ -4554,7 +4348,7 @@ static int set_state(WD_STATES newState) if (oldState != newState) { ereport(LOG, - (errmsg("watchdog node state changed from [%s] to [%s]",debug_states[oldState],debug_states[newState]))); + (errmsg("watchdog node state changed from [%s] to [%s]",wd_state_names[oldState],wd_state_names[newState]))); watchdog_state_machine(WD_EVENT_WD_STATE_CHANGED, NULL, NULL); /* send out the info message to all nodes */ send_message_of_type(NULL, WD_INFO_MESSAGE); @@ -5102,7 +4896,7 @@ static void print_watchdog_node_info(WatchdogNode* wdNode) { ereport(DEBUG2, (errmsg("state: \"%s\" Host: \"%s\" Name: \"%s\" WD Port:%d PP Port: %d priority:%d", - debug_states[wdNode->state], + wd_state_names[wdNode->state], wdNode->hostname ,wdNode->nodeName ,wdNode->wd_port @@ -5129,5 +4923,5 @@ static void print_received_packet_info(WDPacketData* pkt,WatchdogNode* wdNode) (errmsg("watchdog packet received from node \"%s\"",wdNode->nodeName), errdetail("command id : %d Type: %s my watchdog state :%s",pkt->command_id, pkt_type?pkt_type->name:"UNKNOWN", - debug_states[get_local_node_state()]))); + wd_state_names[get_local_node_state()]))); } diff --git a/src/watchdog/wd_commands.c b/src/watchdog/wd_commands.c index 0097afa01..87c1ba4d0 100644 --- a/src/watchdog/wd_commands.c +++ b/src/watchdog/wd_commands.c @@ -20,7 +20,6 @@ * is" without express or implied warranty. * */ -#include <pthread.h> #include <stdio.h> #include <errno.h> #include <ctype.h> @@ -50,6 +49,7 @@ #include "watchdog/wd_ipc_commands.h" #include "watchdog/wd_ipc_defines.h" +#define WD_DEFAULT_IPC_COMMAND_TIMEOUT 5 /* default number of seconds to wait for IPC command results*/ #define WD_INTERLOCK_WAIT_MSEC 500 #define WD_INTERLOCK_TIMEOUT_SEC 10 #define WD_INTERLOCK_WAIT_COUNT ((int) ((WD_INTERLOCK_TIMEOUT_SEC * 1000)/WD_INTERLOCK_WAIT_MSEC)) @@ -93,7 +93,7 @@ void wd_ipc_initialize_data(void) pool_config->wd_ipc_socket_dir, pool_config->wd_port); - watchdog_ipc_address = pool_shared_memory_create(strlen(wd_ipc_sock_addr)); + watchdog_ipc_address = pool_shared_memory_create(strlen(wd_ipc_sock_addr) +1); strcpy(watchdog_ipc_address, wd_ipc_sock_addr); } } @@ -103,38 +103,42 @@ char* get_watchdog_ipc_address(void) return watchdog_ipc_address; } +/* + * function issues the command to watchdog process over the watchdog + * IPC command socket. + * type: command type to send. valid command + * types are defined in wd_ipc_defines.h + * timeout_sec: number of seconds to wait for the command response + * from watchdog + * data: command data + * data_len: length of data + * blocking: send true if caller wants to wait for the results + * when blocking is false the timeout_sec is ignored + */ WDIPCCmdResult* -issue_command_to_watchdog(char type, WD_COMMAND_ACTIONS command_action,int timeout_sec, char* data, int data_len, bool blocking) +issue_command_to_watchdog(char type, int timeout_sec, char* data, int data_len, bool blocking) { struct timeval start_time,tv; int sock; WDIPCCmdResult* result = NULL; char res_type = 'P'; - int res_length, action; + int res_length, len; gettimeofday(&start_time, NULL); - + /* open the watchdog command socket for IPC */ sock = open_wd_command_sock(false); if (sock < 0) return NULL; - res_length = htonl(data_len); - action = htonl(command_action); + len = htonl(data_len); if (socket_write(sock, &type, sizeof(char)) <= 0) { close(sock); return NULL; } - - - if (socket_write(sock, &action, sizeof(int)) <= 0) - { - close(sock); - return NULL; - } - if (socket_write(sock, &res_length, sizeof(int)) <= 0) + if (socket_write(sock, &len, sizeof(int)) <= 0) { close(sock); return NULL; @@ -169,7 +173,7 @@ issue_command_to_watchdog(char type, WD_COMMAND_ACTIONS command_action,int timeo /* read the result type char */ if (socket_read(sock, &res_type, 1 ,0) <=0) { - ereport(LOG, + ereport(WARNING, (errmsg("error reading from IPC command socket"), errdetail("read from socket failed with error \"%s\"",strerror(errno)))); close(sock); @@ -178,7 +182,7 @@ issue_command_to_watchdog(char type, WD_COMMAND_ACTIONS command_action,int timeo /* read the result data length */ if (socket_read(sock, &res_length, sizeof(int), 0) <= 0) { - ereport(LOG, + ereport(WARNING, (errmsg("error reading from IPC command socket"), errdetail("read from socket failed with error \"%s\"",strerror(errno)))); close(sock); @@ -227,12 +231,14 @@ wd_start_recovery(void) char type; char* func = get_wd_node_function_json(WD_FUNCTION_START_RECOVERY, NULL,0); - WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, WD_COMMAND_ACTION_DEFAULT,pool_config->recovery_timeout, func, strlen(func), true); + WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, + pool_config->recovery_timeout, + func, strlen(func), true); pfree(func); if (result == NULL) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("issue command to watchdog returned NULL"))); return COMMAND_FAILED; @@ -242,7 +248,7 @@ wd_start_recovery(void) pfree(result); if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); @@ -260,12 +266,14 @@ wd_end_recovery(void) char type; char* func = get_wd_node_function_json(WD_FUNCTION_END_RECOVERY, NULL, 0); - WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, WD_COMMAND_ACTION_DEFAULT,2, func, strlen(func), true); + WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, + WD_DEFAULT_IPC_COMMAND_TIMEOUT, + func, strlen(func), true); pfree(func); if (result == NULL) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("issue command to watchdog returned NULL"))); return COMMAND_FAILED; @@ -275,7 +283,7 @@ wd_end_recovery(void) pfree(result); if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); @@ -301,12 +309,14 @@ wd_send_failback_request(int node_id) return COMMAND_OK; func = get_wd_node_function_json(WD_FUNCTION_FAILBACK_REQUEST,&n, 1); - WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, WD_COMMAND_ACTION_DEFAULT,2, func, strlen(func), true); + WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, + WD_DEFAULT_IPC_COMMAND_TIMEOUT, + func, strlen(func), true); pfree(func); if (result == NULL) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("issue command to watchdog returned NULL"))); return COMMAND_FAILED; @@ -316,7 +326,7 @@ wd_send_failback_request(int node_id) pfree(result); if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); @@ -351,13 +361,15 @@ wd_send_failover_sync_command(WDFailoverCMDTypes cmdType, char* syncReqType) char* json_data = get_wd_failover_cmd_type_json(cmdType, syncReqType); - WDIPCCmdResult *result = issue_command_to_watchdog(WD_FAILOVER_CMD_SYNC_REQUEST, WD_COMMAND_ACTION_DEFAULT,pool_config->recovery_timeout, json_data, strlen(json_data), true); + WDIPCCmdResult *result = issue_command_to_watchdog(WD_FAILOVER_CMD_SYNC_REQUEST + ,pool_config->recovery_timeout, + json_data, strlen(json_data), true); pfree(json_data); if (result == NULL || result->length <= 0) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("issue command to watchdog returned NULL"))); return FAILOVER_RES_ERROR; @@ -393,44 +405,6 @@ wd_send_failover_sync_command(WDFailoverCMDTypes cmdType, char* syncReqType) return interlockingResult; } -WdCommandResult -wd_try_command_lock(void) -{ - WDIPCCmdResult* result; - char type; - - result = issue_command_to_watchdog(WD_TRY_COMMAND_LOCK, WD_COMMAND_ACTION_DEFAULT,10, NULL, 0, true); - if (result == NULL) - { - ereport(LOG, - (errmsg("watchdog command lock failed"), - errdetail("issue command to watchdog returned NULL"))); - return COMMAND_FAILED; - } - - type = result->type; - pfree(result); - if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) - { - ereport(LOG, - (errmsg("watchdog command lock failed"), - errdetail("watchdog cluster is not in stable state"), - errhint("try again when the cluster is fully initialized"))); - return CLUSTER_IN_TRANSATIONING; - } - - if (type == WD_IPC_CMD_RESULT_OK) - return COMMAND_OK; - - return COMMAND_FAILED; -} - -void wd_command_unlock(void) -{ - /* we dont really care about results here */ - issue_command_to_watchdog(WD_COMMAND_UNLOCK, WD_COMMAND_ACTION_DEFAULT,10, NULL, 0, false); -} - WdCommandResult wd_degenerate_backend_set(int *node_id_set, int count) { @@ -443,13 +417,15 @@ wd_degenerate_backend_set(int *node_id_set, int count) return COMMAND_OK; func = get_wd_node_function_json(WD_FUNCTION_DEGENERATE_REQUEST,node_id_set, count); - WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, WD_COMMAND_ACTION_DEFAULT,2, func, strlen(func), true); + WDIPCCmdResult *result = issue_command_to_watchdog(WD_FUNCTION_COMMAND , + WD_DEFAULT_IPC_COMMAND_TIMEOUT, + func, strlen(func), true); pfree(func); if (result == NULL) { - ereport(LOG, - (errmsg("degenerate backend set command failed"), + ereport(WARNING, + (errmsg("degenerate backend set command failed"), errdetail("issue command to watchdog returned NULL"))); return COMMAND_FAILED; } @@ -458,7 +434,7 @@ wd_degenerate_backend_set(int *node_id_set, int count) pfree(result); if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("degenerate backend set command failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); @@ -483,12 +459,14 @@ wd_promote_backend(int node_id) return COMMAND_OK; func = get_wd_node_function_json(WD_FUNCTION_PROMOTE_REQUEST,&n, 1); - result = issue_command_to_watchdog(WD_FUNCTION_COMMAND, WD_COMMAND_ACTION_DEFAULT,2, func, strlen(func), true); + result = issue_command_to_watchdog(WD_FUNCTION_COMMAND , + WD_DEFAULT_IPC_COMMAND_TIMEOUT, + func, strlen(func), true); pfree(func); if (result == NULL) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("issue command to watchdog returned NULL"))); return COMMAND_FAILED; @@ -498,7 +476,7 @@ wd_promote_backend(int node_id) pfree(result); if (type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("start recovery command lock failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); @@ -524,13 +502,15 @@ char* wd_get_watchdog_nodes(int nodeID) json_str = jw_get_json_string(jNode); - result = issue_command_to_watchdog(WD_GET_NODES_LIST_COMMAND, WD_COMMAND_ACTION_DEFAULT,5, json_str, strlen(json_str), true); + result = issue_command_to_watchdog(WD_GET_NODES_LIST_COMMAND + ,WD_DEFAULT_IPC_COMMAND_TIMEOUT, + json_str, strlen(json_str), true); jw_destroy(jNode); if (result == NULL) { - ereport(LOG, + ereport(WARNING, (errmsg("get watchdog nodes command failed"), errdetail("issue command to watchdog returned NULL"))); return NULL; @@ -538,7 +518,7 @@ char* wd_get_watchdog_nodes(int nodeID) if (result->type == WD_IPC_CMD_CLUSTER_IN_TRAN) { - ereport(LOG, + ereport(WARNING, (errmsg("get watchdog nodes command failed"), errdetail("watchdog cluster is not in stable state"), errhint("try again when the cluster is fully initialized"))); diff --git a/src/watchdog/wd_escalation.c b/src/watchdog/wd_escalation.c index 5c97a09fb..16349323a 100644 --- a/src/watchdog/wd_escalation.c +++ b/src/watchdog/wd_escalation.c @@ -35,7 +35,6 @@ #include "watchdog/wd_utils.h" #include "query_cache/pool_memqcache.h" -extern int *escalation_status; static void wd_exit(int exit_signo) @@ -59,8 +58,6 @@ pid_t fork_escalation_process(void) { pid_t pid; - int has_vip = 0; - pid = fork(); if (pid != 0) { @@ -85,13 +82,10 @@ fork_escalation_process(void) MemoryContextSwitchTo(TopMemoryContext); - set_ps_display("escalation",false); + set_ps_display("watchdog escalation",false); ereport(LOG, (errmsg("watchdog: escalation started"))); - - *escalation_status = 1; - /* * STEP 1 * clear shared memory cache @@ -108,7 +102,7 @@ fork_escalation_process(void) /* * STEP 2 - * execute escalation command + * execute escalation command provided by user in pgpool conf file */ if (strlen(pool_config->wd_escalation_command)) { @@ -133,17 +127,15 @@ fork_escalation_process(void) /* * STEP 3 - * interface up as delegate IP + * bring up the delegate IP */ - if (strlen(pool_config->delegate_IP) != 0) { - has_vip = wd_IP_up(); - } - - if (has_vip == WD_OK) - *escalation_status = 2; + if (wd_IP_up() != WD_OK) + ereport(WARNING, + (errmsg("watchdog de-escalation failed to bring down delegate IP"))); + } exit(0); } @@ -154,8 +146,7 @@ pid_t fork_plunging_process(void) { pid_t pid; - int has_vip = 0; - + pid = fork(); if (pid != 0) { @@ -180,16 +171,14 @@ fork_plunging_process(void) MemoryContextSwitchTo(TopMemoryContext); - set_ps_display("de-escalation",false); + set_ps_display("watchdog de-escalation",false); ereport(LOG, (errmsg("watchdog: de-escalation started"))); - *escalation_status = 1; - /* - * STEP 2 - * execute escalation command + * STEP 1 + * execute de-escalation command provided by user in pgpool conf file */ if (strlen(pool_config->wd_de_escalation_command)) { @@ -213,16 +202,15 @@ fork_plunging_process(void) } /* - * STEP 3 - * interface up as delegate IP + * STEP 2 + * bring down the delegate IP */ if (strlen(pool_config->delegate_IP) != 0) { - has_vip = wd_IP_down(); + if (wd_IP_down() != WD_OK) + ereport(WARNING, + (errmsg("watchdog de-escalation failed to bring down delegate IP"))); } - - if (has_vip == WD_OK) - *escalation_status = 2; exit(0); } diff --git a/src/watchdog/wd_interlock.c b/src/watchdog/wd_interlock.c deleted file mode 100644 index 77534b3b1..000000000 --- a/src/watchdog/wd_interlock.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * $Header$ - * - * Handles watchdog connection, and protocol communication with pgpool-II - * - * pgpool: a language independent connection pool server for PostgreSQL - * written by Tatsuo Ishii - * - * Copyright (c) 2003-2013 PgPool Global Development Group - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby - * granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission - * notice appear in supporting documentation, and that the name of the - * author not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. The author makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - */ - -/* - interlocking mechnism - - 1-) Only master can assign locks - 2-) pgpool-II Will ask watchdog to aquire lock - -- watchdog will return one of following - -- CLUSTER IN TRANSATIONING - -- LOCK AQUIRED - -- LOCK FAILED - - 3-) On receiving lock request, standby pgpool-II will forward - the lock request to master node. And wait for the reply - and return the result to caller based on reply - - 4-) on receiving lock request, master pgpool-II will replicate - check if lock holder exists, it will decline the request - and accept it otherwise. - -- Once the new lock is granted this information will be - replicated to all connected nodes. - - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/time.h> -#include <unistd.h> - -#include "pool.h" -#include "utils/elog.h" -#include "pool_config.h" -#include "watchdog/watchdog.h" -#include "watchdog/wd_ext.h" - -static volatile bool * WD_Locks; - -static void wd_update_lock_holder(void); -static int wd_assume_lock_holder(void); -static void wd_resign_lock_holder(void); -static void wd_lock_all(void); -static void wd_confirm_contactable(void); - -static void sleep_in_waiting(void); -static WDFailoverCMDResults wd_issue_failover_lock_command(WDFailoverCMDTypes cmdType, char* syncReqType); - -#define WD_INTERLOCK_WAIT_MSEC 500 -#define WD_INTERLOCK_TIMEOUT_SEC 10 -#define WD_INTERLOCK_WAIT_COUNT ((int) ((WD_INTERLOCK_TIMEOUT_SEC * 1000)/WD_INTERLOCK_WAIT_MSEC)) - - -void wd_wati_until_lock_or_timeout(WDFailoverCMDTypes cmdType) -{ - WDFailoverCMDResults res = FAILOVER_RES_TRANSITION; - int count = WD_INTERLOCK_WAIT_COUNT; - while (1) - { - res = wd_failover_command_check_lock(cmdType); - if (res == FAILOVER_RES_PROCEED_LOCK_HOLDER || - res == FAILOVER_RES_PROCEED_UNLOCKED) - { - /* we have the permision */ - return; - } - sleep_in_waiting(); - if (--count < 0) - { - ereport(WARNING, - (errmsg("timeout wating for unlock"))); - break; - } - } -} - -WDFailoverCMDResults wd_failover_command_start(WDFailoverCMDTypes cmdType) -{ - if (pool_config->use_watchdog) - return wd_issue_failover_lock_command(cmdType,"START_COMMAND"); - return FAILOVER_RES_PROCEED_LOCK_HOLDER; -} - -WDFailoverCMDResults wd_failover_command_end(WDFailoverCMDTypes cmdType) -{ - if (pool_config->use_watchdog) - return wd_issue_failover_lock_command(cmdType,"END_COMMAND"); - return FAILOVER_RES_PROCEED_LOCK_HOLDER; -} - -WDFailoverCMDResults wd_failover_command_check_lock(WDFailoverCMDTypes cmdType) -{ - if (pool_config->use_watchdog) - return wd_issue_failover_lock_command(cmdType,"CHECK_LOCKED"); - return FAILOVER_RES_PROCEED_LOCK_HOLDER; -} - -WDFailoverCMDResults wd_release_failover_command_lock(WDFailoverCMDTypes cmdType) -{ - if (pool_config->use_watchdog) - return wd_issue_failover_lock_command(cmdType,"UNLOCK_COMMAND"); - return FAILOVER_RES_PROCEED_LOCK_HOLDER; -} - -/* - * This is just a wrapper over wd_send_failover_sync_command() - * but tries to wait for WD_INTERLOCK_TIMEOUT_SEC amount of time - * if watchdog is in transition state - */ - -static WDFailoverCMDResults wd_issue_failover_lock_command(WDFailoverCMDTypes cmdType, char* syncReqType) -{ - WDFailoverCMDResults res; - int x; - for (x=0; x < MAX_SEC_WAIT_FOR_CLUSTER_TRANSATION; x++) - { - res = wd_send_failover_sync_command(NODE_FAILBACK_CMD, syncReqType); - if (res != FAILOVER_RES_TRANSITION) - break; - sleep(1); - } - return res; -} - -static void -sleep_in_waiting(void) -{ - struct timeval t = {0, WD_INTERLOCK_WAIT_MSEC * 1000}; - select(0, NULL, NULL, NULL, &t); -} diff --git a/src/watchdog/wd_lifecheck.c b/src/watchdog/wd_lifecheck.c index 7652e3bae..8d638a73b 100644 --- a/src/watchdog/wd_lifecheck.c +++ b/src/watchdog/wd_lifecheck.c @@ -48,6 +48,12 @@ #include "libpq-fe.h" +#define LIFECHECK_GETNODE_WAIT_SEC_COUNT 5 /* max number of seconds the lifecheck process + * should waits before giving up + * while fetching the configured watchdog node + * infromation from watchdog process through IPC channel + */ + /* * thread argument for lifecheck of pgpool */ @@ -312,6 +318,7 @@ static pid_t fork_lifecheck_child(void) return pid; } + /* main entry point of watchdog lifecheck process*/ static pid_t lifecheck_main(void) @@ -346,11 +353,11 @@ lifecheck_main(void) /* Get the list of watchdog node to monitor * from watchdog process */ - for (i =0; i < 5; i++) + for (i =0; i < LIFECHECK_GETNODE_WAIT_SEC_COUNT; i++) { if (fetch_watchdog_nodes_data() == true) break; - sleep(2); + sleep(1); } if (!gslifeCheckCluster) @@ -466,7 +473,7 @@ static bool inform_node_status(LifeCheckNode* node, char *message) for (x=0; x < MAX_SEC_WAIT_FOR_CLUSTER_TRANSATION; x++) { - res = issue_command_to_watchdog(WD_NODE_STATUS_CHANGE_COMMAND, WD_COMMAND_ACTION_DEFAULT,0, json_data, strlen(json_data),false); + res = issue_command_to_watchdog(WD_NODE_STATUS_CHANGE_COMMAND ,0, json_data, strlen(json_data),false); if (res) break; sleep(1); @@ -630,7 +637,7 @@ static int wd_lifecheck(void) ereport(WARNING, (errmsg("watchdog lifecheck, failed to connect to any trusted servers"))); - inform_node_status(node,"trusted server is down"); + inform_node_status(node,"trusted server is unreachable"); } return WD_NG; } diff --git a/src/watchdog/wd_list.c b/src/watchdog/wd_list.c deleted file mode 100644 index 6179a1db1..000000000 --- a/src/watchdog/wd_list.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * $Header$ - * - * Handles watchdog connection, and protocol communication with pgpool-II - * - * pgpool: a language independent connection pool server for PostgreSQL - * written by Tatsuo Ishii - * - * Copyright (c) 2003-2012 PgPool Global Development Group - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby - * granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission - * notice appear in supporting documentation, and that the name of the - * author not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. The author makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/time.h> - -#include "pool.h" -#include "utils/elog.h" -#include "pool_config.h" -#include "watchdog/watchdog.h" -#include "watchdog/wd_ext.h" - -static void wd_reset_wd_info(WdInfo *info); - -/* add or modify watchdog information list */ -int -wd_set_wd_list(char * hostname, int pgpool_port, int wd_port, char * delegate_ip, struct timeval * tv, int status) -{ - int i = 0; - WdInfo * p = NULL; - - if ((WD_List == NULL) || (hostname == NULL)) - ereport(ERROR, - (errmsg("adding watchdog information list. memory allocation error"))); - - if (strcmp(pool_config->delegate_IP, delegate_ip)) - ereport(ERROR, - (errmsg("adding watchdog information list. delegate IP mismatch error"), - errdetail("delegate IP defined in config \"%s\" does not match with \"%s\"",pool_config->delegate_IP, delegate_ip))); - - for ( i = 0 ; i < MAX_WATCHDOG_NUM ; i ++) - { - p = (WD_List+i); - - if( p->status != WD_END) - { - /* found; modify the pgpool. */ - if ((!strncmp(p->hostname, hostname, sizeof(p->hostname))) && - (p->pgpool_port == pgpool_port) && - (p->wd_port == wd_port)) - { - if (p->status == WD_DOWN || p->status == WD_INIT) - { - wd_reset_wd_info(p); - } - - p->status = status; - - if (tv != NULL) - { - memcpy(&(p->tv), tv, sizeof(struct timeval)); - } - - return i; - } - } - - /* not found; add as a new pgpool */ - else - { - wd_reset_wd_info(p); - - p->status = status; - p->pgpool_port = pgpool_port; - p->wd_port = wd_port; - - strlcpy(p->hostname, hostname, sizeof(p->hostname)); - strlcpy(p->delegate_ip, delegate_ip, sizeof(p->delegate_ip)); - - if (tv != NULL) - { - memcpy(&(p->tv), tv, sizeof(struct timeval)); - } - - return i; - } - } - ereport(WARNING, - (errmsg("failed adding watchdog information list. list is full"))); - return -1; -} - -/** reset watchdog info*/ -static void -wd_reset_wd_info(WdInfo * info) -{ - WD_TIME_INIT(info->hb_send_time); - WD_TIME_INIT(info->hb_last_recv_time); - - info->in_interlocking = false; - info->is_lock_holder = false; -} - -/* add watchdog information to list using config description */ -int -wd_add_wd_list(WdDesc * other_wd) -{ - WdInfo * p = NULL; - int i = 0; - - if (other_wd == NULL) - { - ereport(ERROR, - (errmsg("adding watchdog information list. memory allocation error"))); - } - for ( i = 0 ; i < other_wd->num_wd ; i ++) - { - p = &(other_wd->wd_info[i]); - strlcpy(p->delegate_ip, pool_config->delegate_IP, sizeof(p->delegate_ip)); - wd_set_wd_info(p); - } - - return i; -} - -/* set watchdog information to list */ -int -wd_set_wd_info(WdInfo * info) -{ - int rtn; - rtn = wd_set_wd_list(info->hostname, info->pgpool_port, info->wd_port, - info->delegate_ip, &(info->tv), info->status); - return rtn; -} - -/* return master if exist, NULL if not found */ -WdInfo * -wd_is_exist_master(void) -{ - WdInfo * p = WD_List; - - while (p->status != WD_END) - { - /* find master pgpool in the other servers */ - if (p->status == WD_MASTER) - { - /* master found */ - return p; - } - p++; - } - /* not found */ - return NULL; -} - -/* set or unset in_interlocking flag */ -void -wd_set_interlocking(WdInfo *info, bool value) -{ - WdInfo * p = WD_List; - - while (p->status != WD_END) - { - if ((!strncmp(p->hostname, info->hostname, sizeof(p->hostname))) && - (p->pgpool_port == info->pgpool_port) && - (p->wd_port == info->wd_port)) - { - p->in_interlocking = value; - - return; - } - p++; - } -} - -/* set or unset lock holder flag */ -void -wd_set_lock_holder(WdInfo *info, bool value) -{ - WdInfo * p = WD_List; - - while (p->status != WD_END) - { - if ((!strncmp(p->hostname, info->hostname, sizeof(p->hostname))) && - (p->pgpool_port == info->pgpool_port) && - (p->wd_port == info->wd_port)) - { - p->is_lock_holder = value; - - return; - } - p++; - } -} - -/* return the lock holder if exist, NULL if not found */ -WdInfo * -wd_get_lock_holder(void) -{ - WdInfo * p = WD_List; - - while (p->status != WD_END) - { - /* find failover lock holder */ - if ((p->status == WD_NORMAL || p->status == WD_MASTER) && - p->is_lock_holder) - { - /* found */ - return p; - } - p++; - } - - /* not found */ - return NULL; -} - -/* return the pgpool in interlocking found in first, NULL if not found */ -WdInfo * -wd_get_interlocking(void) -{ - WdInfo * p = WD_List; - - /* for updating contactable flag */ - wd_update_info(); - - while (p->status != WD_END) - { - /* skip if not contactable */ - if (!p->is_contactable) - { - p++; - continue; - } - - /* find pgpool in interlocking */ - if ((p->status == WD_NORMAL || p->status == WD_MASTER) && - p->in_interlocking) - { - /* found */ - return p; - } - p++; - } - - /* not found */ - return NULL; -} - -/* if all pgpool are in interlocking return true, otherwise false */ -bool -wd_are_interlocking_all(void) -{ - WdInfo * p = WD_List; - bool rtn = true; - - /* for updating contactable flag */ - wd_update_info(); - - while (p->status != WD_END) - { - /* skip if not contactable */ - if (!p->is_contactable) - { - p++; - continue; - } - - /* find pgpool not in interlocking */ - if ((p->status == WD_NORMAL || p->status == WD_MASTER) && - !p->in_interlocking) - { - rtn = false; - } - p++; - } - - return rtn; -} - -/* clear flags for interlocking */ -void -wd_clear_interlocking_info(void) -{ - WdInfo * p = WD_List; - - while (p->status != WD_END) - { - wd_set_lock_holder(p, false); - wd_set_interlocking(p, false); - p++; - } -} - -int -wd_am_I_oldest(void) -{ - WdInfo * p = WD_List; - - p++; - while (p->status != WD_END) - { - if ((p->status == WD_NORMAL) || - (p->status == WD_MASTER)) - { - if (WD_TIME_BEFORE(p->tv, WD_MYSELF->tv)) - { - return WD_NG; - } - } - p++; - } - return WD_OK; -} - -int -wd_set_myself(struct timeval * tv, int status) -{ - if (WD_MYSELF == NULL) - { - return WD_NG; - } - - if (tv != NULL) - { - memcpy(&(WD_MYSELF->tv),tv,sizeof(struct timeval)); - } - - WD_MYSELF->status = status; - - return WD_OK; -} - - - -/* - * if master exists and it is contactable return true, - * otherwise return false - */ -bool -wd_is_contactable_master(void) -{ - WdInfo * master = NULL; - - if (WD_MYSELF->status == WD_MASTER) - return true; - - /* for updating contactable flag */ - wd_update_info(); - - master = wd_is_exist_master(); - if (master != NULL) - { - return master->is_contactable; - } - - return false; -} - -bool -wd_are_contactable_all(void) -{ - WdInfo * p = WD_List; - - /* for updating contactable flag */ - wd_update_info(); - - while (p->status != WD_END) - { - if ((p->status == WD_NORMAL || p->status == WD_MASTER) && - !p->is_contactable) - { - return false; - } - p++; - } - - return true; -} - -/* - * get watchdog information of specified index - */ -WdInfo * -wd_get_watchdog_info(int wd_index) -{ - if (wd_index < 0 || wd_index > pool_config->other_wd->num_wd) - return NULL; - - return &WD_List[wd_index]; -} diff --git a/src/watchdog/wd_ping.c b/src/watchdog/wd_ping.c index c5832eec4..6ad149020 100644 --- a/src/watchdog/wd_ping.c +++ b/src/watchdog/wd_ping.c @@ -33,7 +33,6 @@ #include "pool.h" #include "utils/elog.h" #include "pool_config.h" -//#include "watchdog/watchdog.h" #include "watchdog/wd_utils.h" #define WD_MAX_PING_RESULT 256 [parent: 701890a7cb11]