Skip to content

Commit

Permalink
Minor refactor - don't search replicas array unless necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
gooding470 committed Dec 5, 2018
1 parent 6b35a89 commit 586fc5b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions as/src/fabric/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,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);
Expand Down Expand Up @@ -726,9 +724,7 @@ partition_reserve_lockfree(as_partition* p, as_namespace* ns,
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';
}

Expand All @@ -744,12 +740,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.
Expand Down

0 comments on commit 586fc5b

Please sign in to comment.