election quorum support sf_election_quorum_auto
parent
613c31fcf3
commit
78e321f4ad
|
|
@ -128,6 +128,8 @@ int sf_load_quorum_config_ex(SFElectionQuorum *quorum,
|
|||
"quorum", ini_ctx->context);
|
||||
if (str == NULL) {
|
||||
*quorum = def_quorum;
|
||||
} else if (strncasecmp(str, "auto", 4) == 0) {
|
||||
*quorum = sf_election_quorum_auto;
|
||||
} else if (strncasecmp(str, "any", 3) == 0) {
|
||||
*quorum = sf_election_quorum_any;
|
||||
} else if (strncasecmp(str, "majority", 8) == 0) {
|
||||
|
|
|
|||
|
|
@ -92,6 +92,8 @@ static inline const char *sf_get_quorum_caption(
|
|||
const SFElectionQuorum quorum)
|
||||
{
|
||||
switch (quorum) {
|
||||
case sf_election_quorum_auto:
|
||||
return "auto";
|
||||
case sf_election_quorum_any:
|
||||
return "any";
|
||||
case sf_election_quorum_majority:
|
||||
|
|
@ -101,11 +103,31 @@ static inline const char *sf_get_quorum_caption(
|
|||
}
|
||||
}
|
||||
|
||||
static inline bool sf_election_quorum_check(const SFElectionQuorum quorum,
|
||||
const int total_count, const int active_count)
|
||||
{
|
||||
switch (quorum) {
|
||||
case sf_election_quorum_any:
|
||||
return active_count > 0;
|
||||
case sf_election_quorum_auto:
|
||||
if (total_count % 2 == 0) { //same as sf_election_quorum_any
|
||||
return active_count > 0;
|
||||
}
|
||||
//continue
|
||||
case sf_election_quorum_majority:
|
||||
if (active_count == total_count) {
|
||||
return true;
|
||||
} else {
|
||||
return active_count > total_count / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define sf_load_read_rule_config(rule, ini_ctx) \
|
||||
sf_load_read_rule_config_ex(rule, ini_ctx, sf_data_read_rule_master_only)
|
||||
|
||||
#define sf_load_quorum_config(quorum, ini_ctx) \
|
||||
sf_load_quorum_config_ex(quorum, ini_ctx, sf_election_quorum_majority)
|
||||
sf_load_quorum_config_ex(quorum, ini_ctx, sf_election_quorum_auto)
|
||||
|
||||
#define SF_NET_RETRY_FINISHED(retry_times, counter, result) \
|
||||
!((SF_IS_RETRIABLE_ERROR(result) && ((retry_times > 0 && \
|
||||
|
|
|
|||
|
|
@ -245,8 +245,9 @@ typedef struct sf_synchronize_context {
|
|||
} SFSynchronizeContext;
|
||||
|
||||
typedef enum sf_election_quorum {
|
||||
sf_election_quorum_any = 1,
|
||||
sf_election_quorum_majority
|
||||
sf_election_quorum_auto,
|
||||
sf_election_quorum_any,
|
||||
sf_election_quorum_majority,
|
||||
} SFElectionQuorum;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue