nitpicks around older changes for stale-serving

parent 92940733
...@@ -1242,8 +1242,8 @@ static int cache_ns_tout(lua_State *L) ...@@ -1242,8 +1242,8 @@ static int cache_ns_tout(lua_State *L)
lua_error(L); lua_error(L);
} }
lua_Number interval_lua = lua_tonumber(L, 1); lua_Integer interval_lua = lua_tointeger(L, 1);
if (!(interval_lua >= 0 && interval_lua < UINT_MAX)) { if (!(interval_lua > 0 && interval_lua < UINT_MAX)) {
format_error(L, "invalid interval specified, it must be in range > 0, < " xstr(UINT_MAX)); format_error(L, "invalid interval specified, it must be in range > 0, < " xstr(UINT_MAX));
lua_error(L); lua_error(L);
} }
......
...@@ -125,14 +125,14 @@ ...@@ -125,14 +125,14 @@
* @param table pointer to LRU * @param table pointer to LRU
* @param key_ lookup key * @param key_ lookup key
* @param len_ key lengthkeys * @param len_ key lengthkeys
* @param res pointer to bool to store result of operation * @param is_new pointer to bool to store result of operation
* (true if entry is newly added, false otherwise; can be NULL). * (true if entry is newly added, false otherwise; can be NULL).
* @return pointer to data or NULL (can be even if memory could be allocated!) * @return pointer to data or NULL (can be even if memory could be allocated!)
*/ */
#define lru_get_new(table, key_, len_, res) \ #define lru_get_new(table, key_, len_, is_new) \
(__typeof__((table)->pdata_t)) \ (__typeof__((table)->pdata_t)) \
lru_get_impl(&(table)->lru, (key_), (len_), \ lru_get_impl(&(table)->lru, (key_), (len_), \
sizeof(*(table)->pdata_t), true, res) sizeof(*(table)->pdata_t), true, is_new)
/** /**
* @brief Apply a function to every item in LRU. * @brief Apply a function to every item in LRU.
......
...@@ -94,8 +94,8 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx, ...@@ -94,8 +94,8 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
uint64_t now = kr_now(); uint64_t now = kr_now();
/* Name server is better candidate if it has address record. */ /* Name server is better candidate if it has address record. */
uint8_t *it = pack_head(*addr_set); for (uint8_t *it = pack_head(*addr_set); it != pack_tail(*addr_set);
while (it != pack_tail(*addr_set)) { it = pack_obj_next(it)) {
void *val = pack_obj_val(it); void *val = pack_obj_val(it);
size_t len = pack_obj_len(it); size_t len = pack_obj_len(it);
unsigned favour = 0; unsigned favour = 0;
...@@ -112,10 +112,10 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx, ...@@ -112,10 +112,10 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
} }
if (!is_valid) { if (!is_valid) {
goto get_next_iterator; continue;
} }
/* Get RTT for this address (if known) */ /* Get score for the current address. */
kr_nsrep_rtt_lru_entry_t *cached = rtt_cache ? kr_nsrep_rtt_lru_entry_t *cached = rtt_cache ?
lru_get_try(rtt_cache, val, len) : lru_get_try(rtt_cache, val, len) :
NULL; NULL;
...@@ -167,8 +167,6 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx, ...@@ -167,8 +167,6 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx,
break; break;
} }
} }
get_next_iterator:
it = pack_obj_next(it);
} }
/* At this point, rtt_cache_entry_ptr contains up to KR_NSREP_MAXADDR /* At this point, rtt_cache_entry_ptr contains up to KR_NSREP_MAXADDR
...@@ -380,7 +378,7 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx) ...@@ -380,7 +378,7 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx)
int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr, int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
unsigned score, kr_nsrep_rtt_lru_t *cache, int umode) unsigned score, kr_nsrep_rtt_lru_t *cache, int umode)
{ {
if (!cache || umode > KR_NS_MAX) { if (!cache || umode > KR_NS_MAX || umode < 0) {
return kr_error(EINVAL); return kr_error(EINVAL);
} }
...@@ -409,15 +407,10 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr, ...@@ -409,15 +407,10 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
if (score <= KR_NS_GLUED) { if (score <= KR_NS_GLUED) {
score = KR_NS_GLUED + 1; score = KR_NS_GLUED + 1;
} }
/* First update is always set unless KR_NS_UPDATE_NORESET mode used. */ /* If there's nothing to update, we reset it unless KR_NS_UPDATE_NORESET
if (is_new_entry) { * mode was requested. New items are zeroed by LRU automatically. */
if (umode == KR_NS_UPDATE_NORESET) { if (is_new_entry && umode != KR_NS_UPDATE_NORESET) {
/* Zero initial value. */ umode = KR_NS_RESET;
cur->score = 0;
} else {
/* Force KR_NS_RESET otherwise. */
umode = KR_NS_RESET;
}
} }
unsigned new_score = 0; unsigned new_score = 0;
/* Update score, by default smooth over last two measurements. */ /* Update score, by default smooth over last two measurements. */
...@@ -428,7 +421,7 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr, ...@@ -428,7 +421,7 @@ int kr_nsrep_update_rtt(struct kr_nsrep *ns, const struct sockaddr *addr,
case KR_NS_RESET: new_score = score; break; case KR_NS_RESET: new_score = score; break;
case KR_NS_ADD: new_score = MIN(KR_NS_MAX_SCORE - 1, cur->score + score); break; case KR_NS_ADD: new_score = MIN(KR_NS_MAX_SCORE - 1, cur->score + score); break;
case KR_NS_MAX: new_score = MAX(cur->score, score); break; case KR_NS_MAX: new_score = MAX(cur->score, score); break;
default: break; default: return kr_error(EINVAL);
} }
/* Score limits */ /* Score limits */
if (new_score > KR_NS_MAX_SCORE) { if (new_score > KR_NS_MAX_SCORE) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment