Blame SOURCES/patch.4.7.25.4

9e325d
*** cvotn/dbinc/repmgr.h.orig	2009-05-04 10:33:55.000000000 -0400
9e325d
--- cvotn/dbinc/repmgr.h	2009-05-04 10:27:26.000000000 -0400
9e325d
***************
9e325d
*** 374,379 ****
9e325d
--- 374,380 ----
9e325d
  #define	SITE_FROM_EID(eid)	(&db_rep->sites[eid])
9e325d
  #define	EID_FROM_SITE(s)	((int)((s) - (&db_rep->sites[0])))
9e325d
  #define	IS_VALID_EID(e)		((e) >= 0)
9e325d
+ #define	IS_KNOWN_REMOTE_SITE(e)	((e) >= 0 && ((u_int)(e)) < db_rep->site_cnt)
9e325d
  #define	SELF_EID		INT_MAX
9e325d
  
9e325d
  #define	IS_PEER_POLICY(p) ((p) == DB_REPMGR_ACKS_ALL_PEERS ||		\
9e325d
*** cvotn/rep/rep_elect.c.orig	2009-05-04 10:35:50.000000000 -0400
9e325d
--- cvotn/rep/rep_elect.c	2009-05-04 10:31:24.000000000 -0400
9e325d
***************
9e325d
*** 33,39 ****
9e325d
  static int __rep_fire_elected __P((ENV *, REP *, u_int32_t));
9e325d
  static void __rep_elect_master __P((ENV *, REP *));
9e325d
  static int __rep_tally __P((ENV *, REP *, int, u_int32_t *, u_int32_t, roff_t));
9e325d
! static int __rep_wait __P((ENV *, db_timeout_t *, int *, int, u_int32_t));
9e325d
  
9e325d
  /*
9e325d
   * __rep_elect --
9e325d
--- 33,39 ----
9e325d
  static int __rep_fire_elected __P((ENV *, REP *, u_int32_t));
9e325d
  static void __rep_elect_master __P((ENV *, REP *));
9e325d
  static int __rep_tally __P((ENV *, REP *, int, u_int32_t *, u_int32_t, roff_t));
9e325d
! static int __rep_wait __P((ENV *, db_timeout_t *, int, u_int32_t));
9e325d
  
9e325d
  /*
9e325d
   * __rep_elect --
9e325d
***************
9e325d
*** 55,61 ****
9e325d
  	ENV *env;
9e325d
  	LOG *lp;
9e325d
  	REP *rep;
9e325d
! 	int done, eid, elected, full_elect, locked, in_progress, need_req;
9e325d
  	int ret, send_vote, t_ret;
9e325d
  	u_int32_t ack, ctlflags, egen, nsites, orig_tally, priority, realpri;
9e325d
  	u_int32_t tiebreaker;
9e325d
--- 55,61 ----
9e325d
  	ENV *env;
9e325d
  	LOG *lp;
9e325d
  	REP *rep;
9e325d
! 	int done, elected, full_elect, locked, in_progress, need_req;
9e325d
  	int ret, send_vote, t_ret;
9e325d
  	u_int32_t ack, ctlflags, egen, nsites, orig_tally, priority, realpri;
9e325d
  	u_int32_t tiebreaker;
9e325d
***************
9e325d
*** 181,188 ****
9e325d
  			REP_SYSTEM_UNLOCK(env);
9e325d
  			(void)__rep_send_message(env, DB_EID_BROADCAST,
9e325d
  			    REP_MASTER_REQ, NULL, NULL, 0, 0);
9e325d
! 			ret = __rep_wait(env, &to, &eid,
9e325d
! 			    0, REP_F_EPHASE0);
9e325d
  			REP_SYSTEM_LOCK(env);
9e325d
  			F_CLR(rep, REP_F_EPHASE0);
9e325d
  			switch (ret) {
9e325d
--- 181,187 ----
9e325d
  			REP_SYSTEM_UNLOCK(env);
9e325d
  			(void)__rep_send_message(env, DB_EID_BROADCAST,
9e325d
  			    REP_MASTER_REQ, NULL, NULL, 0, 0);
9e325d
! 			ret = __rep_wait(env, &to, 0, REP_F_EPHASE0);
9e325d
  			REP_SYSTEM_LOCK(env);
9e325d
  			F_CLR(rep, REP_F_EPHASE0);
9e325d
  			switch (ret) {
9e325d
***************
9e325d
*** 286,296 ****
9e325d
  		REP_SYSTEM_LOCK(env);
9e325d
  		goto vote;
9e325d
  	}
9e325d
! 	ret = __rep_wait(env, &to, &eid, full_elect, REP_F_EPHASE1);
9e325d
  	switch (ret) {
9e325d
  		case 0:
9e325d
  			/* Check if election complete or phase complete. */
9e325d
! 			if (eid != DB_EID_INVALID && !IN_ELECTION(rep)) {
9e325d
  				RPRINT(env, DB_VERB_REP_ELECT,
9e325d
  				    (env, "Ended election phase 1"));
9e325d
  				goto edone;
9e325d
--- 285,295 ----
9e325d
  		REP_SYSTEM_LOCK(env);
9e325d
  		goto vote;
9e325d
  	}
