sheep: add debug info in zookeeper.c

Set sheep node information in zookeeper files so we can debug it easier when
there are same problmes happens in cluster.

And, add come sd_debug() in zookeeper.c

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep: avoid dead loop when zookeeper session is expired

When zookeeper session is expired, zk_get_least_seq() will return
ZNONODE, but we have not check the return value of zk_get_least_seq()
so the routine will fall in dead loop.

To avoid it, we add check for return value of zk_get_least_seq() and
jump to recreate sequential-node if find out the ZNONODE event.

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/cluster: let local_lock() support nested

In kv_create_object(), we need to lock bucket and then lock allocator of it:

    lock(bucket_vid)
        lock(data_vid)
        unlock(data_vid)
    unlock(bucket_vid)

so the implementations of ->lock() for 'local' in cluster must support nested
lock.

The pthread_mutex_t with attribute of "PTHREAD_PROCESS_SHARED" could used by
threads in different processes.
(ref: http://stackoverflow.com/questions/17809231/mutex-attribute-pthread-process-shared-inverts-logic,
http://royontechnology.blogspot.com/2007/06/comparison-of-pthreadprocessshared-in.html)

First, we create a 'global_lock' to protect lock_tree, then we can create new
'SHARED' lock to use. Since the pthread_mutex_t is actually store in files, we
must check the exists of files before init mutex on mmap-memory.

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/cluster: delete znodes when leaving cluster

A sheep node call zk_lock() to create a znode in zookeeper and become the
owner of the lock, then if all disks under this sheep node is broken
suddenly, the node will have to leave cluster.Now, the znode will stay
in "/lock" and make other sheep nodes waiting it forever.

So we should delete znodes which created by this sheep node when leaving
cluster.

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/cluster: use wrapper function to create ephemeral znode

We use zk_create_node() before, but when operation of creating ephemeral
zonde has been timeout, we will see multi-znodes in parent znode because
zk_create_node() will create znodes again if there is ZOPERATIONTIMEOUT.
Multi-znodes in same directry will make zk_lock() be dead loop.

The best solution for this problem is make value of 'timeout' for
zookeeper_init() bigger, but we still need to use zk_create_seq_node() to
replace zk_create_node() for which we will see "operation timeout" fail
in sheep log.

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sheep/cluster: change output format in sheep log

We have print debug information for 'lock_id' in octal when calling
zk_lock(), so is the zk_unlock().

Signed-off-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>