static thread_local int t_cleanCounter = 0;
static thread_local bool t_running; // houseKeeping can get suspended in secpoll, and be restarted, which makes us do duplicate work
static time_t s_last_RC_prune = 0;
+ static time_t s_last_ZTC_prune = 0;
auto luaconfsLocal = g_luaconfs.getLocal();
if (t_last_trustAnchorUpdate == 0 && !luaconfsLocal->trustAnchorFileInfo.fname.empty() && luaconfsLocal->trustAnchorFileInfo.interval != 0) {
}
if (isHandlerThread()) {
- static map<DNSName, RecZoneToCache::State> ztcState;
- for (auto& ztc : luaconfsLocal->ztcConfigs) {
- RecZoneToCache::ZoneToCache(ztc.second, ztcState[ztc.first]);
+ if (now.tv_sec - s_last_ZTC_prune > 60) {
+ s_last_ZTC_prune = now.tv_sec;
+ static map<DNSName, RecZoneToCache::State> ztcStates;
+ RecZoneToCache::maintainStates(luaconfsLocal->ztcConfigs, ztcStates, luaconfsLocal->generation);
+ for (auto& ztc : luaconfsLocal->ztcConfigs) {
+ RecZoneToCache::ZoneToCache(ztc.second, ztcStates.at(ztc.first));
+ }
}
if (now.tv_sec - s_last_RC_prune > 5) {
}
}
+void RecZoneToCache::maintainStates(const map<DNSName, Config>& configs, map<DNSName, State>& states, uint64_t mygeneration)
+{
+ // Delete states that have no config
+ for (auto it = states.begin(); it != states.end();) {
+ if (configs.find(it->first) == configs.end()) {
+ it = states.erase(it);
+ }
+ else {
+ it = ++it;
+ }
+ }
+ // Reset states for which the config generation changed and create new states for new configs
+ for (auto config : configs) {
+ auto state = states.find(config.first);
+ if (state != states.end()) {
+ if (state->second.d_generation != mygeneration) {
+ state->second = {0, 0, mygeneration};
+ }
+ }
+ else {
+ states.emplace(std::make_pair(config.first, State{0, 0, mygeneration}));
+ }
+ }
+}
+
void RecZoneToCache::ZoneToCache(const RecZoneToCache::Config& config, RecZoneToCache::State& state)
{
if (state.d_waittime == 0 && state.d_lastrun > 0) {
log->info("Unable to load zone into cache, will retry", "exception", Logging::Loggable("unknown"), "refresh", Logging::Loggable(state.d_waittime));
}
state.d_lastrun = time(nullptr);
+ return;
}
{
time_t d_lastrun{0};
time_t d_waittime{0};
+ uint64_t d_generation;
};
+ static void maintainStates(const map<DNSName, Config>&, map<DNSName, State>&, uint64_t mygeneration);
static void ZoneToCache(const Config& config, State& state);
};