040-patch.4.7.25.4.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. --- a/dbinc/repmgr.h
  2. +++ b/dbinc/repmgr.h
  3. @@ -374,6 +374,7 @@ typedef struct {
  4. #define SITE_FROM_EID(eid) (&db_rep->sites[eid])
  5. #define EID_FROM_SITE(s) ((int)((s) - (&db_rep->sites[0])))
  6. #define IS_VALID_EID(e) ((e) >= 0)
  7. +#define IS_KNOWN_REMOTE_SITE(e) ((e) >= 0 && ((u_int)(e)) < db_rep->site_cnt)
  8. #define SELF_EID INT_MAX
  9. #define IS_PEER_POLICY(p) ((p) == DB_REPMGR_ACKS_ALL_PEERS || \
  10. --- a/rep/rep_elect.c
  11. +++ b/rep/rep_elect.c
  12. @@ -33,7 +33,7 @@ static int __rep_elect_init
  13. static int __rep_fire_elected __P((ENV *, REP *, u_int32_t));
  14. static void __rep_elect_master __P((ENV *, REP *));
  15. static int __rep_tally __P((ENV *, REP *, int, u_int32_t *, u_int32_t, roff_t));
  16. -static int __rep_wait __P((ENV *, db_timeout_t *, int *, int, u_int32_t));
  17. +static int __rep_wait __P((ENV *, db_timeout_t *, int, u_int32_t));
  18. /*
  19. * __rep_elect --
  20. @@ -55,7 +55,7 @@ __rep_elect(dbenv, given_nsites, nvotes,
  21. ENV *env;
  22. LOG *lp;
  23. REP *rep;
  24. - int done, eid, elected, full_elect, locked, in_progress, need_req;
  25. + int done, elected, full_elect, locked, in_progress, need_req;
  26. int ret, send_vote, t_ret;
  27. u_int32_t ack, ctlflags, egen, nsites, orig_tally, priority, realpri;
  28. u_int32_t tiebreaker;
  29. @@ -181,8 +181,7 @@ __rep_elect(dbenv, given_nsites, nvotes,
  30. REP_SYSTEM_UNLOCK(env);
  31. (void)__rep_send_message(env, DB_EID_BROADCAST,
  32. REP_MASTER_REQ, NULL, NULL, 0, 0);
  33. - ret = __rep_wait(env, &to, &eid,
  34. - 0, REP_F_EPHASE0);
  35. + ret = __rep_wait(env, &to, 0, REP_F_EPHASE0);
  36. REP_SYSTEM_LOCK(env);
  37. F_CLR(rep, REP_F_EPHASE0);
  38. switch (ret) {
  39. @@ -286,11 +285,11 @@ restart:
  40. REP_SYSTEM_LOCK(env);
  41. goto vote;
  42. }
  43. - ret = __rep_wait(env, &to, &eid, full_elect, REP_F_EPHASE1);
  44. + ret = __rep_wait(env, &to, full_elect, REP_F_EPHASE1);
  45. switch (ret) {
  46. case 0:
  47. /* Check if election complete or phase complete. */
  48. - if (eid != DB_EID_INVALID && !IN_ELECTION(rep)) {
  49. + if (!IN_ELECTION(rep)) {
  50. RPRINT(env, DB_VERB_REP_ELECT,
  51. (env, "Ended election phase 1"));
  52. goto edone;
  53. @@ -398,15 +397,12 @@ phase2:
  54. REP_SYSTEM_LOCK(env);
  55. goto i_won;
  56. }
  57. - ret = __rep_wait(env, &to, &eid, full_elect, REP_F_EPHASE2);
  58. + ret = __rep_wait(env, &to, full_elect, REP_F_EPHASE2);
  59. RPRINT(env, DB_VERB_REP_ELECT,
  60. (env, "Ended election phase 2 %d", ret));
  61. switch (ret) {
  62. case 0:
  63. - if (eid != DB_EID_INVALID)
  64. - goto edone;
  65. - ret = DB_REP_UNAVAIL;
  66. - break;
  67. + goto edone;
  68. case DB_REP_EGENCHG:
  69. if (to > timeout)
  70. to = timeout;
  71. @@ -1050,13 +1046,6 @@ __rep_elect_master(env, rep)
  72. ENV *env;
  73. REP *rep;
  74. {
  75. - /*
  76. - * We often come through here twice, sometimes even more. We mustn't
  77. - * let the redundant calls affect stats counting. But rep_elect relies
  78. - * on this first part for setting eidp.
  79. - */
  80. - rep->master_id = rep->eid;
  81. -
  82. if (F_ISSET(rep, REP_F_MASTERELECT | REP_F_MASTER)) {
  83. /* We've been through here already; avoid double counting. */
  84. return;
  85. @@ -1093,10 +1082,10 @@ __rep_fire_elected(env, rep, egen)
  86. (timeout > 5000000) ? 500000 : ((timeout >= 10) ? timeout / 10 : 1);
  87. static int
  88. -__rep_wait(env, timeoutp, eidp, full_elect, flags)
  89. +__rep_wait(env, timeoutp, full_elect, flags)
  90. ENV *env;
  91. db_timeout_t *timeoutp;
  92. - int *eidp, full_elect;
  93. + int full_elect;
  94. u_int32_t flags;
  95. {
  96. DB_REP *db_rep;
  97. @@ -1174,7 +1163,6 @@ __rep_wait(env, timeoutp, eidp, full_ele
  98. F_CLR(rep, REP_F_EGENUPDATE);
  99. ret = DB_REP_EGENCHG;
  100. } else if (phase_over) {
  101. - *eidp = rep->master_id;
  102. done = 1;
  103. ret = 0;
  104. }
  105. --- a/repmgr/repmgr_net.c
  106. +++ b/repmgr/repmgr_net.c
  107. @@ -100,6 +100,8 @@ __repmgr_send(dbenv, control, rec, lsnp,
  108. control, rec, &nsites_sent, &npeers_sent)) != 0)
  109. goto out;
  110. } else {
  111. + DB_ASSERT(env, IS_KNOWN_REMOTE_SITE(eid));
  112. +
  113. /*
  114. * If this is a request that can be sent anywhere, then see if
  115. * we can send it to our peer (to save load on the master), but