[sheepdog] [PATCH v2 5/6] sheep/http: add FORCE_DELETE to delete 'incompleted' object

Robin Dong robin.k.dong at gmail.com
Tue Feb 25 07:07:23 CET 2014


From: Robin Dong <sanbai at taobao.com>

Since sheep will only return 'CONFLICT' for a DELETE request to 'incompleted' object,
we need a 'FORCE_DELETE' to really remove the 'incompleted' object and free its
allocated space.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/http/http.c  |  5 +++++
 sheep/http/http.h  |  5 ++++-
 sheep/http/kv.c    |  5 +++--
 sheep/http/s3.c    |  2 +-
 sheep/http/swift.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/sheep/http/http.c b/sheep/http/http.c
index 6a04252..e742a85 100644
--- a/sheep/http/http.c
+++ b/sheep/http/http.c
@@ -30,6 +30,7 @@ static inline const char *stropcode(enum http_opcode opcode)
 		[HTTP_PUT] = "PUT",
 		[HTTP_POST] = "POST",
 		[HTTP_DELETE] = "DELETE",
+		[HTTP_FORCE_DELETE] = "FORCE_DELETE",
 		[HTTP_HEAD] = "HEAD",
 	};
 
@@ -152,6 +153,8 @@ static int request_init_operation(struct http_request *req)
 		req->opcode = HTTP_POST;
 	} else if (!strcmp(p, "DELETE")) {
 		req->opcode = HTTP_DELETE;
+	} else if (!strcmp(p, "FORCE_DELETE")) {
+		req->opcode = HTTP_FORCE_DELETE;
 	} else if (!strcmp(p, "HEAD")) {
 		req->opcode = HTTP_HEAD;
 	} else {
@@ -263,6 +266,8 @@ static void http_run_request(struct work *work)
 		case HTTP_DELETE:
 			method = hdrv->delete;
 			break;
+		case HTTP_FORCE_DELETE:
+			method = hdrv->force_delete;
 		default:
 			break;
 		}
diff --git a/sheep/http/http.h b/sheep/http/http.h
index 5bcd528..87833e9 100644
--- a/sheep/http/http.h
+++ b/sheep/http/http.h
@@ -21,6 +21,7 @@ enum http_opcode {
 	HTTP_PUT,
 	HTTP_POST,
 	HTTP_DELETE,
+	HTTP_FORCE_DELETE,
 	HTTP_HEAD,
 };
 
@@ -62,6 +63,7 @@ struct http_driver {
 	void (*put)(struct http_request *req);
 	void (*post)(struct http_request *req);
 	void (*delete)(struct http_request *req);
+	void (*force_delete)(struct http_request *req);
 
 	struct list_node list;
 };
@@ -146,7 +148,8 @@ int kv_read_object(struct http_request *req, const char *account,
 		   const char *bucket, const char *object);
 int kv_read_object_meta(struct http_request *req, const char *account,
 			const char *bucket, const char *object);
-int kv_delete_object(const char *account, const char *bucket, const char *);
+int kv_delete_object(const char *account, const char *bucket, const char *,
+		     bool force);
 int kv_iterate_object(const char *account, const char *bucket,
 		      void (*cb)(const char *object, void *opaque),
 		      void *opaque);
diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index 4e1f0c6..da73338 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -1200,7 +1200,8 @@ out:
 	return ret;
 }
 
-int kv_delete_object(const char *account, const char *bucket, const char *name)
+int kv_delete_object(const char *account, const char *bucket, const char *name,
+		     bool force)
 {
 	char vdi_name[SD_MAX_VDI_LEN];
 	uint32_t bucket_vid;
@@ -1218,7 +1219,7 @@ int kv_delete_object(const char *account, const char *bucket, const char *name)
 		goto out;
 
 	/* this object has not been uploaded complete */
-	if (onode->flags != ONODE_COMPLETE) {
+	if (!force && onode->flags != ONODE_COMPLETE) {
 		ret = SD_RES_INCOMPLETE;
 		goto out;
 	}
diff --git a/sheep/http/s3.c b/sheep/http/s3.c
index aab1d1c..bf7b311 100644
--- a/sheep/http/s3.c
+++ b/sheep/http/s3.c
@@ -137,7 +137,7 @@ static void s3_post_object(struct http_request *req, const char *bucket,
 static void s3_delete_object(struct http_request *req, const char *bucket,
 			     const char *object)
 {
-	kv_delete_object("s3", bucket, object);
+	kv_delete_object("s3", bucket, object, 0);
 
 	if (req->status == NOT_FOUND)
 		s3_write_err_response(req, "NoSuchKey",
diff --git a/sheep/http/swift.c b/sheep/http/swift.c
index aff0f09..8071299 100644
--- a/sheep/http/swift.c
+++ b/sheep/http/swift.c
@@ -94,6 +94,12 @@ static void swift_delete_account(struct http_request *req, const char *account)
 	}
 }
 
+static void swift_force_delete_account(struct http_request *req,
+				       const char *account)
+{
+	http_response_header(req, NOT_IMPLEMENTED);
+}
+
 /* Operations on Containers */
 
 static void swift_head_container(struct http_request *req, const char *account,
@@ -194,6 +200,13 @@ static void swift_delete_container(struct http_request *req,
 	}
 }
 
+static void swift_force_delete_container(struct http_request *req,
+					 const char *account,
+					 const char *container)
+{
+	http_response_header(req, NOT_IMPLEMENTED);
+}
+
 /* Operations on Objects */
 
 static void swift_head_object(struct http_request *req, const char *account,
@@ -280,7 +293,7 @@ static void swift_delete_object(struct http_request *req, const char *account,
 {
 	int ret;
 
-	ret = kv_delete_object(account, container, object);
+	ret = kv_delete_object(account, container, object, 0);
 	switch (ret) {
 	case SD_RES_SUCCESS:
 		http_response_header(req, NO_CONTENT);
@@ -298,6 +311,27 @@ static void swift_delete_object(struct http_request *req, const char *account,
 	}
 }
 
+static void swift_force_delete_object(struct http_request *req,
+				      const char *account,
+				      const char *container, const char *object)
+{
+	int ret;
+
+	ret = kv_delete_object(account, container, object, 1);
+	switch (ret) {
+	case SD_RES_SUCCESS:
+		http_response_header(req, NO_CONTENT);
+		break;
+	case SD_RES_NO_VDI:
+	case SD_RES_NO_OBJ:
+		http_response_header(req, NOT_FOUND);
+		break;
+	default:
+		http_response_header(req, INTERNAL_SERVER_ERROR);
+		break;
+	}
+}
+
 /* Swift driver interfaces */
 
 static int swift_init(const char *option)
@@ -381,6 +415,13 @@ static void swift_delete(struct http_request *req)
 			     swift_delete_object);
 }
 
+static void swift_force_delete(struct http_request *req)
+{
+	swift_handle_request(req, swift_force_delete_account,
+			     swift_force_delete_container,
+			     swift_force_delete_object);
+}
+
 static struct http_driver hdrv_swift = {
 	.name	= "swift",
 
@@ -390,6 +431,7 @@ static struct http_driver hdrv_swift = {
 	.put	= swift_put,
 	.post	= swift_post,
 	.delete	= swift_delete,
+	.force_delete = swift_force_delete,
 };
 
 hdrv_register(hdrv_swift);
-- 
1.7.12.4




More information about the sheepdog mailing list