Skip to content

Commit

Permalink
Merge pull request #1215 from kgaillot/fixes
Browse files Browse the repository at this point in the history
Improve CIB re-sync handling
  • Loading branch information
kgaillot committed Jan 30, 2017
2 parents 8e7515c + 3a94d53 commit 40ba78a
Showing 1 changed file with 13 additions and 45 deletions.
58 changes: 13 additions & 45 deletions cib/messages.c
Expand Up @@ -40,16 +40,12 @@
#include <cibmessages.h>
#include <callbacks.h>

/* Maximum number of diffs to ignore while waiting for a resync */
#define MAX_DIFF_RETRY 5

#ifdef CIBPIPE
gboolean cib_is_master = TRUE;
#else
gboolean cib_is_master = FALSE;
#endif

xmlNode *the_cib = NULL;
gboolean syncd_once = FALSE;
extern const char *cib_our_uname;
int revision_check(xmlNode * cib_update, xmlNode * cib_copy, int flags);
int get_revision(xmlNode * xml_obj, int cur_revision);
Expand All @@ -73,9 +69,6 @@ cib_process_shutdown_req(const char *op, int options, const char *section, xmlNo
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
int result = pcmk_ok;
const char *host = crm_element_value(req, F_ORIG);

Expand All @@ -96,7 +89,6 @@ cib_process_shutdown_req(const char *op, int options, const char *section, xmlNo
}

return result;
#endif
}

int
Expand Down Expand Up @@ -141,9 +133,6 @@ cib_process_readwrite(const char *op, int options, const char *section, xmlNode
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
int result = pcmk_ok;

crm_trace("Processing \"%s\" event", op);
Expand All @@ -161,8 +150,6 @@ cib_process_readwrite(const char *op, int options, const char *section, xmlNode
if (cib_is_master == FALSE) {
crm_info("We are now in R/W mode");
cib_is_master = TRUE;
syncd_once = TRUE;

} else {
crm_debug("We are still in R/W mode");
}
Expand All @@ -173,17 +160,20 @@ cib_process_readwrite(const char *op, int options, const char *section, xmlNode
}

return result;
#endif
}

int sync_in_progress = 0;
/* Set to 1 when a sync is requested, incremented when a diff is ignored,
* reset to 0 when a sync is received
*/
static int sync_in_progress = 0;

void
send_sync_request(const char *host)
{
xmlNode *sync_me = create_xml_node(NULL, "sync-me");

crm_info("Requesting re-sync from peer");
sync_in_progress++;
crm_info("Requesting re-sync from %s", (host? host : "all peers"));
sync_in_progress = 1;

crm_xml_add(sync_me, F_TYPE, "cib");
crm_xml_add(sync_me, F_CIB_OPERATION, CIB_OP_SYNC_ONE);
Expand All @@ -197,9 +187,6 @@ int
cib_process_ping(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
const char *host = crm_element_value(req, F_ORIG);
const char *seq = crm_element_value(req, F_CIB_PING_ID);
char *digest = calculate_xml_versioned_digest(the_cib, FALSE, TRUE, CRM_FEATURE_SET);
Expand Down Expand Up @@ -241,27 +228,19 @@ cib_process_ping(const char *op, int options, const char *section, xmlNode * req
free(digest);

return pcmk_ok;
#endif
}

int
cib_process_sync(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
return sync_our_cib(req, TRUE);
#endif
}

int
cib_process_upgrade_server(const char *op, int options, const char *section, xmlNode * req, xmlNode * input,
xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
int rc = pcmk_ok;

*answer = NULL;
Expand Down Expand Up @@ -314,19 +293,14 @@ cib_process_upgrade_server(const char *op, int options, const char *section, xml
free_xml(scratch);
}
return rc;
#endif
}

int
cib_process_sync_one(const char *op, int options, const char *section, xmlNode * req,
xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
xmlNode ** answer)
{
#ifdef CIBPIPE
return -EINVAL;
#else
return sync_our_cib(req, FALSE);
#endif
}

int
Expand All @@ -336,19 +310,15 @@ cib_server_process_diff(const char *op, int options, const char *section, xmlNod
{
int rc = pcmk_ok;

if (cib_is_master) {
/* the master is never waiting for a resync */
sync_in_progress = 0;
}

if (sync_in_progress > MAX_DIFF_RETRY) {
/* request another full-sync,
* the last request may have been lost
/* Don't ignore diffs forever; the last request may have been lost.
* If the diff fails, we'll ask for another full resync.
*/
sync_in_progress = 0;
}

if (sync_in_progress) {
/* The master should never ignore a diff */
if (sync_in_progress && !cib_is_master) {
int diff_add_updates = 0;
int diff_add_epoch = 0;
int diff_add_admin_epoch = 0;
Expand Down Expand Up @@ -382,7 +352,7 @@ cib_server_process_diff(const char *op, int options, const char *section, xmlNod
crm_warn("Not requesting full refresh in R/W mode");
}

} else if(rc != pcmk_ok && cib_legacy_mode()) {
} else if ((rc != pcmk_ok) && !cib_is_master && cib_legacy_mode()) {
crm_warn("Requesting full CIB refresh because update failed: %s"
CRM_XS " rc=%d", pcmk_strerror(rc), rc);
xml_log_patchset(LOG_INFO, __FUNCTION__, input);
Expand Down Expand Up @@ -524,7 +494,6 @@ check_generation(xmlNode * newCib, xmlNode * oldCib)
return FALSE;
}

#ifndef CIBPIPE
int
sync_our_cib(xmlNode * request, gboolean all)
{
Expand Down Expand Up @@ -575,4 +544,3 @@ sync_our_cib(xmlNode * request, gboolean all)
free(digest);
return result;
}
#endif

0 comments on commit 40ba78a

Please sign in to comment.