[sheepdog] [PATCH v1] sheep/http: add Created-Time for onode

Robin Dong robin.k.dong at gmail.com
Wed Feb 26 09:15:33 CET 2014


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>
---
 sheep/http/kv.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index 6f648e3..61014a3 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;
@@ -786,6 +787,13 @@ static int onode_populate_data(struct kv_onode *onode, struct http_request *req)
 			      sizeof(uint8_t), offset, false);
 	if (ret != SD_RES_SUCCESS)
 		sd_err("Failed to write flags of onode %s", onode->name);
+	/* write mtime for onode */
+	onode->mtime = get_seconds();
+	offset = offsetof(struct kv_onode, mtime);
+	ret = sd_write_object(onode->oid, (char *)onode + offset,
+			      sizeof(uint64_t), offset, false);
+	if (ret != SD_RES_SUCCESS)
+		sd_err("Failed to write mtime of onode %s", onode->name);
 out:
 	return ret;
 }
@@ -1330,6 +1338,8 @@ int kv_read_object_meta(struct http_request *req, const char *account,
 		goto out;
 
 	req->data_length = onode->size;
+	http_request_writef(req, "Created: %s\n",
+			    http_time(onode->ctime));
 	http_request_writef(req, "Last-Modified: %s\n",
 			    http_time(onode->mtime));
 
-- 
1.7.12.4




More information about the sheepdog mailing list