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);
|
"quorum", ini_ctx->context);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
*quorum = def_quorum;
|
*quorum = def_quorum;
|
||||||
|
} else if (strncasecmp(str, "auto", 4) == 0) {
|
||||||
|
*quorum = sf_election_quorum_auto;
|
||||||
} else if (strncasecmp(str, "any", 3) == 0) {
|
} else if (strncasecmp(str, "any", 3) == 0) {
|
||||||
*quorum = sf_election_quorum_any;
|
*quorum = sf_election_quorum_any;
|
||||||
} else if (strncasecmp(str, "majority", 8) == 0) {
|
} else if (strncasecmp(str, "majority", 8) == 0) {
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ static inline const char *sf_get_quorum_caption(
|
||||||
const SFElectionQuorum quorum)
|
const SFElectionQuorum quorum)
|
||||||
{
|
{
|
||||||
switch (quorum) {
|
switch (quorum) {
|
||||||
|
case sf_election_quorum_auto:
|
||||||
|
return "auto";
|
||||||
case sf_election_quorum_any:
|
case sf_election_quorum_any:
|
||||||
return "any";
|
return "any";
|
||||||
case sf_election_quorum_majority:
|
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) \
|
#define sf_load_read_rule_config(rule, ini_ctx) \
|
||||||
sf_load_read_rule_config_ex(rule, ini_ctx, sf_data_read_rule_master_only)
|
sf_load_read_rule_config_ex(rule, ini_ctx, sf_data_read_rule_master_only)
|
||||||
|
|
||||||
#define sf_load_quorum_config(quorum, ini_ctx) \
|
#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) \
|
#define SF_NET_RETRY_FINISHED(retry_times, counter, result) \
|
||||||
!((SF_IS_RETRIABLE_ERROR(result) && ((retry_times > 0 && \
|
!((SF_IS_RETRIABLE_ERROR(result) && ((retry_times > 0 && \
|
||||||
|
|
|
||||||
|
|
@ -245,8 +245,9 @@ typedef struct sf_synchronize_context {
|
||||||
} SFSynchronizeContext;
|
} SFSynchronizeContext;
|
||||||
|
|
||||||
typedef enum sf_election_quorum {
|
typedef enum sf_election_quorum {
|
||||||
sf_election_quorum_any = 1,
|
sf_election_quorum_auto,
|
||||||
sf_election_quorum_majority
|
sf_election_quorum_any,
|
||||||
|
sf_election_quorum_majority,
|
||||||
} SFElectionQuorum;
|
} SFElectionQuorum;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue