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:
parent
1eaf52d2eb
commit
b448156da4
2 changed files with 42 additions and 0 deletions
|
@ -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)
|
||||
|
|
29
ircd/db.cc
29
ircd/db.cc
|
@ -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_,
|
||||
|
|
Loading…
Reference in a new issue