From: levin li <[email protected]>

Signed-off-by: levin li <[email protected]>
---
 sheep/farm/trunk.c   |    8 ++++++--
 sheep/group.c        |   16 ++++++++--------
 sheep/object_cache.c |    8 ++++++--
 sheep/sheep_priv.h   |    1 +
 4 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index 6725c47..2a38c4c 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -282,10 +282,14 @@ static struct omap_entry *omap_file_insert(struct strbuf 
*buf, struct omap_entry
 
 static int oid_stale(uint64_t oid)
 {
-       int i, vidx;
+       int i, vidx, copies;
        struct sd_vnode *vnodes = sys->vnodes;
 
-       for (i = 0; i < sys->nr_sobjs; i++) {
+       copies = sys->nr_sobjs;
+       if (copies > sys->nr_zones)
+               copies = sys->nr_zones;
+
+       for (i = 0; i < copies; i++) {
                vidx = obj_to_sheep(vnodes, sys->nr_vnodes, oid, i);
                if (is_myself(vnodes[vidx].addr, vnodes[vidx].port))
                        return 0;
diff --git a/sheep/group.c b/sheep/group.c
index 65933c5..62824ae 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -162,7 +162,7 @@ int get_ordered_sd_vnode_list(struct sd_vnode **entries,
                return SD_RES_NO_MEM;
        }
 
-       cache->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+       cache->nr_zones = sys->nr_zones;
        memcpy(cache->vnodes, sys->vnodes, sizeof(sys->vnodes[0]) * 
sys->nr_vnodes);
        cache->nr_vnodes = sys->nr_vnodes;
        cache->epoch = sys->epoch;
@@ -589,6 +589,8 @@ join_finished:
        qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
        sys->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
                                         sys->vnodes);
+       sys->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+
        if (msg->cluster_status == SD_STATUS_OK ||
            msg->cluster_status == SD_STATUS_HALT) {
                if (msg->inc_epoch) {
@@ -843,9 +845,7 @@ static void __sd_join_done(struct cpg_event *cevent)
        }
 
        if (sys_stat_halt()) {
-               int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-
-               if (nr_zones >= sys->nr_sobjs)
+               if (sys->nr_zones >= sys->nr_sobjs)
                        sys_stat_set(SD_STATUS_OK);
        }
 
@@ -863,6 +863,8 @@ static void __sd_leave_done(struct cpg_event *cevent)
        qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
        sys->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
                                         sys->vnodes);
+       sys->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+
        if (sys_can_recover()) {
                sys->epoch++;
                update_epoch_store(sys->epoch);
@@ -875,9 +877,7 @@ static void __sd_leave_done(struct cpg_event *cevent)
                start_recovery(sys->epoch);
 
        if (sys_can_halt()) {
-               int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-
-               if (nr_zones < sys->nr_sobjs)
+               if (sys->nr_zones < sys->nr_sobjs)
                        sys_stat_set(SD_STATUS_HALT);
        }
 }
@@ -1008,7 +1008,7 @@ int is_access_to_busy_objects(uint64_t oid)
                        continue;
                }
                if (oid == req->local_oid)
-                               return 1;
+                       return 1;
        }
        return 0;
 }
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index e370647..b5bf223 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -292,7 +292,7 @@ out:
 /* Fetch the object, cache it in success */
 int object_cache_pull(struct object_cache *oc, uint32_t idx)
 {
-       int i, n = 0, fd, ret = SD_RES_NO_MEM;
+       int i, n = 0, fd, ret = SD_RES_NO_MEM, copies;
        unsigned wlen = 0, rlen, data_length, read_len;
        uint64_t oid = oc->oid;
        struct sd_obj_req hdr = { 0 };
@@ -311,8 +311,12 @@ int object_cache_pull(struct object_cache *oc, uint32_t 
idx)
                goto out;
        }
 
+       copies = sys->nr_sobjs;
+       if (copies > sys->nr_zones)
+               copies = sys->nr_zones;
+
        /* Check if we can read locally */
-       for (i = 0; i < sys->nr_sobjs; i++) {
+       for (i = 0; i < copies; i++) {
                n = obj_to_sheep(vnodes, sys->nr_vnodes, oid, i);
                if (is_myself(vnodes[n].addr, vnodes[n].port)) {
                        struct siocb iocb = { 0 };
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 7dbfab2..311c95f 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -137,6 +137,7 @@ struct cluster_info {
        struct list_head blocking_conn_list;
 
        uint32_t nr_sobjs;
+       int nr_zones;
 
        struct list_head cpg_event_siblings;
        struct cpg_event *cur_cevent;
-- 
1.7.1

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to