0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-31 19:08:59 +01:00

ircd::db: Interface to get the charge value of cache entry.

This commit is contained in:
Jason Volk 2020-05-05 13:06:39 -07:00
parent 1eaf52d2eb
commit b448156da4
2 changed files with 42 additions and 0 deletions

View file

@ -45,6 +45,10 @@ namespace ircd::db
bool exists(const rocksdb::Cache &, const string_view &key);
bool exists(const rocksdb::Cache *const &, const string_view &key);
// Get charge value for key
size_t charge(const rocksdb::Cache &, const string_view &key);
size_t charge(const rocksdb::Cache *const &, const string_view &key);
// Iterate the cache entries.
using cache_closure = std::function<void (const const_buffer &)>;
void for_each(const rocksdb::Cache &, const cache_closure &);
@ -111,6 +115,15 @@ ircd::db::for_each(const rocksdb::Cache *const &cache,
for_each(*cache, closure);
}
inline size_t
ircd::db::charge(const rocksdb::Cache *const &cache,
const string_view &key)
{
return cache?
charge(*cache, key):
0UL;
}
inline bool
ircd::db::exists(const rocksdb::Cache *const &cache,
const string_view &key)

View file

@ -7238,6 +7238,35 @@ ircd::db::for_each(const rocksdb::Cache &cache,
true);
}
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE
size_t
ircd::db::charge(const rocksdb::Cache &cache_,
const string_view &key)
{
auto &cache
{
const_cast<rocksdb::Cache &>(cache_)
};
const custom_ptr<rocksdb::Cache::Handle> handle
{
cache.Lookup(slice(key)), [&cache](auto *const &handle)
{
cache.Release(handle);
}
};
return cache.GetCharge(handle);
}
#else
size_t
ircd::db::charge(const rocksdb::Cache &cache,
const string_view &key)
{
return 0UL;
}
#endif
[[gnu::hot]]
bool
ircd::db::exists(const rocksdb::Cache &cache_,