mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::db: Add cache entry iteration (experimental).
This commit is contained in:
parent
8f40fd574a
commit
9e0acde5cf
2 changed files with 49 additions and 0 deletions
|
@ -36,4 +36,9 @@ namespace ircd::db
|
|||
// Test if key exists
|
||||
bool exists(rocksdb::Cache &, const string_view &key);
|
||||
bool exists(rocksdb::Cache *const &, const string_view &key);
|
||||
|
||||
// Iterate the cache entries.
|
||||
using cache_closure = std::function<void (const string_view &, const size_t &)>;
|
||||
void for_each(rocksdb::Cache &, const cache_closure &);
|
||||
void for_each(rocksdb::Cache *const &, const cache_closure &);
|
||||
}
|
||||
|
|
44
ircd/db.cc
44
ircd/db.cc
|
@ -5074,6 +5074,50 @@ ircd::db::_seek_(rocksdb::Iterator &it,
|
|||
// cache.h
|
||||
//
|
||||
|
||||
void
|
||||
ircd::db::for_each(rocksdb::Cache *const &cache,
|
||||
const cache_closure &closure)
|
||||
{
|
||||
if(cache)
|
||||
for_each(*cache, closure);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::db::for_each(rocksdb::Cache &cache,
|
||||
const cache_closure &closure)
|
||||
{
|
||||
thread_local rocksdb::Cache *_cache;
|
||||
_cache = &cache;
|
||||
|
||||
thread_local const cache_closure *_closure;
|
||||
_closure = &closure;
|
||||
|
||||
cache.ApplyToAllCacheEntries([]
|
||||
(void *const data, const size_t charge)
|
||||
{
|
||||
assert(_cache);
|
||||
assert(_closure);
|
||||
auto *const &handle
|
||||
{
|
||||
reinterpret_cast<rocksdb::Cache::Handle *>(data)
|
||||
};
|
||||
|
||||
const void *const &value
|
||||
{
|
||||
_cache->Value(handle)
|
||||
};
|
||||
|
||||
assert(value);
|
||||
const auto &s
|
||||
{
|
||||
*reinterpret_cast<const rocksdb::Slice *>(value)
|
||||
};
|
||||
|
||||
(*_closure)(slice(s), charge);
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::db::exists(rocksdb::Cache *const &cache,
|
||||
const string_view &key)
|
||||
|
|
Loading…
Reference in a new issue