[sheepdog] [PATCH 2/2] sheep: get current nodes and vnodes from cache

yaohaiting.wujue at gmail.com yaohaiting.wujue at gmail.com
Fri May 25 10:28:29 CEST 2012


From: HaiTing Yao <wujue.yht at taobao.com>

Initialize the recovery work, no need to read current nodes from disk.

Signed-off-by: HaiTing Yao <wujue.yht at taobao.com>
---
 sheep/recovery.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/sheep/recovery.c b/sheep/recovery.c
index 72a9797..640e8b8 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -634,11 +634,22 @@ again:
 static int init_rw(struct recovery_work *rw)
 {
 	uint32_t epoch = rw->epoch;
-
-	rw->cur_nr_nodes = epoch_log_read_nr(epoch, (char *)rw->cur_nodes,
-					     sizeof(rw->cur_nodes));
-	qsort(rw->cur_nodes, rw->cur_nr_nodes, sizeof(struct sd_node),
-		  node_cmp);
+	struct vnode_info *vnodes;
+
+	if (epoch == sys->epoch) {
+		rw->cur_nr_nodes = sys->nr_nodes;
+		memcpy(rw->cur_nodes, sys->nodes, sizeof(rw->cur_nodes));
+		vnodes = get_vnode_info();
+		rw->cur_nr_vnodes = vnodes->nr_vnodes;
+		memcpy(rw->cur_vnodes, vnodes->entries, sizeof(rw->cur_vnodes));
+	} else {
+		rw->cur_nr_nodes = epoch_log_read_nr(epoch,
+			(char *)rw->cur_nodes, sizeof(rw->cur_nodes));
+		qsort(rw->cur_nodes, rw->cur_nr_nodes, sizeof(struct sd_node),
+			node_cmp);
+		rw->cur_nr_vnodes = nodes_to_vnodes(rw->cur_nodes,
+			rw->cur_nr_nodes, rw->cur_vnodes);
+	}
 
 	if (rw->cur_nr_nodes <= 0) {
 		eprintf("failed to read epoch log for epoch %"PRIu32"\n", epoch);
@@ -653,8 +664,6 @@ static int init_rw(struct recovery_work *rw)
 	}
 	rw->old_nr_vnodes = nodes_to_vnodes(rw->old_nodes, rw->old_nr_nodes,
 					    rw->old_vnodes);
-	rw->cur_nr_vnodes = nodes_to_vnodes(rw->cur_nodes, rw->cur_nr_nodes,
-					    rw->cur_vnodes);
 
 	return 0;
 }
-- 
1.7.1




More information about the sheepdog mailing list