size_t MemRecursorCache::size()
{
size_t count = 0;
- for (auto& map : d_maps) {
- count += map.d_entriesCount;
+ for (auto& lockGuardedMap : d_maps) {
+ auto map = lock(lockGuardedMap);
+ count += map->d_entriesCount;
}
return count;
}
pair<uint64_t,uint64_t> MemRecursorCache::stats()
{
uint64_t c = 0, a = 0;
- for (auto& map : d_maps) {
- const lock l(map);
- c += map.d_contended_count;
- a += map.d_acquired_count;
+ for (auto& lockGuardedMap : d_maps) {
+ auto map = lock(lockGuardedMap);
+ c += map->d_contended_count;
+ a += map->d_acquired_count;
}
return pair<uint64_t,uint64_t>(c, a);
}
// XXX!
size_t count = 0;
for (auto& map : d_maps) {
- const lock l(map);
- count += map.d_ecsIndex.size();
+ auto m = lock(map);
+ count += m->d_ecsIndex.size();
}
return count;
}
{
size_t ret = 0;
for (auto& map : d_maps) {
- const lock l(map);
- for (const auto& i : map.d_map) {
+ auto m = lock(map);
+ for (const auto& i : m->d_map) {
ret += sizeof(struct CacheEntry);
ret += i.d_qname.toString().length();
for (const auto& record : i.d_records) {
*wasAuth = true;
}
- auto& map = getMap(qname);
- const lock l(map);
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
/* If we don't have any netmask-specific entries at all, let's just skip this
to be able to use the nice d_cachecache hack. */
- if (qtype != QType::ANY && !map.d_ecsIndex.empty() && !routingTag) {
+ if (qtype != QType::ANY && !map->d_ecsIndex.empty() && !routingTag) {
if (qtype == QType::ADDR) {
time_t ret = -1;
- auto entryA = getEntryUsingECSIndex(map, now, qname, QType::A, requireAuth, who);
- if (entryA != map.d_map.end()) {
- ret = handleHit(map, entryA, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
+ auto entryA = getEntryUsingECSIndex(*map, now, qname, QType::A, requireAuth, who);
+ if (entryA != map->d_map.end()) {
+ ret = handleHit(*map, entryA, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
}
- auto entryAAAA = getEntryUsingECSIndex(map, now, qname, QType::AAAA, requireAuth, who);
- if (entryAAAA != map.d_map.end()) {
- time_t ttdAAAA = handleHit(map, entryAAAA, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
+ auto entryAAAA = getEntryUsingECSIndex(*map, now, qname, QType::AAAA, requireAuth, who);
+ if (entryAAAA != map->d_map.end()) {
+ time_t ttdAAAA = handleHit(*map, entryAAAA, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (ret > 0) {
ret = std::min(ret, ttdAAAA);
} else {
return ret > 0 ? (ret - now) : ret;
}
else {
- auto entry = getEntryUsingECSIndex(map, now, qname, qtype, requireAuth, who);
- if (entry != map.d_map.end()) {
- time_t ret = handleHit(map, entry, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
+ auto entry = getEntryUsingECSIndex(*map, now, qname, qtype, requireAuth, who);
+ if (entry != map->d_map.end()) {
+ time_t ret = handleHit(*map, entry, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (state && cachedState) {
*state = *cachedState;
}
}
if (routingTag) {
- auto entries = getEntries(map, qname, qt, routingTag);
+ auto entries = getEntries(*map, qname, qt, routingTag);
bool found = false;
time_t ttd;
if (entries.first != entries.second) {
OrderedTagIterator_t firstIndexIterator;
for (auto i=entries.first; i != entries.second; ++i) {
- firstIndexIterator = map.d_map.project<OrderedTag>(i);
+ firstIndexIterator = map->d_map.project<OrderedTag>(i);
if (i->d_ttd <= now) {
- moveCacheItemToFront<SequencedTag>(map.d_map, firstIndexIterator);
+ moveCacheItemToFront<SequencedTag>(map->d_map, firstIndexIterator);
continue;
}
continue;
}
found = true;
- ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
+ ttd = handleHit(*map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (qt != QType::ANY && qt != QType::ADDR) { // normally if we have a hit, we are done
break;
}
}
// Try (again) without tag
- auto entries = getEntries(map, qname, qt, boost::none);
+ auto entries = getEntries(*map, qname, qt, boost::none);
if (entries.first != entries.second) {
OrderedTagIterator_t firstIndexIterator;
time_t ttd;
for (auto i=entries.first; i != entries.second; ++i) {
- firstIndexIterator = map.d_map.project<OrderedTag>(i);
+ firstIndexIterator = map->d_map.project<OrderedTag>(i);
if (i->d_ttd <= now) {
- moveCacheItemToFront<SequencedTag>(map.d_map, firstIndexIterator);
+ moveCacheItemToFront<SequencedTag>(map->d_map, firstIndexIterator);
continue;
}
}
found = true;
- ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
+ ttd = handleHit(*map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
if (qt != QType::ANY && qt != QType::ADDR) { // normally if we have a hit, we are done
break;
void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask, const OptTag& routingTag, vState state, boost::optional<ComboAddress> from)
{
- auto& map = getMap(qname);
- const lock l(map);
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
- map.d_cachecachevalid = false;
+ map->d_cachecachevalid = false;
if (ednsmask) {
ednsmask = ednsmask->getNormalized();
}
// We only store an ednsmask if we do not have a tag and we do have a mask.
auto key = boost::make_tuple(qname, qt.getCode(), ednsmask ? routingTag : boost::none, (ednsmask && !routingTag) ? *ednsmask : Netmask());
bool isNew = false;
- cache_t::iterator stored = map.d_map.find(key);
- if (stored == map.d_map.end()) {
- stored = map.d_map.insert(CacheEntry(key, auth)).first;
- map.d_entriesCount++;
+ cache_t::iterator stored = map->d_map.find(key);
+ if (stored == map->d_map.end()) {
+ stored = map->d_map.insert(CacheEntry(key, auth)).first;
+ map->d_entriesCount++;
isNew = true;
}
/* don't bother building an ecsIndex if we don't have any netmask-specific entries */
if (!routingTag && ednsmask && !ednsmask->empty()) {
auto ecsIndexKey = boost::make_tuple(qname, qt.getCode());
- auto ecsIndex = map.d_ecsIndex.find(ecsIndexKey);
- if (ecsIndex == map.d_ecsIndex.end()) {
- ecsIndex = map.d_ecsIndex.insert(ECSIndexEntry(qname, qt.getCode())).first;
+ auto ecsIndex = map->d_ecsIndex.find(ecsIndexKey);
+ if (ecsIndex == map->d_ecsIndex.end()) {
+ ecsIndex = map->d_ecsIndex.insert(ECSIndexEntry(qname, qt.getCode())).first;
}
ecsIndex->addMask(*ednsmask);
}
}
if (!isNew) {
- moveCacheItemToBack<SequencedTag>(map.d_map, stored);
+ moveCacheItemToBack<SequencedTag>(map->d_map, stored);
}
ce.d_submitted = false;
- map.d_map.replace(stored, ce);
+ map->d_map.replace(stored, ce);
}
size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, const QType qtype)
size_t count = 0;
if (!sub) {
- auto& map = getMap(name);
- const lock l(map);
- map.d_cachecachevalid = false;
- auto& idx = map.d_map.get<OrderedTag>();
+ auto& lockGuardedMap = getMap(name);
+ auto map = lock(lockGuardedMap);
+ map->d_cachecachevalid = false;
+ auto& idx = map->d_map.get<OrderedTag>();
auto range = idx.equal_range(name);
auto i = range.first;
while (i != range.second) {
if (i->d_qtype == qtype || qtype == 0xffff) {
i = idx.erase(i);
count++;
- map.d_entriesCount--;
+ map->d_entriesCount--;
} else {
++i;
}
}
if (qtype == 0xffff) {
- auto& ecsIdx = map.d_ecsIndex.get<OrderedTag>();
+ auto& ecsIdx = map->d_ecsIndex.get<OrderedTag>();
auto ecsIndexRange = ecsIdx.equal_range(name);
ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
}
else {
- auto& ecsIdx = map.d_ecsIndex.get<HashedTag>();
+ auto& ecsIdx = map->d_ecsIndex.get<HashedTag>();
auto ecsIndexRange = ecsIdx.equal_range(tie(name, qtype));
ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
}
}
else {
- for (auto& map : d_maps) {
- const lock l(map);
- map.d_cachecachevalid = false;
- auto& idx = map.d_map.get<OrderedTag>();
+ for (auto& lockGuardedMap : d_maps) {
+ auto map = lock(lockGuardedMap);
+ map->d_cachecachevalid = false;
+ auto& idx = map->d_map.get<OrderedTag>();
for (auto i = idx.lower_bound(name); i != idx.end(); ) {
if (!i->d_qname.isPartOf(name))
break;
if (i->d_qtype == qtype || qtype == 0xffff) {
count++;
i = idx.erase(i);
- map.d_entriesCount--;
+ map->d_entriesCount--;
} else {
++i;
}
}
- auto& ecsIdx = map.d_ecsIndex.get<OrderedTag>();
+ auto& ecsIdx = map->d_ecsIndex.get<OrderedTag>();
for (auto i = ecsIdx.lower_bound(name); i != ecsIdx.end(); ) {
if (!i->d_qname.isPartOf(name))
break;
// Name should be doLimitTime or so
bool MemRecursorCache::doAgeCache(time_t now, const DNSName& name, const QType qtype, uint32_t newTTL)
{
- auto& map = getMap(name);
- const lock l(map);
- cache_t::iterator iter = map.d_map.find(tie(name, qtype));
- if (iter == map.d_map.end()) {
+ auto& lockGuardedMap = getMap(name);
+ auto map = lock(lockGuardedMap);
+ cache_t::iterator iter = map->d_map.find(tie(name, qtype));
+ if (iter == map->d_map.end()) {
return false;
}
uint32_t maxTTL = static_cast<uint32_t>(ce.d_ttd - now);
if (maxTTL > newTTL) {
- map.d_cachecachevalid = false;
+ map->d_cachecachevalid = false;
time_t newTTD = now + newTTL;
if (ce.d_ttd > newTTD) {
ce.d_ttd = newTTD;
- map.d_map.replace(iter, ce);
+ map->d_map.replace(iter, ce);
}
return true;
}
throw std::runtime_error("Trying to update the DNSSEC validation status of several (via ADDR) records for " + qname.toLogString());
}
- auto& map = getMap(qname);
- const lock l(map);
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
bool updated = false;
- if (!map.d_ecsIndex.empty() && !routingTag) {
- auto entry = getEntryUsingECSIndex(map, now, qname, qtype, requireAuth, who);
- if (entry == map.d_map.end()) {
+ if (!map->d_ecsIndex.empty() && !routingTag) {
+ auto entry = getEntryUsingECSIndex(*map, now, qname, qtype, requireAuth, who);
+ if (entry == map->d_map.end()) {
return false;
}
return true;
}
- auto entries = getEntries(map, qname, qt, routingTag);
+ auto entries = getEntries(*map, qname, qt, routingTag);
for(auto i = entries.first; i != entries.second; ++i) {
- auto firstIndexIterator = map.d_map.project<OrderedTag>(i);
+ auto firstIndexIterator = map->d_map.project<OrderedTag>(i);
if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
continue;
fprintf(fp.get(), "; main record cache dump follows\n;\n");
uint64_t count = 0;
- for (auto& map : d_maps) {
- const lock l(map);
- const auto& sidx = map.d_map.get<SequencedTag>();
+ for (auto& lockGuardedMap : d_maps) {
+ auto map = lock(lockGuardedMap);
+ const auto& sidx = map->d_map.get<SequencedTag>();
time_t now = time(nullptr);
for (const auto& i : sidx) {
{
}
-size_t NegCache::size() const
+size_t NegCache::size()
{
size_t count = 0;
- for (const auto& map : d_maps) {
- count += map.d_entriesCount;
+ for (auto& lockGuardedMap : d_maps) {
+ auto map = lock(lockGuardedMap);
+ count += map->d_entriesCount;
}
return count;
}
static const QType qtnull(0);
DNSName lastLabel = qname.getLastLabel();
- auto& map = getMap(lastLabel);
- const lock l(map);
+ auto& lockGuardedMap = getMap(lastLabel);
+ auto map = lock(lockGuardedMap);
- negcache_t::const_iterator ni = map.d_map.find(tie(lastLabel, qtnull));
+ negcache_t::const_iterator ni = map->d_map.find(tie(lastLabel, qtnull));
- while (ni != map.d_map.end() && ni->d_name == lastLabel && ni->d_auth.isRoot() && ni->d_qtype == qtnull) {
+ while (ni != map->d_map.end() && ni->d_name == lastLabel && ni->d_auth.isRoot() && ni->d_qtype == qtnull) {
// We have something
if (now.tv_sec < ni->d_ttd) {
ne = *ni;
- moveCacheItemToBack<SequenceTag>(map.d_map, ni);
+ moveCacheItemToBack<SequenceTag>(map->d_map, ni);
return true;
}
- moveCacheItemToFront<SequenceTag>(map.d_map, ni);
+ moveCacheItemToFront<SequenceTag>(map->d_map, ni);
++ni;
}
return false;
*/
bool NegCache::get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch)
{
- auto& map = getMap(qname);
- const lock l(map);
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
- const auto& idx = map.d_map.get<NegCacheEntry>();
+ const auto& idx = map->d_map.get<NegCacheEntry>();
auto range = idx.equal_range(qname);
auto ni = range.first;
// We have an entry
if ((!typeMustMatch && ni->d_qtype.getCode() == 0) || ni->d_qtype == qtype) {
// We match the QType or the whole name is denied
- auto firstIndexIterator = map.d_map.project<CompositeKey>(ni);
+ auto firstIndexIterator = map->d_map.project<CompositeKey>(ni);
if (now.tv_sec < ni->d_ttd) {
// Not expired
ne = *ni;
- moveCacheItemToBack<SequenceTag>(map.d_map, firstIndexIterator);
+ moveCacheItemToBack<SequenceTag>(map->d_map, firstIndexIterator);
return true;
}
// expired
- moveCacheItemToFront<SequenceTag>(map.d_map, firstIndexIterator);
+ moveCacheItemToFront<SequenceTag>(map->d_map, firstIndexIterator);
}
++ni;
}
*/
void NegCache::add(const NegCacheEntry& ne)
{
- auto& map = getMap(ne.d_name);
- const lock l(map);
- bool inserted = lruReplacingInsert<SequenceTag>(map.d_map, ne);
+ auto& lockGuardedMap = getMap(ne.d_name);
+ auto map = lock(lockGuardedMap);
+ bool inserted = lruReplacingInsert<SequenceTag>(map->d_map, ne);
if (inserted) {
- map.d_entriesCount++;
+ ++map->d_entriesCount;
}
}
*/
void NegCache::updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional<time_t> capTTD)
{
- auto& map = getMap(qname);
- const lock l(map);
- auto range = map.d_map.equal_range(tie(qname, qtype));
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
+ auto range = map->d_map.equal_range(tie(qname, qtype));
if (range.first != range.second) {
range.first->d_validationState = newState;
*
* \param qname The name of the entries to be counted
*/
-size_t NegCache::count(const DNSName& qname) const
+size_t NegCache::count(const DNSName& qname)
{
- const auto& map = getMap(qname);
- const lock l(map);
- return map.d_map.count(tie(qname));
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
+ return map->d_map.count(tie(qname));
}
/*!
* \param qname The name of the entries to be counted
* \param qtype The type of the entries to be counted
*/
-size_t NegCache::count(const DNSName& qname, const QType qtype) const
+size_t NegCache::count(const DNSName& qname, const QType qtype)
{
- const auto& map = getMap(qname);
- const lock l(map);
- return map.d_map.count(tie(qname, qtype));
+ auto& lockGuardedMap = getMap(qname);
+ auto map = lock(lockGuardedMap);
+ return map->d_map.count(tie(qname, qtype));
}
/*!
{
size_t ret = 0;
if (subtree) {
- for (auto& m : d_maps) {
- const lock l(m);
- for (auto i = m.d_map.lower_bound(tie(name)); i != m.d_map.end();) {
+ for (auto& map : d_maps) {
+ auto m = lock(map);
+ for (auto i = m->d_map.lower_bound(tie(name)); i != m->d_map.end();) {
if (!i->d_name.isPartOf(name))
break;
- i = m.d_map.erase(i);
+ i = m->d_map.erase(i);
ret++;
- m.d_entriesCount--;
+ --m->d_entriesCount;
}
}
return ret;
}
- auto& map = getMap(name);
- const lock l(map);
- auto range = map.d_map.equal_range(tie(name));
+ auto& lockGuardedMap = getMap(name);
+ auto map = lock(lockGuardedMap);
+ auto range = map->d_map.equal_range(tie(name));
auto i = range.first;
while (i != range.second) {
- i = map.d_map.erase(i);
+ i = map->d_map.erase(i);
ret++;
- map.d_entriesCount--;
+ --map->d_entriesCount;
}
return ret;
}
*/
void NegCache::clear()
{
- for (auto& m : d_maps) {
- const lock l(m);
- m.d_map.clear();
- m.d_entriesCount = 0;
+ for (auto& map : d_maps) {
+ auto m = lock(map);
+ m->d_map.clear();
+ m->d_entriesCount = 0;
}
}
*
* \param fp A pointer to an open FILE object
*/
-size_t NegCache::dumpToFile(FILE* fp, const struct timeval& now) const
+size_t NegCache::dumpToFile(FILE* fp, const struct timeval& now)
{
size_t ret = 0;
- for (const auto& m : d_maps) {
- const lock l(m);
- auto& sidx = m.d_map.get<SequenceTag>();
+ for (auto& map : d_maps) {
+ auto m = lock(map);
+ auto& sidx = m->d_map.get<SequenceTag>();
for (const NegCacheEntry& ne : sidx) {
ret++;
int64_t ttl = ne.d_ttd - now.tv_sec;