[sheepdog] [PATCH v1] sheep/http: only read name of kv_onode when iterating

Robin Dong robin.k.dong at gmail.com
Thu Mar 6 08:58:50 CET 2014


From: root <root at localhost.localdomain>

In object_iterater() it read whole length of SD_DATA_OBJ_SIZE data for
onode which is not necessary and will hurt performance badly.
We only need to read out the 'name' of onode.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/http/kv.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index 7570edf..ff3bfd8 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -458,15 +458,16 @@ static void object_iterater(struct sd_index *idx, void *arg, int ignore)
 {
 	struct object_iterater_arg *oiarg = arg;
 	struct kv_onode *onode = NULL;
-	uint64_t oid;
+	uint64_t oid, read_size;
 	int ret;
 
 	if (!idx->vdi_id)
 		goto out;
 
-	onode = xmalloc(SD_DATA_OBJ_SIZE);
+	read_size = offsetof(struct kv_onode, name) + sizeof(onode->name);
+	onode = xmalloc(read_size);
 	oid = vid_to_data_oid(idx->vdi_id, idx->idx);
-	ret = sd_read_object(oid, (char *)onode, SD_DATA_OBJ_SIZE, 0);
+	ret = sd_read_object(oid, (char *)onode, read_size, 0);
 	if (ret != SD_RES_SUCCESS) {
 		sd_err("Failed to read data object %"PRIx64, oid);
 		goto out;
-- 
1.7.1




More information about the sheepdog mailing list