[sheepdog] [PATCH 4/6] object cache: fix add oid to object list race
Liu Yuan
namei.unix at gmail.com
Wed Aug 1 12:03:48 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
When there are multiple thread calling object_cache_pull(), they all will return
success even though there is only one thread that can actually create the object.
Then we should only add oid to object list once.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
include/sheepdog_proto.h | 1 +
sheep/object_cache.c | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 45a4b81..9e66769 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -68,6 +68,7 @@
#define SD_RES_CLUSTER_RECOVERING 0x22 /* Cluster is recovering. */
#define SD_RES_OBJ_RECOVERING 0x23 /* Object is recovering */
#define SD_RES_KILLED 0x24 /* Node is killed */
+#define SD_RES_OID_EXIST 0x25 /* Object ID exists already */
/* errors above 0x80 are sheepdog-internal */
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 5e709c2..e34b12e 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -692,7 +692,8 @@ out:
static int create_cache_object(struct object_cache *oc, uint32_t idx,
void *buffer, size_t buf_size)
{
- int flags = def_open_flags | O_CREAT | O_EXCL, fd, ret = SD_RES_SUCCESS;
+ int flags = def_open_flags | O_CREAT | O_EXCL, fd;
+ int ret = SD_RES_OID_EXIST;
struct strbuf buf;
strbuf_init(&buf, PATH_MAX);
@@ -771,6 +772,8 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
ret = create_cache_object(oc, idx, buf, data_length);
if (ret == SD_RES_SUCCESS)
add_to_object_cache(oc, idx, 0);
+ else if (ret == SD_RES_OID_EXIST)
+ ret = SD_RES_SUCCESS;
}
free(buf);
out:
--
1.7.10.2
More information about the sheepdog
mailing list