[Sheepdog] [PATCH 2/3] sheep: add SD_MSG_MASTER_TRANSFER message

Liu Yuan namei.unix at gmail.com
Mon Sep 26 12:57:24 CEST 2011


From: Liu Yuan <tailai.ly at taobao.com>

This is sugguested by Kazutaka for crash cluster recovery to remove
the timing race casued by leave message.

This race was found by Kazutaka's below script:

    #!/bin/bash

    # create a directory which has a different creation time
    sheep /store/1 -p 7001
    sleep 1
    collie cluster format -p 7001
    collie cluster shutdown -p 7001
    sleep 1

    # start Sheepdog
    sheep /store/0 -p 7000
    sleep 1
    collie cluster format -p 7000

    while true; do
        sheep /store/1 -p 7001
        sheep /store/2 -p 7002

        # wait for node join
        while [ "`collie cluster info -p 7002 -r 2>&1 | head -1`" != 'running' ]; do
            sleep 0.1
        done

        if [ "`collie node list -p 7002 -r | wc -l`" -ne 2 ]; then
            # break if the result is not correct
            break
        fi

        pkill -f "sheep /store/2"
    done

    # show results
    collie cluster info -p 7000
    collie cluster info -p 7002

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c      |   10 ++++++++++
 sheep/sheep_priv.h |    1 +
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 4bf275e..6301f1b 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -84,6 +84,11 @@ struct vdi_op_message {
 	uint8_t data[0];
 };
 
+struct mastership_tx_message {
+	struct message_header header;
+	uint32_t epoch;
+};
+
 struct work_deliver {
 	struct cpg_event cev;
 
@@ -162,6 +167,11 @@ static inline int leave_message(struct message_header *m)
 	return m->op == SD_MSG_LEAVE;
 }
 
+static inline int master_tx_message(struct message_header *m)
+{
+	return m->op == SD_MSG_MASTER_TRANSFER;
+}
+
 static int send_message(cpg_handle_t handle, struct message_header *msg)
 {
 	struct iovec iov;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 6680f79..b7e5dfc 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -30,6 +30,7 @@
 #define SD_MSG_VDI_OP           0x02
 #define SD_MSG_MASTER_CHANGED   0x03
 #define SD_MSG_LEAVE            0x04
+#define SD_MSG_MASTER_TRANSFER  0x05
 
 #define SD_STATUS_OK                0x00
 #define SD_STATUS_WAIT_FOR_FORMAT   0x01
-- 
1.7.6.1




More information about the sheepdog mailing list