Skip to content

Commit

Permalink
Emit all election messages on LOGMSG_USER
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hannum <[email protected]>
  • Loading branch information
markhannum committed Jan 4, 2025
1 parent 070ca61 commit 5d7e4ca
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 63 deletions.
59 changes: 29 additions & 30 deletions berkdb/rep/rep_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static const char revid[] = "$Id: rep_method.c,v 1.134 2003/11/13 15:41:51 sue E
#include <locks_wrap.h>
#include <assert.h>
extern int gbl_fullrecovery;
extern int gbl_debug_election;
int gbl_reproduce_ckp_bug = 0;

int gbl_rep_method_max_sleep_cnt = 0;
Expand Down Expand Up @@ -353,7 +352,7 @@ __rep_start(dbenv, dbt, gen, flags)
__rep_set_gen(dbenv, __func__, __LINE__,
rep->recover_gen + 1);
}
} else if (gbl_debug_election) {
} else {
logmsg(LOGMSG_USER, "%s line %d keeping gen %d for full recovery\n", __func__, __LINE__, rep->gen);
}
/*
Expand All @@ -370,7 +369,7 @@ __rep_start(dbenv, dbt, gen, flags)
logmsg(LOGMSG_DEBUG, "%s line %d setting gen to rep->egen "
"%d\n", __func__, __LINE__, rep->egen);
__rep_set_gen(dbenv, __func__, __LINE__, rep->egen);
} else if (gbl_debug_election) {
} else {
logmsg(LOGMSG_USER, "%s line %d keeping gen %d for full recovery\n", __func__, __LINE__, rep->gen);
}
}
Expand Down Expand Up @@ -1308,7 +1307,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
*/
if (in_progress) {
*eidp = dbenv->rep_eid;
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d returning %d master %s egen is %d\n",
__func__, __LINE__, ret, *eidp, *newgen);
return (0);
Expand All @@ -1317,7 +1316,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
fprintf(stderr, "%s:%d broadcasting REP_MASTER_REQ\n",
__FILE__, __LINE__);
#endif
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s start sending master req\n", __func__);
send_master_req(dbenv, __func__, __LINE__);
ret = __rep_wait(dbenv, timeout / 4, eidp, newgen, 0, REP_F_EPHASE1);
Expand All @@ -1329,7 +1328,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
if (FLD_ISSET(dbenv->verbose, DB_VERB_REPLICATION))
__db_err(dbenv, "Found master %d", *eidp);
#endif
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d returning %d master %s egen is %d\n",
__func__, __LINE__, ret, *eidp, *newgen);
return (0);
Expand Down Expand Up @@ -1359,7 +1358,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
MUTEX_LOCK(dbenv, db_rep->rep_mutexp);

/* WAITSTART pushes us past point of no-return */
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d setting PHASE1 clearing TALLY\n", __func__, __LINE__);
F_SET(rep, REP_F_EPHASE1 | REP_F_WAITSTART | REP_F_NOARCHIVE);
F_CLR(rep, REP_F_TALLY);
Expand All @@ -1381,7 +1380,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
/* Tally our own vote */
if (__rep_tally(dbenv, rep, rep->eid, &rep->sites, rep->egen,
rep->tally_off, __func__, __LINE__) != 0) {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d rep-tally failed, lockdone\n", __func__, __LINE__);
goto lockdone;
}
Expand All @@ -1398,13 +1397,13 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
egen = rep->egen;
committed_gen = rep->committed_gen;
send_vote2 = (rep->sites >= rep->nsites && rep->w_priority != 0);
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d send_vote2 is %d, rep->sites is %d, rep->nsites is %d\n",
__func__, __LINE__, send_vote2, rep->sites, rep->nsites);

