mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-03 03:41:53 +08:00
Add encapsulation to TagSet
This commit is contained in:
parent
cc10aef548
commit
b044eeab0c
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user