Skip to content
Snippets Groups Projects
Commit f72135c8 authored by Tomas Krizek's avatar Tomas Krizek
Browse files

Merge branch 'cache-stale-readers' into 'master'

cache: clear any stale readers when opening cache

See merge request !1172
parents c78ecf8c 39d37327
No related branches found
No related tags found
1 merge request!1172cache: clear any stale readers when opening cache
Pipeline #80678 passed
......@@ -10,6 +10,7 @@ Bugfixes
- dnstap module: fix repeated configuration (!1168)
- validator: fix SERVFAIL for some rare dynamic proofs (!1166)
- fix SIGBUS on uncommon ARM machines (unaligned access; !1167, #426)
- cache: better resilience on abnormal termination/restarts (!1172)
Knot Resolver 5.3.1 (2021-03-31)
......
......@@ -124,6 +124,18 @@ static int refresh_mapsize(struct lmdb_env *env)
return kr_ok();
}
static void clear_stale_readers(struct lmdb_env *env)
{
int cleared;
int ret = mdb_reader_check(env->env, &cleared);
if (ret != MDB_SUCCESS) {
kr_log_error("[cache] failed to clear stale reader locks: "
"LMDB error %d %s\n", ret, mdb_strerror(ret));
} else if (cleared != 0) {
kr_log_info("[cache] cleared %d stale reader locks\n", cleared);
}
}
#define FLAG_RENEW (2*MDB_RDONLY)
/** mdb_txn_begin or _renew + handle retries in some situations
*
......@@ -154,13 +166,7 @@ static int txn_get_noresize(struct lmdb_env *env, unsigned int flag, MDB_txn **t
if (ret == 0)
goto retry;
} else if (unlikely(ret == MDB_READERS_FULL)) {
int cleared;
ret = mdb_reader_check(env->env, &cleared);
if (ret == MDB_SUCCESS)
kr_log_info("[cache] cleared %d stale reader locks\n", cleared);
else
kr_log_error("[cache] failed to clear stale reader locks: "
"LMDB error %d %s\n", ret, mdb_strerror(ret));
clear_stale_readers(env);
goto retry;
}
return ret;
......@@ -389,6 +395,11 @@ static int cdb_open_env(struct lmdb_env *env, const char *path, const size_t map
ret = mdb_txn_commit(txn);
if (ret != MDB_SUCCESS) goto error_mdb;
/* Stale RO transactions could have been left behind by a cashing process
* (e.g. one whose termination lead to spawning the current one).
* According to docs they might hold onto some space until we clear them. */
clear_stale_readers(env);
return kr_ok();
error_mdb:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment