summaryrefslogtreecommitdiffstats
path: root/cpgx
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2009-05-28 14:30:36 -0500
committerDavid Teigland <teigland@redhat.com>2009-05-28 14:30:36 -0500
commit2de0c639c305773afdbba412a0ca49f47e1dd149 (patch)
tree3a54854f42ed34792d4c97a0db9d0c7d0d736072 /cpgx
parent7bf79e8a629d6d17768a5d48db5a2a1f2cdb8a2f (diff)
downloaddct-stuff-2de0c639c305773afdbba412a0ca49f47e1dd149.tar.gz
dct-stuff-2de0c639c305773afdbba412a0ca49f47e1dd149.tar.xz
dct-stuff-2de0c639c305773afdbba412a0ca49f47e1dd149.zip
cpgx: simpler should_leave should_fail
Signed-off-by: David Teigland <teigland@redhat.com>
Diffstat (limited to 'cpgx')
-rw-r--r--cpgx/cpgx.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/cpgx/cpgx.c b/cpgx/cpgx.c
index 5639144..b6e5934 100644
--- a/cpgx/cpgx.c
+++ b/cpgx/cpgx.c
@@ -45,6 +45,7 @@
#define HISTORY_EVENTS (1024 * 1024)
#define DEFAULT_SYNC_MAX 1000 /* sync up to this many events */
#define DUMP_WRITE_PATH "/var/log/cluster/cpgx_debug.txt"
+#define LEAVE_TIME_MAX 8 /* leave or fail up to this long after join */
#define EV_CONFCHG 1
#define EV_MSGTIME 2
@@ -133,6 +134,8 @@ static int continue_after_error = 0;
static int opt_print_event = 1;
static int opt_print_debug = 1;
static time_t prog_begin;
+static time_t join_time;
+static time_t leave_time;
static int dump_point;
static int dump_wrap;
static char debug_buf[256];
@@ -415,7 +418,7 @@ void print_nodes_list(void)
struct node *node;
list_for_each_entry(node, &nodes, list) {
- log_debug("nodeid %u is_member %d needs_sync %d join %u check %u",
+ log_debug("nodeid %u is_member %d needs_sync %d join %08u check %08u",
node->nodeid, node->is_member, node->needs_sync,
node->join_eventid, node->last_check_eventid);
}
@@ -1047,6 +1050,8 @@ static void confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name,
sync_wait = 1;
sync_done = 0;
we_join = 1;
+ join_time = time(NULL);
+ leave_time = join_time + rand_int(1, LEAVE_TIME_MAX);
}
/* Shortcut to bootstrap things. Doesn't work if more than one node
@@ -1373,12 +1378,44 @@ int we_should_send(void)
return 0;
}
-/* TODO: when we join, pick a random number of seconds between 1 and 16;
- when we've been running for this number of seconds, either leave or fail;
- leave if the number is even, fail if it's odd. */
+/* when we join we pick a random number of seconds to run before either leaving
+ or failing; half the time leave, half fail */
int we_should_leave(void)
{
+ time_t now = time(NULL);
+ int half = leave_time % 2;
+
+ if (!opt_leave)
+ return 0;
+
+ if (!opt_fail)
+ half = 1;
+
+ if (now >= leave_time && half) {
+ log_debug("do leave %lu", leave_time - join_time);
+ return 1;
+ }
+ return 0;
+}
+
+int we_should_fail(void)
+{
+ time_t now = time(NULL);
+
+ if (!opt_fail)
+ return 0;
+
+ if (now >= leave_time) {
+ log_debug("do fail %lu", leave_time - join_time);
+ return 1;
+ }
+ return 0;
+}
+
+#if 0
+int we_should_leave(void)
+{
static unsigned int tries;
int rv;
@@ -1413,6 +1450,7 @@ int we_should_fail(void)
}
return 0;
}
+#endif
void loop(void)
{