[sheepdog] [PATCH v2] sheep: do COW at local node for just one time

Liu Yuan namei.unix at gmail.com
Wed Jun 27 07:50:06 CEST 2012


On 06/27/2012 11:05 AM, yaohaiting.wujue at gmail.com wrote:
> From: HaiTing Yao <wujue.yht at taobao.com>
> 
> Node A receives a COW write request, and then forward the request to
> replica nodes B, C, D. Nodes B, C, D do COW separately. On some
> conditions, nodes B, C, D maybe need read base data from node A. Now
> node A is waiting for the reply from B, C, D. If the I/O threads are
> busy, there is dead lock.
> 
> Signed-off-by: HaiTing Yao <wujue.yht at taobao.com>
> ---
>  sheep/gateway.c    |   43 +++++++++++++++++++++++++++++++++++++++++++
>  sheep/ops.c        |    2 +-
>  sheep/sheep_priv.h |    3 +++
>  3 files changed, 47 insertions(+), 1 deletions(-)
> 
> diff --git a/sheep/gateway.c b/sheep/gateway.c
> index 42f028a..dfee8f3 100644
> --- a/sheep/gateway.c
> +++ b/sheep/gateway.c
> @@ -208,6 +208,42 @@ err:
>  	return ret;
>  }
>  
> +static int do_cow_at_gateway(struct request *req)
> +{
> +	int ret = 0;
> +	char *buf = NULL;
> +
> +	dprintf("%" PRIx64 ", %" PRIx64 "\n", req->rq.obj.oid,
> +		req->rq.obj.cow_oid);
> +
> +	buf = valloc(SD_DATA_OBJ_SIZE);
> +	if (!buf) {
> +		eprintf("can not allocate memory\n");
> +		return -1;
> +	}
> +
> +	if (req->rq.data_length != SD_DATA_OBJ_SIZE) {
> +		ret = read_copy_from_replica(req->vnodes, req->rq.epoch,
> +			req->rq.obj.cow_oid, buf);

Indentation.


> +		if (ret != SD_RES_SUCCESS) {
> +			eprintf("failed to read cow object\n");
> +			free(buf);
> +			return -1;
> +		}
> +
> +		memcpy(buf + req->rq.obj.offset, req->data,
> +			req->rq.data_length);
> +

Ditto

> +		free(req->data);
> +		req->data = buf;
> +
> +		req->rq.data_length = SD_DATA_OBJ_SIZE;
> +		req->rq.obj.offset = 0;
> +	}
> +
> +	return ret;
> +}
> +
>  void do_gateway_request(struct work *work)
>  {
>  	struct request *req = container_of(work, struct request, work);
> @@ -216,6 +252,13 @@ void do_gateway_request(struct work *work)
>  	dprintf("%x, %" PRIx64" , %u\n",
>  		req->rq.opcode, req->rq.obj.oid, req->rq.epoch);
>  
> +	if ((req->rq.flags & SD_FLAG_CMD_WRITE) &&
> +		(req->rq.flags & SD_FLAG_CMD_COW)) {

ditto.

Also here We should document fallback of the failure and why we fallback.

Thanks,
Yuan



More information about the sheepdog mailing list