<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/29 Liu Yuan <span dir="ltr"><<a href="mailto:namei.unix@gmail.com" target="_blank">namei.unix@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Fri, Nov 29, 2013 at 05:10:31PM +0800, Robin Dong wrote:<br>
> Implement the distributed lock by zookeeper (refer: <a href="http://zookeeper.apache.org/doc/trunk/recipes.html" target="_blank">http://zookeeper.apache.org/doc/trunk/recipes.html</a>)<br>
> The routine is:<br>
> 1. create a seq-ephemeral znode in lock directory (use lock-id as dir name)<br>
> 2. get smallest file path as owner of the lock; the other thread wait on a pthread_mutex_t<br>
> 3. if owner of the lock release it (or the owner is killed by accident), zookeeper will<br>
> trigger zk_watch() which will wake up all waiting threads to compete new owner of the lock<br>
><br>
> We add ->local_lock for dist_mutex to avoid many threads in one sheepdog daemon to create too many files<br>
> in a lock directory.<br>
><br>
> Signed-off-by: Robin Dong <<a href="mailto:sanbai@taobao.com">sanbai@taobao.com</a>><br>
> ---<br>
> sheep/cluster.h | 15 +++++<br>
> sheep/cluster/zookeeper.c | 140 ++++++++++++++++++++++++++++++++++++++++++++-<br>
> 2 files changed, 154 insertions(+), 1 deletions(-)<br>
><br>
> diff --git a/sheep/cluster.h b/sheep/cluster.h<br>
> index 81b5ae4..0aa058c 100644<br>
> --- a/sheep/cluster.h<br>
> +++ b/sheep/cluster.h<br>
> @@ -23,6 +23,13 @@<br>
> #include "sheep.h"<br>
> #include "config.h"<br>
><br>
> +struct dist_mutex {<br>
> + uint32_t id; /* id of this mutex */<br>
> + pthread_mutex_t wait;<br>
> + pthread_mutex_t local_lock;<br>
> + char ephemeral_path[MAX_NODE_STR_LEN];<br>
> +};<br>
> +<br>
> /*<br>
> * maximum payload size sent in ->notify and ->unblock, it should be large<br>
> * enough to support COROSYNC_MAX_NODES * struct sd_node<br>
> @@ -109,6 +116,14 @@ struct cluster_driver {<br>
> int (*unblock)(void *msg, size_t msg_len);<br>
><br>
> /*<br>
> + * A distributed mutex lock to avoid race condition when using swift<br>
> + * interface to add/delete/list object.<br>
<br>
</div></div>This is not a swift only operation. Instead it is now as a generic locking<br>
service.<br>
<div class="im"><br>
> + */<br>
> + int (*init_mutex)(struct dist_mutex *mutex, uint32_t id);<br>
> + void (*lock_mutex)(struct dist_mutex *mutex);<br>
> + void (*unlock_mutex)(struct dist_mutex *mutex);<br>
<br>
</div>Please explain every function clearly as other interface does.<br>
<br>
Any reason to call it mutex? I'd suggest shorter name as<br></blockquote><div><br></div><div>Because it is only mutex now, I will add dist_rwlock,dist_selock or some other kind of locks in the future.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
->init_lock()<br>
->lock()<br>
->unlock()<br>
<br>
So struct dist_mutex -> struct cluster_lock<br>
<br>
Finally, I think you need to initialize local/cluster driver's lock interface's<br>
too, thought it would be currently empty operations for them. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888">Yuan<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Best Regard<br>Robin Dong
</div></div>