[sheepdog] [PATCH v1 4/4] sheep/http: add flag for onode

Liu Yuan namei.unix at gmail.com
Fri Feb 21 08:14:24 CET 2014


On Fri, Feb 21, 2014 at 02:47:33PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> Add flag for onode, so we can identify which object is upload complete and
> which has been interrupted by client when uploading.
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/http/kv.c    | 29 +++++++++++++++++++++++++++--
>  sheep/http/swift.c |  3 +++
>  2 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/sheep/http/kv.c b/sheep/http/kv.c
> index 037df66..9e71e92 100644
> --- a/sheep/http/kv.c
> +++ b/sheep/http/kv.c
> @@ -30,6 +30,10 @@ struct onode_extent {
>  	uint64_t count;
>  };
>  
> +/* for onode->flags */
> +#define ONODE_INIT	1	/* created and allocated space, but no data */
> +#define ONODE_COMPLETE	2	/* data upload complete */
> +
>  struct kv_onode {
>  	union {
>  		struct {
> @@ -42,6 +46,7 @@ struct kv_onode {
>  			uint32_t nr_extent;
>  			uint64_t oid;
>  			uint8_t inlined;
> +			uint8_t flags;
>  		};
>  
>  		uint8_t pad[BLOCK_SIZE];
> @@ -751,7 +756,7 @@ out:
>  static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
>  {
>  	ssize_t size;
> -	int ret = SD_RES_SUCCESS;
> +	int ret = SD_RES_SUCCESS, offset;
>  
>  	if (req->data_length <= KV_ONODE_INLINE_SIZE) {
>  		size = http_request_read(req, onode->data, sizeof(onode->data));
> @@ -770,6 +775,13 @@ static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
>  		if (ret != SD_RES_SUCCESS)
>  			goto out;
>  	}
> +	/* write ONODE_COMPLETE to onode->flags */
> +	onode->flags = ONODE_COMPLETE;
> +	offset = offsetof(struct kv_onode, flags);
> +	ret = sd_write_object(onode->oid, (char *)onode + offset,
> +			      sizeof(uint8_t), offset, false);
> +	if (ret != SD_RES_SUCCESS)
> +		sd_err("Failed to write flags of onode %s", onode->name);
>  out:
>  	return ret;
>  }
> @@ -1077,6 +1089,7 @@ static int onode_create_for_space(struct http_request *req, const char *account,
>  	memset(onode, 0, sizeof(*onode));
>  	pstrcpy(onode->name, sizeof(onode->name), name);
>  	onode->data_vid = data_vid;
> +	onode->flags = ONODE_INIT;
>  
>  	ret = onode_allocate_data(onode, req);
>  	if (ret != SD_RES_SUCCESS) {
> @@ -1157,9 +1170,15 @@ int kv_read_object(struct http_request *req, const char *account,
>  	if (ret != SD_RES_SUCCESS)
>  		goto out;
>  
> +	/* this object has not been uploaded complete */
> +	if (onode->flags != ONODE_COMPLETE) {
> +		ret = SD_RES_EIO;
> +		goto out;
> +	}
> +
>  	ret = onode_read_data(onode, req);
>  	if (ret != SD_RES_SUCCESS)
> -		sd_err("failed to read data for %s", name);
> +		sd_err("failed to read data for %s ret %d", name, ret);
>  out:
>  	free(onode);
>  	return ret;
> @@ -1279,6 +1298,12 @@ int kv_read_object_meta(struct http_request *req, const char *account,
>  	req->data_length = onode->size;
>  	http_request_writef(req, "Last-Modified: %s\n",
>  			    http_time(onode->mtime));
> +
> +	/* this object has not been uploaded complete */
> +	if (onode->flags != ONODE_COMPLETE) {
> +		ret = SD_RES_EIO;
> +		goto out;

This is an abuse of SD_RES_EIO, add a new SD_RES_INCOMPLETE flag for it.

Thanks
Yuan



More information about the sheepdog mailing list