Skip to content

Commit

Permalink
Move select_loadbalance and select_failover logic into their own func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
luke-jr committed Nov 5, 2014
1 parent 6c03a3b commit 16a58f8
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -5444,36 +5444,16 @@ static struct pool *select_balanced(struct pool *cp)
return ret;
}

static bool pool_active(struct pool *, bool pinging);
static void pool_died(struct pool *);
static struct pool *priority_pool(int choice);
static bool pool_unusable(struct pool *pool);

/* Select any active pool in a rotating fashion when loadbalance is chosen if
* it has any quota left. */
static inline struct pool *select_pool(bool lagging)
static
struct pool *select_loadbalance()
{
static int rotating_pool = 0;
struct pool *pool, *cp;
struct pool *pool;
bool avail = false;
int tested, i;

retry:
cp = current_pool();

if (pool_strategy == POOL_BALANCE) {
pool = select_balanced(cp);
if (pool_unworkable(pool))
goto simple_failover;
goto out;
}

if (pool_strategy != POOL_LOADBALANCE && (!lagging || opt_fail_only)) {
pool = cp;
goto out;
} else
pool = NULL;

for (i = 0; i < total_pools; i++) {
struct pool *tp = pools[i];

Expand All @@ -5492,6 +5472,7 @@ static inline struct pool *select_pool(bool lagging)
}

/* Try to find the first pool in the rotation that is usable */
pool = NULL;
tested = 0;
while (!pool && tested++ < total_pools) {
pool = pools[rotating_pool];
Expand All @@ -5507,19 +5488,58 @@ static inline struct pool *select_pool(bool lagging)
if (++rotating_pool >= total_pools)
rotating_pool = 0;
}

return pool;
}

static bool pool_unusable(struct pool *pool);

static
struct pool *select_failover()
{
int i;

for (i = 0; i < total_pools; i++) {
struct pool *tp = priority_pool(i);

if (!pool_unusable(tp)) {
return tp;
}
}

return NULL;
}

static bool pool_active(struct pool *, bool pinging);
static void pool_died(struct pool *);

/* Select any active pool in a rotating fashion when loadbalance is chosen if
* it has any quota left. */
static inline struct pool *select_pool(bool lagging)
{
struct pool *pool, *cp;

retry:
cp = current_pool();

if (pool_strategy == POOL_BALANCE) {
pool = select_balanced(cp);
if (pool_unworkable(pool))
goto simple_failover;
goto out;
}

if (pool_strategy != POOL_LOADBALANCE && (!lagging || opt_fail_only)) {
pool = cp;
goto out;
} else
pool = select_loadbalance();

simple_failover:
/* If there are no alive pools with quota, choose according to
* priority. */
if (!pool) {
for (i = 0; i < total_pools; i++) {
struct pool *tp = priority_pool(i);

if (!pool_unusable(tp)) {
pool = tp;
break;
}
}
pool = select_failover();
}

/* If still nothing is usable, use the current pool */
Expand Down

0 comments on commit 16a58f8

Please sign in to comment.