diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-03-05 03:21:58 +0000 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2014-03-05 03:29:34 +0000 |
commit | 4a36ed564fae9e99fb43fcaeeea228a75a890f60 (patch) | |
tree | ffdb237a3d534bfdf2ba2760366f7c583a844bba /xlators/cluster/nsr-server/src/etcd-sim.c | |
parent | d23e33a93ccf46435e4176943da1797b7c142288 (diff) |
nsr: change leader-election code to use new etcd_lock
This is certainy much simpler (therefore easier to maintain) and should
be more robust as well. Tested with both real and simulated versions of
the etcd API.
Change-Id: Ic67de7f87455fcd9aeb1354714698f9562b7e4a7
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/cluster/nsr-server/src/etcd-sim.c')
-rw-r--r-- | xlators/cluster/nsr-server/src/etcd-sim.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/xlators/cluster/nsr-server/src/etcd-sim.c b/xlators/cluster/nsr-server/src/etcd-sim.c index 782b5f617..d0bea12c7 100644 --- a/xlators/cluster/nsr-server/src/etcd-sim.c +++ b/xlators/cluster/nsr-server/src/etcd-sim.c @@ -34,6 +34,8 @@ #include <fcntl.h> #include <sys/file.h> +#include "mem-pool.h" + /* * Mock implementation of etcd * The etcd file is simulated in /tmp/<server-names> @@ -244,3 +246,35 @@ etcd_watch (etcd_session this, char *pfx, char **keyp, char **valuep, { return ETCD_WTF; } + +etcd_result +etcd_lock (etcd_session session_as_void, char *key, unsigned int ttl, + char *index_in, char **index_out) +{ + char *path; + int fd; + + if (!index_in) { + if (gf_asprintf(&path,"/var/tmp/%s",key) < 0) { + return ETCD_WTF; + } + fd = open(path,O_RDWR|O_CREAT,0666); + GF_FREE(path); + if (fd < 0) { + return ETCD_WTF; + } + if (flock(fd,LOCK_EX) < 0) { + close(fd); + return ETCD_WTF; + } + *index_out = strdup("42"); + } + + /* + * Yes, we leak an fd by not closing it here (and nobody else even + * knows about it). That would be awful in any other context, but + * for test scripts it won't matter. + */ + return ETCD_OK; +} + |