Browse Source

Add failover_only pool flag, to avoid using it regardless of strategy

Ignored by failover and loadbalance strategies (use priority and quota for those)
Luke Dashjr 11 years ago
parent
commit
1734789459
3 changed files with 35 additions and 7 deletions
  1. 6 1
      api.c
  2. 28 6
      miner.c
  3. 1 0
      miner.h

+ 6 - 1
api.c

@@ -1899,6 +1899,9 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 			case POOL_ENABLED:
 			case POOL_ENABLED:
 				if (pool->idle)
 				if (pool->idle)
 					status = (char *)DEAD;
 					status = (char *)DEAD;
+				else
+				if (pool->failover_only)
+					status = "Failover";
 				else
 				else
 					status = (char *)ALIVE;
 					status = (char *)ALIVE;
 				break;
 				break;
@@ -2324,6 +2327,7 @@ static void switchpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
 	}
 	}
 
 
 	pool = pools[id];
 	pool = pools[id];
+	pool->failover_only = false;
 	pool->enabled = POOL_ENABLED;
 	pool->enabled = POOL_ENABLED;
 	cg_runlock(&control_lock);
 	cg_runlock(&control_lock);
 	switch_pools(pool);
 	switch_pools(pool);
@@ -2437,11 +2441,12 @@ static void enablepool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
 	}
 	}
 
 
 	pool = pools[id];
 	pool = pools[id];
-	if (pool->enabled == POOL_ENABLED) {
+	if (pool->enabled == POOL_ENABLED && !pool->failover_only) {
 		message(io_data, MSG_ALRENAP, id, NULL, isjson);
 		message(io_data, MSG_ALRENAP, id, NULL, isjson);
 		return;
 		return;
 	}
 	}
 
 
+	pool->failover_only = false;
 	pool->enabled = POOL_ENABLED;
 	pool->enabled = POOL_ENABLED;
 	if (pool->prio < current_pool()->prio)
 	if (pool->prio < current_pool()->prio)
 		switch_pools(pool);
 		switch_pools(pool);

+ 28 - 6
miner.c

@@ -4798,18 +4798,25 @@ static struct pool *_select_longpoll_pool(struct pool *, bool(*)(struct pool *))
 static struct pool *select_balanced(struct pool *cp)
 static struct pool *select_balanced(struct pool *cp)
 {
 {
 	int i, lowest = cp->shares;
 	int i, lowest = cp->shares;
-	struct pool *ret = cp;
+	struct pool *ret = cp, *failover_pool = NULL;
 
 
 	for (i = 0; i < total_pools; i++) {
 	for (i = 0; i < total_pools; i++) {
 		struct pool *pool = pools[i];
 		struct pool *pool = pools[i];
 
 
 		if (pool_unworkable(pool))
 		if (pool_unworkable(pool))
 			continue;
 			continue;
+		if (pool->failover_only)
+		{
+			BFGINIT(failover_pool, pool);
+			continue;
+		}
 		if (pool->shares < lowest) {
 		if (pool->shares < lowest) {
 			lowest = pool->shares;
 			lowest = pool->shares;
 			ret = pool;
 			ret = pool;
 		}
 		}
 	}
 	}
+	if (pool_unworkable(ret) && failover_pool)
+		ret = failover_pool;
 
 
 	ret->shares++;
 	ret->shares++;
 	return ret;
 	return ret;
@@ -4834,6 +4841,8 @@ static inline struct pool *select_pool(bool lagging)
 retry:
 retry:
 	if (pool_strategy == POOL_BALANCE) {
 	if (pool_strategy == POOL_BALANCE) {
 		pool = select_balanced(cp);
 		pool = select_balanced(cp);
+		if (pool_unworkable(pool))
+			goto simple_failover;
 		goto out;
 		goto out;
 	}
 	}
 
 
@@ -4877,6 +4886,7 @@ retry:
 			rotating_pool = 0;
 			rotating_pool = 0;
 	}
 	}
 
 
