[sheepdog] [PATCH v2 03/21] sheep: make stale object erasure aware

Liu Yuan namei.unix at gmail.com
Wed Oct 16 07:50:29 CEST 2013


Replica with different ec_index should be considered stale.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/plain_store.c |   32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 0eb955a..2c9b6ef 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -311,6 +311,15 @@ static int set_erasure_index(const char *path, uint8_t idx)
 	return 0;
 }
 
+static int get_erasure_index(const char *path, uint8_t *idx)
+{
+	if (getxattr(path, ECNAME, idx, ECSIZE) < 0) {
+		sd_err("failed to getxattr %s, %m", path);
+		return -1;
+	}
+	return 0;
+}
+
 int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 {
 	char path[PATH_MAX], tmp_path[PATH_MAX];
@@ -409,9 +418,17 @@ out:
 	return SD_RES_SUCCESS;
 }
 
+/*
+ * For replicated object, if any of the replica belongs to this node, we
+ * consider it not stale.
+ *
+ * For erasured object, since every copy is unique and if it migrates to other
+ * node(index gets changed even it has some other copy belongs to it) because
+ * of hash ring changes, we consider it stale.
+ */
 static bool oid_stale(uint64_t oid)
 {
-	int i, nr_copies;
+	uint32_t i, nr_copies;
 	struct vnode_info *vinfo;
 	const struct sd_vnode *v;
 	bool ret = true;
@@ -424,7 +441,18 @@ static bool oid_stale(uint64_t oid)
 	for (i = 0; i < nr_copies; i++) {
 		v = obj_vnodes[i];
 		if (vnode_is_local(v)) {
-			ret = false;
+			if (is_erasure_oid(oid)) {
+				char path[PATH_MAX];
+				uint8_t idx;
+
+				get_obj_path(oid, path, sizeof(path));
+				if (get_erasure_index(path, &idx) < 0)
+					break;
+				if (idx == i)
+					ret = false;
+			} else {
+				ret = false;
+			}
 			break;
 		}
 	}
-- 
1.7.9.5




More information about the sheepdog mailing list