9e325d
! 	ret = __rep_wait(env, &to, full_elect, REP_F_EPHASE1);
9e325d
  	switch (ret) {
9e325d
  		case 0:
9e325d
  			/* Check if election complete or phase complete. */
9e325d
! 			if (!IN_ELECTION(rep)) {
9e325d
  				RPRINT(env, DB_VERB_REP_ELECT,
9e325d
  				    (env, "Ended election phase 1"));
9e325d
  				goto edone;
9e325d
***************
9e325d
*** 398,412 ****
9e325d
  		REP_SYSTEM_LOCK(env);
9e325d
  		goto i_won;
9e325d
  	}
9e325d
! 	ret = __rep_wait(env, &to, &eid, full_elect, REP_F_EPHASE2);
9e325d
  	RPRINT(env, DB_VERB_REP_ELECT,
9e325d
  	    (env, "Ended election phase 2 %d", ret));
9e325d
  	switch (ret) {
9e325d
  		case 0:
9e325d
! 			if (eid != DB_EID_INVALID)
9e325d
! 				goto edone;
9e325d
! 			ret = DB_REP_UNAVAIL;
9e325d
! 			break;
9e325d
  		case DB_REP_EGENCHG:
9e325d
  			if (to > timeout)
9e325d
  				to = timeout;
9e325d
--- 397,408 ----
9e325d
  		REP_SYSTEM_LOCK(env);
9e325d
  		goto i_won;
9e325d
  	}
9e325d
! 	ret = __rep_wait(env, &to, full_elect, REP_F_EPHASE2);
9e325d
  	RPRINT(env, DB_VERB_REP_ELECT,
9e325d
  	    (env, "Ended election phase 2 %d", ret));
9e325d
  	switch (ret) {
9e325d
  		case 0:
9e325d
! 			goto edone;
9e325d
  		case DB_REP_EGENCHG:
9e325d
  			if (to > timeout)
9e325d
  				to = timeout;
9e325d
***************
9e325d
*** 1050,1062 ****
9e325d
  	ENV *env;
9e325d
  	REP *rep;
9e325d
  {
9e325d
- 	/*
9e325d
- 	 * We often come through here twice, sometimes even more.  We mustn't
9e325d
- 	 * let the redundant calls affect stats counting.  But rep_elect relies
9e325d
- 	 * on this first part for setting eidp.
9e325d
- 	 */
9e325d
- 	rep->master_id = rep->eid;
9e325d
- 
9e325d
  	if (F_ISSET(rep, REP_F_MASTERELECT | REP_F_MASTER)) {
9e325d
  		/* We've been through here already; avoid double counting. */
9e325d
  		return;
9e325d
--- 1046,1051 ----
9e325d
***************
9e325d
*** 1093,1102 ****
9e325d
  	(timeout > 5000000) ? 500000 : ((timeout >= 10) ? timeout / 10 : 1);
9e325d
  
9e325d
  static int
9e325d
! __rep_wait(env, timeoutp, eidp, full_elect, flags)
9e325d
  	ENV *env;
9e325d
  	db_timeout_t *timeoutp;
9e325d
! 	int *eidp, full_elect;
9e325d
  	u_int32_t flags;
9e325d
  {
9e325d
  	DB_REP *db_rep;
9e325d
--- 1082,1091 ----
9e325d
  	(timeout > 5000000) ? 500000 : ((timeout >= 10) ? timeout / 10 : 1);
9e325d
  
9e325d
  static int
9e325d
! __rep_wait(env, timeoutp, full_elect, flags)
9e325d
  	ENV *env;
9e325d
  	db_timeout_t *timeoutp;
9e325d
! 	int full_elect;
9e325d
  	u_int32_t flags;
9e325d
  {
9e325d
  	DB_REP *db_rep;
9e325d
***************
9e325d
*** 1174,1180 ****
9e325d
  			F_CLR(rep, REP_F_EGENUPDATE);
9e325d
  			ret = DB_REP_EGENCHG;
9e325d
  		} else if (phase_over) {
9e325d
- 			*eidp = rep->master_id;
9e325d
  			done = 1;
9e325d
  			ret = 0;
9e325d
  		}
9e325d
--- 1163,1168 ----
9e325d
*** cvotn/repmgr/repmgr_net.c.orig	2009-05-04 10:34:46.000000000 -0400
9e325d
--- cvotn/repmgr/repmgr_net.c	2009-05-04 10:27:26.000000000 -0400
9e325d
***************
9e325d
*** 100,105 ****
9e325d
--- 100,107 ----
9e325d
  		    control, rec, &nsites_sent, &npeers_sent)) != 0)
9e325d
  			goto out;
9e325d
  	} else {
9e325d
+ 		DB_ASSERT(env, IS_KNOWN_REMOTE_SITE(eid));
9e325d
+ 
9e325d
  		/*
9e325d
  		 * If this is a request that can be sent anywhere, then see if
9e325d
  		 * we can send it to our peer (to save load on the master), but