diff --git a/exec/coroparse.c b/exec/coroparse.c index df6f1de..801984d 100644 --- a/exec/coroparse.c +++ b/exec/coroparse.c @@ -399,6 +399,7 @@ static int main_config_parser_cb(const char *path, } if ((strcmp(path, "quorum.two_node") == 0) || + (strcmp(path, "quorum.expected_votes_tracking") == 0) || (strcmp(path, "quorum.leave_remove") == 0) || (strcmp(path, "quorum.wait_for_all") == 0) || (strcmp(path, "quorum.auto_tie_breaker") == 0) || diff --git a/exec/votequorum.c b/exec/votequorum.c index c03d3f3..c0353c2 100644 --- a/exec/votequorum.c +++ b/exec/votequorum.c @@ -36,7 +36,10 @@ #include #include +#include +#include #include +#include #include #include @@ -85,6 +88,11 @@ static uint32_t last_man_standing_window = DEFAULT_LMS_WIN; static uint8_t leave_remove = 0; static uint32_t ev_barrier = 0; + +static uint8_t ev_tracking = 0; +static uint32_t ev_tracking_barrier = 0; +static int ev_tracking_fd = -1; + /* * votequorum_exec defines/structs/forward definitions */ @@ -480,6 +488,40 @@ static int check_low_node_id_partition(void) return found; } +/* + * load/save are copied almost pristine from totemsrp,c + */ +static int load_ev_tracking_barrier(void) +{ + int res = 0; + char filename[PATH_MAX]; + + snprintf(filename, sizeof(filename) - 1, LOCALSTATEDIR "/lib/corosync/ev_tracking"); + + ev_tracking_fd = open(filename, O_RDWR, 0700); + if (ev_tracking_fd != -1) { + res = read (ev_tracking_fd, &ev_tracking_barrier, sizeof(uint32_t)); + if (res == sizeof (uint32_t)) { + return 0; + } + } + + ev_tracking_barrier = 0; + umask(0); + ev_tracking_fd = open (filename, O_CREAT|O_RDWR, 0700); + if (ev_tracking_fd != -1) { + res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t)); + if ((res == -1) || (res != sizeof (uint32_t))) { + log_printf(LOGSYS_LEVEL_WARNING, + "Unable to write to %s", filename); + } + return 0; + } + log_printf(LOGSYS_LEVEL_CRIT, + "Unable to create %s file", filename); + return -1; +} + static void update_wait_for_all_status(uint8_t wfa_status) { wait_for_all_status = wfa_status; @@ -498,6 +540,28 @@ static void update_ev_barrier(uint32_t expected_votes) icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier); } +static void update_ev_tracking_barrier(uint32_t ev_t_barrier) +{ + int res; + + log_printf(LOGSYS_LEVEL_CRIT, "FUCK2: %d", ev_t_barrier); + + ev_tracking_barrier = ev_t_barrier; + icmap_set_uint32("runtime.votequorum.ev_tracking_barrier", ev_tracking_barrier); + + if (lseek (ev_tracking_fd, 0, SEEK_SET) != 0) { + log_printf(LOGSYS_LEVEL_WARNING, + "Unable to update ev_tracking_barrier on disk data!!!"); + return; + } + + res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t)); + if (res != sizeof (uint32_t)) { + log_printf(LOGSYS_LEVEL_WARNING, + "Unable to update ev_tracking_barrier on disk data!!!"); + } +} + /* * quorum calculation core bits */ @@ -669,6 +733,11 @@ static void recalculate_quorum(int allow_decrease, int by_current_nodes) votequorum_exec_send_expectedvotes_notification(); } + if ((ev_tracking) && + (us->expected_votes > ev_tracking_barrier)) { + update_ev_tracking_barrier(us->expected_votes); + } + quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes); are_we_quorate(total_votes); @@ -754,6 +823,14 @@ static char *votequorum_readconfig_static(void) wait_for_all = 1; } + icmap_get_uint8("quorum.expected_votes_tracking", &ev_tracking); + if (ev_tracking) { + if (load_ev_tracking_barrier() < 0) { + return ((char *)"Unable to load ev_tracking file!"); + } + update_ev_tracking_barrier(ev_tracking_barrier); + } + icmap_get_uint8("quorum.leave_remove", &leave_remove); icmap_get_uint8("quorum.wait_for_all", &wait_for_all); icmap_get_uint8("quorum.auto_tie_breaker", &auto_tie_breaker); @@ -792,6 +869,10 @@ static void votequorum_readconfig_dynamic(void) update_ev_barrier(us->expected_votes); + if (ev_tracking) { + us->expected_votes = max(us->expected_votes, ev_tracking_barrier); + } + #ifdef EXPERIMENTAL_QUORUM_DEVICE_API if (icmap_get_uint32("quorum.quorumdev_poll", &quorumdev_poll) != CS_OK) { quorumdev_poll = DEFAULT_QDEV_POLL; @@ -1191,6 +1272,10 @@ static int votequorum_exec_exit_fn (void) ENTER(); + if ((ev_tracking) && (ev_tracking_fd != -1)) { + close(ev_tracking_fd); + } + if (leave_remove) { us->flags |= NODE_FLAGS_LEAVING; ret = votequorum_exec_send_nodeinfo();