container.preRemoval(*shard, *i);
i = sidx.erase(i);
erased++;
- --content.d_entriesCount;
+ content.decEntriesCount();
}
else {
++i;
for (auto i = sidx.begin(); i != sidx.end() && removed < toTrimForThisShard; removed++) {
container.preRemoval(*shard, *i);
i = sidx.erase(i);
- --content.d_entriesCount;
+ content.decEntriesCount();
++totErased;
if (--toTrim == 0) {
return totErased;
{
size_t count = 0;
for (const auto& map : d_maps) {
- count += map.d_entriesCount;
+ count += map.getEntriesCount();
}
return count;
}
auto content = map.lock();
inserted = lruReplacingInsert<SequenceTag>(content->d_map, ne);
if (inserted) {
- ++map.d_entriesCount;
+ map.incEntriesCount();
}
}
break;
i = m->d_map.erase(i);
ret++;
- --map.d_entriesCount;
+ map.decEntriesCount();
}
}
return ret;
while (i != range.second) {
i = content->d_map.erase(i);
ret++;
- --map.d_entriesCount;
+ map.decEntriesCount();
}
return ret;
}
if (i->d_qtype == QType::ENT || i->d_qtype == qtype) {
i = content->d_map.erase(i);
++ret;
- --map.d_entriesCount;
+ map.decEntriesCount();
}
else {
++i;
for (auto& map : d_maps) {
auto m = map.lock();
m->d_map.clear();
- map.d_entriesCount = 0;
+ map.clearEntriesCount();
}
}
uint64_t d_acquired_count{0};
void invalidate() {}
};
- pdns::stat_t d_entriesCount{0};
LockGuardedTryHolder<MapCombo::LockedContent> lock()
{
return locked;
}
+ [[nodiscard]] auto getEntriesCount() const
+ {
+ return d_entriesCount.load();
+ }
+
+ void incEntriesCount()
+ {
+ ++d_entriesCount;
+ }
+
+ void decEntriesCount()
+ {
+ --d_entriesCount;
+ }
+
+ void clearEntriesCount()
+ {
+ d_entriesCount = 0;
+ }
+
private:
LockGuarded<LockedContent> d_content;
+ pdns::stat_t d_entriesCount{0};
};
vector<MapCombo> d_maps;
{
uint64_t count = 0;
for (const auto& map : d_maps) {
- count += map.d_entriesCount;
+ count += map.getEntriesCount();
}
return count;
}
}
if (qtype == 0xffff || iter->d_type == qtype) {
iter = idx.erase(iter);
- map.d_entriesCount--;
+ map.decEntriesCount();
count++;
}
else {
return;
}
- struct Entry entry(qname, qtype, qclass, std::move(responsePacket), std::move(query), tcp, qhash, now + ttl, now, tag, valState);
+ struct Entry entry(DNSName(qname), qtype, qclass, std::move(responsePacket), std::move(query), tcp, qhash, now + ttl, now, tag, valState);
if (pbdata) {
entry.d_pbdata = std::move(*pbdata);
}
shard->d_map.insert(entry);
- map.d_entriesCount++;
+ map.incEntriesCount();
if (shard->d_map.size() > shard->d_shardSize) {
auto& seq_idx = shard->d_map.get<SequencedTag>();
seq_idx.erase(seq_idx.begin());
- map.d_entriesCount--;
+ map.decEntriesCount();
}
- assert(map.d_entriesCount == shard->d_map.size()); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay): clib implementation
+ assert(map.getEntriesCount() == shard->d_map.size()); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay): clib implementation
}
void RecursorPacketCache::doPruneTo(size_t maxSize)
*/
#pragma once
#include <string>
-#include <inttypes.h>
+#include <cinttypes>
#include "dns.hh"
#include "namespaces.hh"
#include <iostream>
private:
struct Entry
{
- Entry(const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& packet, std::string&& query, bool tcp,
- uint32_t qhash, time_t ttd, time_t now, uint32_t tag, vState vstate) :
- d_name(qname), d_packet(std::move(packet)), d_query(std::move(query)), d_ttd(ttd), d_creation(now), d_qhash(qhash), d_tag(tag), d_type(qtype), d_class(qclass), d_vstate(vstate), d_tcp(tcp)
+ Entry(DNSName&& qname, uint16_t qtype, uint16_t qclass, std::string&& packet, std::string&& query, bool tcp,
+ uint32_t qhash, time_t ttd, time_t now, uint32_t tag, vState vstate) : // NOLINT
+ d_name(std::move(qname)), d_packet(std::move(packet)), d_query(std::move(query)), d_ttd(ttd), d_creation(now), d_qhash(qhash), d_tag(tag), d_type(qtype), d_class(qclass), d_vstate(vstate), d_tcp(tcp)
{
}
struct MapCombo
{
MapCombo() = default;
+ ~MapCombo() = default;
MapCombo(const MapCombo&) = delete;
+ MapCombo(MapCombo&&) = delete;
MapCombo& operator=(const MapCombo&) = delete;
+ MapCombo& operator=(MapCombo&&) = delete;
+
struct LockedContent
{
packetCache_t d_map;
uint64_t d_acquired_count{0};
void invalidate() {}
};
- pdns::stat_t d_entriesCount{0};
LockGuardedTryHolder<MapCombo::LockedContent> lock()
{
return locked;
}
+ [[nodiscard]] auto getEntriesCount() const
+ {
+ return d_entriesCount.load();
+ }
+
+ void incEntriesCount()
+ {
+ ++d_entriesCount;
+ }
+
+ void decEntriesCount()
+ {
+ --d_entriesCount;
+ }
+
private:
LockGuarded<LockedContent> d_content;
+ pdns::stat_t d_entriesCount{0};
};
vector<MapCombo> d_maps;
{
size_t count = 0;
for (const auto& shard : d_maps) {
- count += shard.d_entriesCount;
+ count += shard.getEntriesCount();
}
return count;
}
cache_t::iterator stored = lockedShard->d_map.find(key);
if (stored == lockedShard->d_map.end()) {
stored = lockedShard->d_map.insert(CacheEntry(key, auth)).first;
- ++shard.d_entriesCount;
+ shard.incEntriesCount();
isNew = true;
}
if (i->d_qtype == qtype || qtype == 0xffff) {
i = idx.erase(i);
count++;
- --shard.d_entriesCount;
+ shard.decEntriesCount();
}
else {
++i;
if (i->d_qtype == qtype || qtype == 0xffff) {
count++;
i = idx.erase(i);
- --mc.d_entriesCount;
+ mc.decEntriesCount();
}
else {
++i;
}
};
- pdns::stat_t d_entriesCount{0};
-
LockGuardedTryHolder<LockedContent> lock()
{
auto locked = d_content.try_lock();
return locked;
}
+ [[nodiscard]] auto getEntriesCount() const
+ {
+ return d_entriesCount.load();
+ }
+
+ void incEntriesCount()
+ {
+ ++d_entriesCount;
+ }
+
+ void decEntriesCount()
+ {
+ --d_entriesCount;
+ }
+
+ void clearEntriesCount()
+ {
+ d_entriesCount = 0;
+ }
+
private:
LockGuarded<LockedContent> d_content;
+ pdns::stat_t d_entriesCount{0};
};
vector<MapCombo> d_maps;