[sheepdog] [PATCH] sheep/http: make kv_delete_object more safe

Liu Yuan namei.unix at gmail.com
Thu Dec 26 13:22:46 CET 2013


We should reverse the order to delete the onode compared to create the onode

    deletion              creation
-----------------------------------------
1 delete onode           update bnode
2 update bnode           creat the onode

For deletion, if (1) fails, we don't update bnode, so bnode is consistent.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/http/kv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index 3bb8a1d..e75d1d1 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -1033,7 +1033,8 @@ int kv_create_object(struct http_request *req, const char *account,
 
 	ret = bnode_update(account, bucket, req->data_length, true);
 	if (ret != SD_RES_SUCCESS) {
-		ret = onode_delete(onode);
+		sd_err("failed to update bucket for %s", name);
+		onode_delete(onode);
 		goto out;
 	}
 out:
@@ -1086,18 +1087,19 @@ int kv_delete_object(const char *account, const char *bucket, const char *name)
 	if (ret != SD_RES_SUCCESS)
 		goto out;
 
-	ret = onode_delete(onode);
-	if (ret != SD_RES_SUCCESS)
+	ret = bnode_update(account, bucket, onode->size, false);
+	if (ret != SD_RES_SUCCESS) {
+		sd_err("failed to update bnode for %s", name);
 		goto out;
+	}
 
-	/*
-	 * If bnode is deleted successfully, we consider it successful deletion
-	 * even if bnode_update() fails.
-	 *
-	 * FIXME: make bnode metadata consistent
-	 */
-	if (bnode_update(account, bucket, onode->size, false) != SD_RES_SUCCESS)
-		sd_err("failed to update bnode for %s/%s", account, bucket);
+	ret = onode_delete(onode);
+	if (ret != SD_RES_SUCCESS) {
+		if (bnode_update(account, bucket, onode->size, true)
+		    != SD_RES_SUCCESS)
+			sd_err("failed to update bnode for %s", name);
+		goto out;
+	}
 out:
 	free(onode);
 	return ret;
-- 
1.8.1.2




More information about the sheepdog mailing list