[sheepdog] [PATCH v2] sheep/http: add Created-Time for onode
Liu Yuan
namei.unix at gmail.com
Fri Feb 28 08:42:48 CET 2014
On Fri, Feb 28, 2014 at 02:34:08PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
>
> At present, we allocate space for an onode and then write data for it,
> so we should record two times: 'ctime' means when the onode is created
> and allocated space, 'mtime' means when the data of onode have all be
> written done.
>
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
> v1-->v2:
> 1. write 'flags' and 'mtime' at once.
>
> sheep/http/kv.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/sheep/http/kv.c b/sheep/http/kv.c
> index 6f648e3..9559493 100644
> --- a/sheep/http/kv.c
> +++ b/sheep/http/kv.c
> @@ -61,6 +61,7 @@ struct kv_onode {
> /* a hash value for etag */
> uint8_t sha1[round_up(SHA1_DIGEST_SIZE, 8)];
> uint64_t size;
> + uint64_t ctime;
> uint64_t mtime;
> uint32_t data_vid;
> uint32_t nr_extent;
> @@ -751,7 +752,7 @@ static int onode_allocate_data(struct kv_onode *onode, struct http_request *req)
> goto out;
> }
>
> - onode->mtime = get_seconds();
> + onode->ctime = get_seconds();
> onode->size = req->data_length;
> out:
> return ret;
> @@ -762,6 +763,9 @@ static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
> ssize_t size;
> int ret = SD_RES_SUCCESS, offset;
>
> + onode->mtime = get_seconds();
> + onode->flags = ONODE_COMPLETE;
> +
> if (req->data_length <= KV_ONODE_INLINE_SIZE) {
> size = http_request_read(req, onode->data, sizeof(onode->data));
> if (size < 0 || req->data_length != size) {
> @@ -778,14 +782,16 @@ static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
> ret = onode_populate_extents(onode, req);
> if (ret != SD_RES_SUCCESS)
> goto out;
> + /* write mtime and flag ONODE_COMPLETE to onode */
> + offset = offsetof(struct kv_onode, flags);
> + ret = sd_write_object(onode->oid, (char *)onode,
> + offset + sizeof(uint8_t), 0, false);
I'd suggest use a macro
#define ONODE_HDR_SIZE BLOCK_SIZE
then update header instead of tricky offset manipulation.
Thanks
Yuan
More information about the sheepdog
mailing list