Add encapsulation to TagSet

This commit is contained in:
sfc-gh-tclinkenbeard 2020-06-14 14:03:45 -07:00
parent cc10aef548
commit b044eeab0c
2 changed files with 42 additions and 26 deletions

View File

@ -55,38 +55,21 @@ public:
return tags.end();
}
//private:
Arena arena;
std::set<TransactionTagRef> tags;
size_t bytes;
};
template <>
struct dynamic_size_traits<TagSet> : std::true_type {
// May be called multiple times during one serialization
template <class Context>
static size_t size(const TagSet& t, Context&) {
return t.tags.size() + t.bytes;
}
// Guaranteed to be called only once during serialization
template <class Context>
static void save(uint8_t* out, const TagSet& t, Context& c) {
void save(uint8_t* out, Context& c) const {
uint8_t *start = out;
for (const auto& tag : t.tags) {
for (const auto& tag : *this) {
*(out++) = (uint8_t)tag.size();
std::copy(tag.begin(), tag.end(), out);
out += tag.size();
}
ASSERT((size_t)(out-start) == size(t, c));
ASSERT((size_t)(out - start) == size() + bytes);
}
// Context is an arbitrary type that is plumbed by reference throughout the
// load call tree.
template <class Context>
static void load(const uint8_t* data, size_t size, TagSet& t, Context& context) {
void load(const uint8_t* data, size_t size, Context& context) {
//const uint8_t *start = data;
const uint8_t *end = data + size;
while(data < end) {
@ -94,8 +77,8 @@ struct dynamic_size_traits<TagSet> : std::true_type {
TransactionTagRef tag(context.tryReadZeroCopy(data, len), len);
data += len;
t.tags.insert(tag);
t.bytes += tag.size();
tags.insert(tag);
bytes += tag.size();
}
ASSERT(data == end);
@ -103,7 +86,40 @@ struct dynamic_size_traits<TagSet> : std::true_type {
// Deserialized tag sets share the arena with the request that contained them
// For this reason, persisting a TagSet that shares memory with other request
// members should be done with caution.
t.arena = context.arena();
arena = context.arena();
}
size_t getBytes() const { return bytes; }
const Arena &getArena() const {
return arena;
}
private:
size_t bytes;
Arena arena;
std::set<TransactionTagRef> tags;
};
template <>
struct dynamic_size_traits<TagSet> : std::true_type {
// May be called multiple times during one serialization
template <class Context>
static size_t size(const TagSet& t, Context&) {
return t.size() + t.getBytes();
}
// Guaranteed to be called only once during serialization
template <class Context>
static void save(uint8_t* out, const TagSet& t, Context& c) {
t.save(out, c);
}
// Context is an arbitrary type that is plumbed by reference throughout the
// load call tree.
template <class Context>
static void load(const uint8_t* data, size_t size, TagSet& t, Context& context) {
t.load(data, size, context);
}
};
@ -184,4 +200,4 @@ using TransactionTagMap = std::unordered_map<TransactionTag, Value, std::hash<Tr
template<class Value>
using PrioritizedTransactionTagMap = std::map<TransactionPriority, TransactionTagMap<Value>>;
#endif
#endif

View File

@ -477,7 +477,7 @@ public:
TEST(true); // Tracking tag on storage server
double cost = costFunction(bytes);
for(auto& tag : tags.get()) {
int64_t &count = intervalCounts[TransactionTag(tag, tags.get().arena)];
int64_t &count = intervalCounts[TransactionTag(tag, tags.get().getArena())];
count += cost;
if(count > busiestTagCount) {
busiestTagCount = count;