[sheepdog] [PATCH v1 2/4] sheep/http: change routine of kv_create_object()

Liu Yuan namei.unix at gmail.com
Fri Feb 21 08:25:34 CET 2014


On Fri, Feb 21, 2014 at 02:47:31PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> Change routine of kv_create_object(): create onode and alloc space first,
> then recveive data from fastcgi of http, and write it.
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/http/kv.c | 170 +++++++++++++++++++++++++++++++++++---------------------
>  1 file changed, 108 insertions(+), 62 deletions(-)
> 
> diff --git a/sheep/http/kv.c b/sheep/http/kv.c
> index 4ac69fc..037df66 100644
> --- a/sheep/http/kv.c
> +++ b/sheep/http/kv.c
> @@ -62,6 +62,9 @@ struct bucket_iterater_arg {
>  	uint64_t bytes_used;
>  };
>  
> +static int kv_delete_object_nolock(const char *account, const char *bucket,
> +				   const char *name);
> +
>  /* Account operations */
>  
>  /*
> @@ -646,15 +649,12 @@ static int vdi_read_write(uint32_t vid, char *data, size_t length,
>  	return local_req_wait(iocb);
>  }
>  
> -static int onode_populate_extents(struct kv_onode *onode,
> +static int onode_allocate_extents(struct kv_onode *onode,
>  				  struct http_request *req)
>  {
> -	ssize_t size;
> -	uint64_t start = 0, count, done = 0, total, offset;
> +	uint64_t start = 0, count;
>  	int ret;
> -	char *data_buf = NULL;
>  	uint32_t data_vid = onode->data_vid;
> -	uint64_t write_buffer_size = MIN(kv_rw_buffer, req->data_length);
>  
>  	count = DIV_ROUND_UP(req->data_length, SD_DATA_OBJ_SIZE);
>  	sys->cdrv->lock(data_vid);
> @@ -666,6 +666,36 @@ static int onode_populate_extents(struct kv_onode *onode,
>  		goto out;
>  	}
>  
> +	sys->cdrv->lock(data_vid);
> +	ret = oalloc_new_finish(data_vid, start, count);
> +	sys->cdrv->unlock(data_vid);
> +	if (ret != SD_RES_SUCCESS) {
> +		sd_err("oalloc_new_finish failed for %s, %s", onode->name,
> +		       sd_strerror(ret));
> +		goto out;
> +	}
> +
> +	onode->o_extent[0].start = start;
> +	onode->o_extent[0].count = count;
> +	onode->nr_extent = 1;
> +out:
> +	return ret;
> +}
> +
> +static int onode_populate_extents(struct kv_onode *onode,
> +				  struct http_request *req)
> +{
> +	ssize_t size;
> +	uint64_t start = onode->o_extent[0].start;
> +	uint64_t count = onode->o_extent[0].count;
> +	uint64_t done = 0, total, offset;
> +	uint64_t write_buffer_size = MIN(kv_rw_buffer, req->data_length);
> +	int ret;
> +	char *data_buf = NULL;
> +	uint32_t data_vid = onode->data_vid;
> +
> +	count = DIV_ROUND_UP(req->data_length, SD_DATA_OBJ_SIZE);
> +
>  	data_buf = xmalloc(write_buffer_size);
>  	offset = start * SD_DATA_OBJ_SIZE;
>  	total = req->data_length;
> @@ -673,9 +703,6 @@ static int onode_populate_extents(struct kv_onode *onode,
>  		size = http_request_read(req, data_buf, write_buffer_size);
>  		if (size <= 0) {
>  			sd_err("Failed to read http request: %ld", size);
> -			sys->cdrv->lock(data_vid);
> -			oalloc_free(data_vid, start, count);
> -			sys->cdrv->unlock(data_vid);
>  			ret = SD_RES_EIO;
>  			goto out;
>  		}
> @@ -683,27 +710,11 @@ static int onode_populate_extents(struct kv_onode *onode,
>  		if (ret != SD_RES_SUCCESS) {
>  			sd_err("Failed to write data object for %s, %s",
>  			       onode->name, sd_strerror(ret));
> -			sys->cdrv->lock(data_vid);
> -			oalloc_free(data_vid, start, count);
> -			sys->cdrv->unlock(data_vid);
>  			goto out;
>  		}
>  		done += size;
>  		offset += size;
>  	}
> -
> -	sys->cdrv->lock(data_vid);
> -	ret = oalloc_new_finish(data_vid, start, count);
> -	sys->cdrv->unlock(data_vid);
> -	if (ret != SD_RES_SUCCESS) {
> -		sd_err("oalloc_new_finish failed for %s, %s", onode->name,
> -		       sd_strerror(ret));
> -		goto out;
> -	}
> -
> -	onode->o_extent[0].start = start;
> -	onode->o_extent[0].count = count;
> -	onode->nr_extent = 1;
>  out:
>  	free(data_buf);
>  	return ret;
> @@ -719,13 +730,30 @@ static uint64_t get_seconds(void)
>  	return seconds;
>  }
>  
> +static int onode_allocate_data(struct kv_onode *onode, struct http_request *req)
> +{
> +	int ret = SD_RES_SUCCESS;
> +
> +	if (req->data_length <= KV_ONODE_INLINE_SIZE)
> +		onode->inlined = 1;
> +	else {
> +		ret = onode_allocate_extents(onode, req);
> +		if (ret != SD_RES_SUCCESS)
> +			goto out;
> +	}
> +
> +	onode->mtime = get_seconds();
> +	onode->size = req->data_length;
> +out:
> +	return ret;
> +}
> +
>  static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
>  {
>  	ssize_t size;
>  	int ret = SD_RES_SUCCESS;
>  
>  	if (req->data_length <= KV_ONODE_INLINE_SIZE) {
> -		onode->inlined = 1;
>  		size = http_request_read(req, onode->data, sizeof(onode->data));
>  		if (size < 0 || req->data_length != size) {
>  			sd_err("Failed to read from web server for %s",
> @@ -733,14 +761,15 @@ static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
>  			ret = SD_RES_SYSTEM_ERROR;
>  			goto out;
>  		}
> +		ret = sd_write_object(onode->oid, (char *)onode,
> +				      BLOCK_SIZE + size, 0, false);
> +		if (ret != SD_RES_SUCCESS)
> +			goto out;
>  	} else {
>  		ret = onode_populate_extents(onode, req);
>  		if (ret != SD_RES_SUCCESS)
>  			goto out;
>  	}
> -
> -	onode->mtime = get_seconds();
> -	onode->size = req->data_length;
>  out:
>  	return ret;
>  }
> @@ -824,17 +853,6 @@ out:
>  	return ret;
>  }
>  
> -static int onode_create(struct kv_onode *onode, uint32_t bucket_vid)
> -{
> -	int ret;
> -
> -	sys->cdrv->lock(bucket_vid);
> -	ret = onode_create_nolock(onode, bucket_vid);
> -	sys->cdrv->unlock(bucket_vid);
> -
> -	return ret;
> -}
> -
>  static int onode_free_data(struct kv_onode *onode, int lock)
>  {
>  	uint32_t data_vid = onode->data_vid;
> @@ -863,6 +881,7 @@ static int onode_read_extents(struct kv_onode *onode, struct http_request *req)
>  	char *data_buf = NULL;
>  	uint64_t read_buffer_size = MIN(kv_rw_buffer, onode->size);
>  
> +	sd_err("req->len: %"PRIu64, len);

use sd_debug() but is it necessary?

Thanks
Yuan



More information about the sheepdog mailing list