/* If we have all vote1, change to PHASE2 immediately */
if (send_vote2) {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG, "%s line %d clearing PHASE1 setting PHASE2\n", __func__, __LINE__);
logmsg(LOGMSG_USER, "%s line %d clearing PHASE1 setting PHASE2\n", __func__, __LINE__);
F_SET(rep, REP_F_EPHASE2);
F_CLR(rep, REP_F_EPHASE1);
if (rep->winner == rep->eid) {
Expand All @@ -1417,13 +1416,13 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
Pthread_mutex_unlock(&rep_candidate_lock);

if (use_committed_gen) {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d broadcasting REP_GEN_VOTE1 to all with committed-gen=%d gen=%d egen=%d\n",
__func__, __LINE__, committed_gen, rep->gen, egen);
__rep_send_gen_vote(dbenv, &lsn, nsites, priority, tiebreaker,
egen, committed_gen, db_eid_broadcast, REP_GEN_VOTE1);
} else {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d broadcasting REP_VOTE1 to all (committed-gen=0) gen=%d egen=%d\n",
__func__, __LINE__, rep->gen, egen);
__rep_send_vote(dbenv, &lsn, nsites, priority, tiebreaker, egen,
Expand All @@ -1443,17 +1442,17 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
#endif
/* This increments our election gen */
__rep_elect_done(dbenv, rep, 0, __func__, __LINE__);
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d returning %d master %s egen is %d\n",
__func__, __LINE__, ret, *eidp, *newgen);
return (0);
}
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d going to phase2 because nomaster\n", __func__, __LINE__);
goto phase2;
case DB_ELECTION_GENCHG:
case DB_TIMEOUT:
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d ret is %d break\n", __func__, __LINE__, ret);
break;
default:
Expand All @@ -1479,7 +1478,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
__db_err(dbenv, "Egen changed from %lu to %lu",
(u_long)egen, (u_long)rep->egen);
#endif
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d rep egen changed from %d to %d, restarting\n",
__func__, __LINE__, egen, rep->egen);
goto restart;
Expand All @@ -1490,7 +1489,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
if (rep->sites > rep->nsites / 2) {

/* We think we've seen enough to cast a vote. */
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d have seen enough votes for vote2\n", __func__, __LINE__);
send_vote = rep->winner;
/*
Expand All @@ -1507,7 +1506,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
"Counted my vote %d", rep->votes);
#endif
}
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d setting PHASE2 clearing PHASE1\n", __func__, __LINE__);
F_SET(rep, REP_F_EPHASE2);
F_CLR(rep, REP_F_EPHASE1);
Expand All @@ -1522,7 +1521,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
"Not enough votes to elect: received %d of %d",
rep->sites, rep->nsites);
#endif
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d not enough vote1s, failing\n", __func__, __LINE__);
ret = DB_REP_UNAVAIL;
goto err;
Expand All @@ -1532,7 +1531,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
* We have seen enough vote1's. Now we need to wait
* for all the vote2's.
*/
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d have seen enough votes to cast vote2!\n", __func__, __LINE__);
if (send_vote != rep->eid) {
#ifdef DIAGNOSTIC
Expand All @@ -1541,14 +1540,14 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
__db_err(dbenv, "Sending vote");
#endif
if (use_committed_gen) {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d sending REP_GEN_VOTE2 to %s "
"with committed-gen=%d gen=%d egen=%d\n", __func__, __LINE__,
send_vote, committed_gen, rep->gen, egen);
__rep_send_gen_vote(dbenv, NULL, 0, 0, 0, egen,
committed_gen, send_vote, REP_GEN_VOTE2);
} else {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d sending REP_VOTE2 to %s "
"(committed-gen=0) gen=%d egen=%d\n", __func__, __LINE__,
send_vote, rep->gen, egen);
Expand All @@ -1568,7 +1567,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
case 0:
/* Increment our election gen */
__rep_elect_done(dbenv, rep, 0, __func__, __LINE__);
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d returning %d master %s egen is %d\n",
__func__, __LINE__, ret, *eidp, *newgen);
return (0);
Expand All @@ -1589,7 +1588,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
if (send_vote == rep->eid && done) {
if (nsites == 1)
__rep_elect_master(dbenv, rep, eidp);
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d elected master %s current-egen "
"%d\n", __func__, __LINE__, rep->eid, rep->egen);
ret = 0;
Expand All @@ -1608,7 +1607,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)
* from elect_init where we were unable to grow_sites. In
* that case we do not want to discard all known election info.
*/
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d ret is %d\n", __func__, __LINE__, ret);
assert(ret == 0 || ret == DB_REP_UNAVAIL);
if (ret == 0 || ret == DB_REP_UNAVAIL) {
Expand All @@ -1619,7 +1618,7 @@ __rep_elect(dbenv, nsites, priority, timeout, newgen, already_master, eidp)

Pthread_mutex_unlock(&rep_candidate_lock);
MUTEX_UNLOCK(dbenv, db_rep->rep_mutexp);
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d returning %d master %s egen is %d\n",
__func__, __LINE__, ret, *eidp, *newgen);
return (ret);
Expand Down Expand Up @@ -1652,7 +1651,7 @@ __rep_elect_init(dbenv, lsnp, nsites, priority, beginp, otally)

/* If we are already a master; simply broadcast that fact and return. */
if (F_ISSET(rep, REP_F_MASTER)) {
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d sending REP_NEWMASTER\n",
__func__, __LINE__);
(void)__rep_send_message(dbenv,
Expand All @@ -1678,7 +1677,7 @@ __rep_elect_init(dbenv, lsnp, nsites, priority, beginp, otally)
DB_ENV_TEST_RECOVERY(dbenv, DB_TEST_ELECTINIT, ret, NULL);
rep->nsites = nsites;
rep->priority = priority;
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d setting master_id to %s\n", __func__, __LINE__, db_eid_invalid);
rep->master_id = db_eid_invalid;
}
Expand All @@ -1700,7 +1699,7 @@ __rep_elect_master(dbenv, rep, eidp)
REP *rep;
char **eidp;
{
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_DEBUG,
logmsg(LOGMSG_USER,
"%s line %d setting master_id to %s\n", __func__, __LINE__, rep->eid);
rep->master_id = rep->eid;
F_SET(rep, REP_F_MASTERELECT);
Expand Down Expand Up @@ -1761,7 +1760,7 @@ __rep_wait(dbenv, timeout, eidp, outegen, inegen, flags)
Pthread_mutex_lock(&gbl_rep_egen_lk);
rc = pthread_cond_timedwait(&gbl_rep_egen_cd, &gbl_rep_egen_lk, &tm);
if (rc && rc != ETIMEDOUT)
logmsg(gbl_debug_election ? LOGMSG_USER : LOGMSG_ERROR,
logmsg(LOGMSG_USER,
"Err rc=%d from pthread_cond_timedwait\n", rc);

*outegen = rep->egen;
Expand Down
Loading

0 comments on commit 5d7e4ca

Please sign in to comment.