root/daemons/controld/controld_join_client.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. update_dc_expected
  2. do_cl_join_query
  3. do_cl_join_announce
  4. do_cl_join_offer_respond
  5. join_query_callback
  6. set_join_state
  7. do_cl_join_finalize_respond

   1 /*
   2  * Copyright 2004-2020 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/crm.h>
  13 #include <crm/cib.h>
  14 #include <crm/msg_xml.h>
  15 #include <crm/common/xml.h>
  16 
  17 #include <pacemaker-controld.h>
  18 
  19 int reannounce_count = 0;
  20 void join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data);
  21 
  22 extern ha_msg_input_t *copy_ha_msg_input(ha_msg_input_t * orig);
  23 
  24 /*!
  25  * \internal
  26  * \brief Remember if DC is shutting down as we join
  27  *
  28  * If we're joining while the current DC is shutting down, update its expected
  29  * state, so we don't fence it if we become the new DC. (We weren't a peer
  30  * when it broadcast its shutdown request.)
  31  *
  32  * \param[in] msg  A join message from the DC
  33  */
  34 static void
  35 update_dc_expected(xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37     if (fsa_our_dc && crm_is_true(crm_element_value(msg, F_CRM_DC_LEAVING))) {
  38         crm_node_t *dc_node = crm_get_peer(0, fsa_our_dc);
  39 
  40         crm_update_peer_expected(__func__, dc_node, CRMD_JOINSTATE_DOWN);
  41     }
  42 }
  43 
  44 /*      A_CL_JOIN_QUERY         */
  45 /* is there a DC out there? */
  46 void
  47 do_cl_join_query(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
  48                  enum crmd_fsa_cause cause,
  49                  enum crmd_fsa_state cur_state,
  50                  enum crmd_fsa_input current_input, fsa_data_t * msg_data)
  51 {
  52     xmlNode *req = create_request(CRM_OP_JOIN_ANNOUNCE, NULL, NULL,
  53                                   CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
  54 
  55     sleep(1);                   // Give the cluster layer time to propagate to the DC
  56     update_dc(NULL);            /* Unset any existing value so that the result is not discarded */
  57     crm_debug("Querying for a DC");
  58     send_cluster_message(NULL, crm_msg_crmd, req, FALSE);
  59     free_xml(req);
  60 }
  61 
  62 /*       A_CL_JOIN_ANNOUNCE     */
  63 
  64 /* this is kind of a workaround for the fact that we may not be around or
  65  * are otherwise unable to reply when the DC sends out A_DC_JOIN_OFFER_ALL
  66  */
  67 void
  68 do_cl_join_announce(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
  69                     enum crmd_fsa_cause cause,
  70                     enum crmd_fsa_state cur_state,
  71                     enum crmd_fsa_input current_input, fsa_data_t * msg_data)
  72 {
  73     /* don't announce if we're in one of these states */
  74     if (cur_state != S_PENDING) {
  75         crm_warn("Not announcing cluster join because in state %s",
  76                  fsa_state2string(cur_state));
  77         return;
  78     }
  79 
  80     if (AM_I_OPERATIONAL) {
  81         /* send as a broadcast */
  82         xmlNode *req = create_request(CRM_OP_JOIN_ANNOUNCE, NULL, NULL,
  83                                       CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
  84 
  85         crm_debug("Announcing availability");
  86         update_dc(NULL);
  87         send_cluster_message(NULL, crm_msg_crmd, req, FALSE);
  88         free_xml(req);
  89 
  90     } else {
  91         /* Delay announce until we have finished local startup */
  92         crm_warn("Delaying announce of cluster join until local startup is complete");
  93         return;
  94     }
  95 }
  96 
  97 static int query_call_id = 0;
  98 
  99 /*       A_CL_JOIN_REQUEST      */
 100 /* aka. accept the welcome offer */
 101 void
 102 do_cl_join_offer_respond(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 103                          enum crmd_fsa_cause cause,
 104                          enum crmd_fsa_state cur_state,
 105                          enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 106 {
 107     ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
 108     const char *welcome_from;
 109     const char *join_id;
 110 
 111     CRM_CHECK(input != NULL, return);
 112 
 113 #if 0
 114     if (we are sick) {
 115         log error;
 116 
 117         /* save the request for later? */
 118         return;
 119     }
 120 #endif
 121 
 122     welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM);
 123     join_id = crm_element_value(input->msg, F_CRM_JOIN_ID);
 124     crm_trace("Accepting cluster join offer from node %s "CRM_XS" join-%s",
 125               welcome_from, crm_element_value(input->msg, F_CRM_JOIN_ID));
 126 
 127     /* we only ever want the last one */
 128     if (query_call_id > 0) {
 129         crm_trace("Cancelling previous join query: %d", query_call_id);
 130         remove_cib_op_callback(query_call_id, FALSE);
 131         query_call_id = 0;
 132     }
 133 
 134     if (update_dc(input->msg) == FALSE) {
 135         crm_warn("Discarding cluster join offer from node %s (expected %s)",
 136                  welcome_from, fsa_our_dc);
 137         return;
 138     }
 139 
 140     update_dc_expected(input->msg);
 141 
 142     query_call_id =
 143         fsa_cib_conn->cmds->query(fsa_cib_conn, NULL, NULL, cib_scope_local | cib_no_children);
 144     fsa_register_cib_callback(query_call_id, FALSE, strdup(join_id), join_query_callback);
 145     crm_trace("Registered join query callback: %d", query_call_id);
 146 
 147     controld_set_fsa_action_flags(A_DC_TIMER_STOP);
 148     trigger_fsa();
 149 }
 150 
 151 void
 152 join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154     char *join_id = user_data;
 155     xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);
 156 
 157     CRM_LOG_ASSERT(join_id != NULL);
 158 
 159     if (query_call_id != call_id) {
 160         crm_trace("Query %d superseded", call_id);
 161         goto done;
 162     }
 163 
 164     query_call_id = 0;
 165     if(rc != pcmk_ok || output == NULL) {
 166         crm_err("Could not retrieve version details for join-%s: %s (%d)",
 167                 join_id, pcmk_strerror(rc), rc);
 168         register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __func__);
 169 
 170     } else if (fsa_our_dc == NULL) {
 171         crm_debug("Membership is in flux, not continuing join-%s", join_id);
 172 
 173     } else {
 174         xmlNode *reply = NULL;
 175 
 176         crm_debug("Respond to join offer join-%s from %s", join_id, fsa_our_dc);
 177         copy_in_properties(generation, output);
 178 
 179         reply = create_request(CRM_OP_JOIN_REQUEST, generation, fsa_our_dc,
 180                                CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
 181 
 182         crm_xml_add(reply, F_CRM_JOIN_ID, join_id);
 183         crm_xml_add(reply, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
 184         send_cluster_message(crm_get_peer(0, fsa_our_dc), crm_msg_crmd, reply, TRUE);
 185         free_xml(reply);
 186     }
 187 
 188   done:
 189     free_xml(generation);
 190 }
 191 
 192 static void
 193 set_join_state(const char * start_state)
     /* [previous][next][first][last][top][bottom][index][help] */
 194 {
 195     if (pcmk__str_eq(start_state, "standby", pcmk__str_casei)) {
 196         crm_notice("Forcing node %s to join in %s state per configured environment",
 197                    fsa_our_uname, start_state);
 198         update_attr_delegate(fsa_cib_conn, cib_sync_call, XML_CIB_TAG_NODES, fsa_our_uuid,
 199                              NULL, NULL, NULL, "standby", "on", TRUE, NULL, NULL);
 200 
 201     } else if (pcmk__str_eq(start_state, "online", pcmk__str_casei)) {
 202         crm_notice("Forcing node %s to join in %s state per configured environment",
 203                    fsa_our_uname, start_state);
 204         update_attr_delegate(fsa_cib_conn, cib_sync_call, XML_CIB_TAG_NODES, fsa_our_uuid,
 205                              NULL, NULL, NULL, "standby", "off", TRUE, NULL, NULL);
 206 
 207     } else if (pcmk__str_eq(start_state, "default", pcmk__str_casei)) {
 208         crm_debug("Not forcing a starting state on node %s", fsa_our_uname);
 209 
 210     } else {
 211         crm_warn("Unrecognized start state '%s', using 'default' (%s)",
 212                  start_state, fsa_our_uname);
 213     }
 214 }
 215 
 216 /*      A_CL_JOIN_RESULT        */
 217 /* aka. this is notification that we have (or have not) been accepted */
 218 void
 219 do_cl_join_finalize_respond(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 220                             enum crmd_fsa_cause cause,
 221                             enum crmd_fsa_state cur_state,
 222                             enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 223 {
 224     xmlNode *tmp1 = NULL;
 225     gboolean was_nack = TRUE;
 226     static gboolean first_join = TRUE;
 227     ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
 228     const char *start_state = pcmk__env_option("node_start_state");
 229 
 230     int join_id = -1;
 231     const char *op = crm_element_value(input->msg, F_CRM_TASK);
 232     const char *ack_nack = crm_element_value(input->msg, CRM_OP_JOIN_ACKNAK);
 233     const char *welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM);
 234 
 235     if (!pcmk__str_eq(op, CRM_OP_JOIN_ACKNAK, pcmk__str_casei)) {
 236         crm_trace("Ignoring op=%s message", op);
 237         return;
 238     }
 239 
 240     /* calculate if it was an ack or a nack */
 241     if (crm_is_true(ack_nack)) {
 242         was_nack = FALSE;
 243     }
 244 
 245     crm_element_value_int(input->msg, F_CRM_JOIN_ID, &join_id);
 246 
 247     if (was_nack) {
 248         crm_err("Shutting down because cluster join with leader %s failed "
 249                 CRM_XS" join-%d NACK'd", welcome_from, join_id);
 250         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 251         return;
 252     }
 253 
 254     if (AM_I_DC == FALSE && pcmk__str_eq(welcome_from, fsa_our_uname, pcmk__str_casei)) {
 255         crm_warn("Discarding our own welcome - we're no longer the DC");
 256         return;
 257     }
 258 
 259     if (update_dc(input->msg) == FALSE) {
 260         crm_warn("Discarding %s from node %s (expected from %s)",
 261                  op, welcome_from, fsa_our_dc);
 262         return;
 263     }
 264 
 265     update_dc_expected(input->msg);
 266 
 267     /* send our status section to the DC */
 268     tmp1 = controld_query_executor_state(fsa_our_uname);
 269     if (tmp1 != NULL) {
 270         xmlNode *reply = create_request(CRM_OP_JOIN_CONFIRM, tmp1, fsa_our_dc,
 271                                         CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
 272 
 273         crm_xml_add_int(reply, F_CRM_JOIN_ID, join_id);
 274 
 275         crm_debug("Confirming join-%d: sending local operation history to %s",
 276                   join_id, fsa_our_dc);
 277 
 278         /*
 279          * If this is the node's first join since the controller started on it,
 280          * set its initial state (standby or member) according to the user's
 281          * preference.
 282          *
 283          * We do not clear the LRM history here. Even if the DC failed to do it
 284          * when we last left, removing them here creates a race condition if the
 285          * controller is being recovered. Instead of a list of active resources
 286          * from the executor, we may end up with a blank status section. If we
 287          * are _NOT_ lucky, we will probe for the "wrong" instance of anonymous
 288          * clones and end up with multiple active instances on the machine.
 289          */
 290         if (first_join && !pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
 291             first_join = FALSE;
 292             if (start_state) {
 293                 set_join_state(start_state);
 294             }
 295         }
 296 
 297         send_cluster_message(crm_get_peer(0, fsa_our_dc), crm_msg_crmd, reply, TRUE);
 298         free_xml(reply);
 299 
 300         if (AM_I_DC == FALSE) {
 301             register_fsa_input_adv(cause, I_NOT_DC, NULL, A_NOTHING, TRUE,
 302                                    __func__);
 303         }
 304 
 305         free_xml(tmp1);
 306 
 307     } else {
 308         crm_err("Could not confirm join-%d with %s: Local operation history failed",
 309                 join_id, fsa_our_dc);
 310         register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL);
 311     }
 312 }

/* [previous][next][first][last][top][bottom][index][help] */