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

Robin Dong robin.k.dong at gmail.com
Fri Feb 21 07:47:33 CET 2014


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;
+	}
 out:
 	free(onode);
 	return ret;
diff --git a/sheep/http/swift.c b/sheep/http/swift.c
index 7b9685a..6b07d01 100644
--- a/sheep/http/swift.c
+++ b/sheep/http/swift.c
@@ -210,6 +210,9 @@ static void swift_head_object(struct http_request *req, const char *account,
 	case SD_RES_NO_OBJ:
 		http_response_header(req, NOT_FOUND);
 		break;
+	case SD_RES_EIO:
+		http_response_header(req, PARTIAL_CONTENT);
+		break;
 	default:
 		http_response_header(req, INTERNAL_SERVER_ERROR);
 		break;
-- 
1.7.12.4




More information about the sheepdog mailing list