[sheepdog] [PATCH RESEND 6/6] farm: avoid of reading object which already exists

Kai Zhang kyle at zelin.io
Wed Jun 5 12:35:14 CEST 2013


Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 collie/cluster.c        |    3 ++-
 collie/farm/farm.c      |   10 ++++++++++
 collie/farm/sha1_file.c |    2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index e7984b6..31b7f84 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -444,7 +444,8 @@ static int cluster_recover(int argc, char **argv)
 /* Subcommand list of snapshot */
 static struct subcommand cluster_snapshot_cmd[] = {
 	{"save", NULL, "h", "save snapshot to localpath",
-	 NULL, SUBCMD_FLAG_NEED_ARG, save_snapshot, NULL},
+	 NULL, SUBCMD_FLAG_NEED_ARG|SUBCMD_FLAG_NEED_NODELIST,
+	 save_snapshot, NULL},
 	{"list", NULL, "h", "list snapshot of localpath",
 	 NULL, SUBCMD_FLAG_NEED_ARG, list_snapshot, NULL},
 	{"load", NULL, "h", "list snapshot of localpath",
diff --git a/collie/farm/farm.c b/collie/farm/farm.c
index cb14c8b..7f895a7 100644
--- a/collie/farm/farm.c
+++ b/collie/farm/farm.c
@@ -222,11 +222,21 @@ static void do_save_object(struct work *work)
 	void *buf;
 	size_t size;
 	struct snapshot_work *sw;
+	unsigned char object_sha1[SHA1_LEN];
 
 	if (uatomic_is_true(&work_error))
 		return;
 
 	sw = container_of(work, struct snapshot_work, work);
+
+	/* read object sha1 and check if exists in local path */
+	if (sd_read_object_sha1(sw->entry.oid, sd_epoch, sw->entry.nr_copies,
+				object_sha1) == 0 &&
+	    sha1_file_exist(object_sha1)) {
+		memcpy(sw->entry.sha1, object_sha1, SHA1_LEN);
+		return;
+	}
+
 	size = get_objsize(sw->entry.oid);
 	buf = xmalloc(size);
 
diff --git a/collie/farm/sha1_file.c b/collie/farm/sha1_file.c
index bc79226..1ccd2b3 100644
--- a/collie/farm/sha1_file.c
+++ b/collie/farm/sha1_file.c
@@ -175,7 +175,7 @@ static int verify_sha1_file(const unsigned char *sha1,
 	get_sha1_trim(buf, len, tmp);
 	if (memcmp((char *)tmp, (char *)sha1, SHA1_LEN) != 0) {
 		fprintf(stderr, "failed, %s != %s\n", sha1_to_hex(sha1),
-			   sha1_to_hex(tmp));
+			sha1_to_hex(tmp));
 		return -1;
 	}
 	return 0;
-- 
1.7.1




More information about the sheepdog mailing list