Blame SOURCES/patch.4.7.25.4

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