From 7b49123c1e71c28e98bb2e4162df72426f2338d4 Mon Sep 17 00:00:00 2001 From: Andrew Gooding Date: Wed, 5 Dec 2018 11:05:31 -0800 Subject: [PATCH] Minor refactor - don't search replicas array unless necessary. --- as/src/fabric/partition.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/as/src/fabric/partition.c b/as/src/fabric/partition.c index 71831a32..14534483 100644 --- a/as/src/fabric/partition.c +++ b/as/src/fabric/partition.c @@ -293,14 +293,12 @@ as_partition_get_replica_stats(as_namespace* ns, repl_stats* p_stats) cf_mutex_lock(&p->lock); - int self_n = find_self_in_replicas(p); // -1 if not - if (g_config.self_node == p->working_master) { accumulate_replica_stats(p, &p_stats->n_master_objects, &p_stats->n_master_tombstones); } - else if (self_n >= 0) { + else if (find_self_in_replicas(p) >= 0) { // -1 if not accumulate_replica_stats(p, &p_stats->n_prole_objects, &p_stats->n_prole_tombstones); @@ -784,9 +782,7 @@ partition_getreplica_prole(as_namespace* ns, uint32_t pid) char partition_descriptor(const as_partition* p) { - int self_n = find_self_in_replicas(p); // -1 if not - - if (self_n >= 0) { + if (find_self_in_replicas(p) >= 0) { // -1 if not return p->pending_immigrations == 0 ? 'S' : 'D'; } @@ -802,12 +798,12 @@ partition_get_replica_self_lockfree(const as_namespace* ns, uint32_t pid) { const as_partition* p = &ns->partitions[pid]; - int self_n = find_self_in_replicas(p); // -1 if not - if (g_config.self_node == p->working_master) { return 0; } + int self_n = find_self_in_replicas(p); // -1 if not + if (self_n > 0 && p->pending_immigrations == 0 && // Check self_n < n_repl only because n_repl could be out-of-sync // with (less than) partition's replica list count.