+simple_failover:
 	/* If there are no alive pools with quota, choose according to
 	/* If there are no alive pools with quota, choose according to
 	 * priority. */
 	 * priority. */
 	if (!pool) {
 	if (!pool) {
@@ -6320,7 +6330,7 @@ static bool pool_unusable(struct pool *pool)
 
 
 void switch_pools(struct pool *selected)
 void switch_pools(struct pool *selected)
 {
 {
-	struct pool *pool, *last_pool;
+	struct pool *pool, *last_pool, *failover_pool = NULL;
 	int i, pool_no, next_pool;
 	int i, pool_no, next_pool;
 
 
 	cg_wlock(&control_lock);
 	cg_wlock(&control_lock);
@@ -6368,6 +6378,11 @@ void switch_pools(struct pool *selected)
 				pool = pools[next_pool];
 				pool = pools[next_pool];
 				if (pool_unusable(pool))
 				if (pool_unusable(pool))
 					continue;
 					continue;
+				if (pool->failover_only)
+				{
+					BFGINIT(failover_pool, pool);
+					continue;
+				}
 				pool_no = next_pool;
 				pool_no = next_pool;
 				break;
 				break;
 			}
 			}
@@ -6376,8 +6391,10 @@ void switch_pools(struct pool *selected)
 			break;
 			break;
 	}
 	}
 
 
-	currentpool = pools[pool_no];
-	pool = currentpool;
+	pool = pools[pool_no];
+	if (pool_unusable(pool) && failover_pool)
+		pool = failover_pool;
+	currentpool = pool;
 	mutex_lock(&lp_lock);
 	mutex_lock(&lp_lock);
 	pthread_cond_broadcast(&lp_cond);
 	pthread_cond_broadcast(&lp_cond);
 	mutex_unlock(&lp_lock);
 	mutex_unlock(&lp_lock);
@@ -7187,12 +7204,15 @@ updated:
 
 
 			if (pool == current_pool())
 			if (pool == current_pool())
 				wattron(logwin, A_BOLD);
 				wattron(logwin, A_BOLD);
-			if (pool->enabled != POOL_ENABLED)
+			if (pool->enabled != POOL_ENABLED || pool->failover_only)
 				wattron(logwin, A_DIM);
 				wattron(logwin, A_DIM);
 			wlogprint("%d: ", pool->prio);
 			wlogprint("%d: ", pool->prio);
 			switch (pool->enabled) {
 			switch (pool->enabled) {
 				case POOL_ENABLED:
 				case POOL_ENABLED:
-					wlogprint("Enabled  ");
+					if (pool->failover_only)
+						wlogprint("Failover ");
+					else
+						wlogprint("Enabled  ");
 					break;
 					break;
 				case POOL_DISABLED:
 				case POOL_DISABLED:
 					wlogprint("Disabled ");
 					wlogprint("Disabled ");
@@ -7258,6 +7278,7 @@ retry:
 			goto retry;
 			goto retry;
 		}
 		}
 		pool = pools[selected];
 		pool = pools[selected];
+		pool->failover_only = false;
 		enable_pool(pool);
 		enable_pool(pool);
 		switch_pools(pool);
 		switch_pools(pool);
 		goto updated;
 		goto updated;
@@ -7283,6 +7304,7 @@ retry:
 			goto retry;
 			goto retry;
 		}
 		}
 		pool = pools[selected];
 		pool = pools[selected];
+		pool->failover_only = false;
 		enable_pool(pool);
 		enable_pool(pool);
 		if (pool->prio < current_pool()->prio)
 		if (pool->prio < current_pool()->prio)
 			switch_pools(pool);
 			switch_pools(pool);

+ 1 - 0
miner.h

@@ -1248,6 +1248,7 @@ struct pool {
 	bool probed;
 	bool probed;
 	int force_rollntime;
 	int force_rollntime;
 	enum pool_enable enabled;
 	enum pool_enable enabled;
+	bool failover_only;  // NOTE: Ignored by failover and loadbalance strategies (use priority and quota respectively)
 	bool submit_old;
 	bool submit_old;
 	bool removed;
 	bool removed;
 	bool lp_started;
 	bool lp_started;