Add SaveEntries() and LoadEntries(). (#233)

These allow saving and loading non-persistent entries in the persistent
file format.
This commit is contained in:
Peter Johnson
2017-10-01 09:13:43 -07:00
committed by GitHub
parent e68a71022c
commit 1f18cc5416
17 changed files with 352 additions and 26 deletions

View File

@@ -948,6 +948,31 @@ bool Storage::GetPersistentEntries(
return true;
}
bool Storage::GetEntries(
StringRef prefix,
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
const {
// copy values out of storage as quickly as possible so lock isn't held
{
std::lock_guard<std::mutex> lock(m_mutex);
entries->reserve(m_entries.size());
for (auto& i : m_entries) {
Entry* entry = i.getValue();
// only write values with given prefix
if (!i.getKey().startswith(prefix)) continue;
entries->emplace_back(i.getKey(), entry->value);
}
}
// sort in name order
std::sort(entries->begin(), entries->end(),
[](const std::pair<std::string, std::shared_ptr<Value>>& a,
const std::pair<std::string, std::shared_ptr<Value>>& b) {
return a.first < b.first;
});
return true;
}
void Storage::CreateRpc(unsigned int local_id, StringRef def,
unsigned int rpc_uid) {
std::unique_lock<std::mutex> lock(m_mutex);