ircd::db: Update for Cache interface refactor; reflections. (RocksDB 8.0)

This commit is contained in:
Jason Volk 2023-03-17 21:24:18 -07:00
parent 1e4f44f41d
commit cc36c17c03
4 changed files with 110 additions and 3 deletions

View File

@ -4124,11 +4124,19 @@ ircd::db::insert(rocksdb::Cache &cache,
// the argument execution doesn't throw after release()
throw_on_error
{
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
cache.Insert(slice(key),
mutable_cast(data(value.release())),
cache.GetCacheItemHelper(nullptr), // ???
value_size,
nullptr)
#else
cache.Insert(slice(key),
mutable_cast(data(value.release())),
value_size,
deleter,
nullptr)
#endif
};
return true;
@ -4137,6 +4145,24 @@ ircd::db::insert(rocksdb::Cache &cache,
void
ircd::db::for_each(const rocksdb::Cache &cache,
const cache_closure &closure)
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
{
const auto _closure{[&closure]
(const auto &slice, void *const value, size_t size, const auto *const helper)
noexcept
{
const const_buffer buf
{
reinterpret_cast<const char *>(value), size
};
closure(buf);
}};
rocksdb::Cache::ApplyToAllEntriesOptions opts;
mutable_cast(cache).ApplyToAllEntries(_closure, opts);
}
#else
{
// Due to the use of the global variables which are required when using a
// C-style callback for RocksDB, we have to make use of this function
@ -4165,6 +4191,7 @@ ircd::db::for_each(const rocksdb::Cache &cache,
},
true);
}
#endif
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE
size_t
@ -5896,6 +5923,9 @@ ircd::db::reflect(const rocksdb::CompactionReason &r)
#ifdef IRCD_DB_HAS_ROUND_ROBIN_TTL
case Reason::kRoundRobinTtl: return "kRoundRobinTtl";
#endif
#ifdef IRCD_DB_HAS_REFIT_LEVEL
case Reason::kRefitLevel: return "RefitLevel";
#endif
case Reason::kNumOfReasons:
break;

View File

@ -61,6 +61,9 @@
#include <rocksdb/compaction_filter.h>
#include <rocksdb/wal_filter.h>
#include <rocksdb/rate_limiter.h>
#if __has_include(<rocksdb/advanced_cache.h>)
#include <rocksdb/advanced_cache.h>
#endif
#pragma clang attribute pop
#include "db_has.h"
@ -218,8 +221,16 @@ ircd::db::database::cache final
std::shared_ptr<rocksdb::Cache> c;
const char *Name() const noexcept override;
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
Status Insert(const Slice &key, ObjectPtr, const CacheItemHelper *, size_t charge, Handle **, Priority) noexcept override;
#else
Status Insert(const Slice &key, void *value, size_t charge, deleter, Handle **, Priority) noexcept override;
#endif
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
Handle *Lookup(const Slice &key, const CacheItemHelper *, CreateContext *, Priority, bool, Statistics *) noexcept override;
#else
Handle *Lookup(const Slice &key, Statistics *) noexcept override;
#endif
bool Ref(Handle *) noexcept override;
bool Release(Handle *, bool force_erase) noexcept override;
void *Value(Handle *) noexcept override;
@ -233,19 +244,27 @@ ircd::db::database::cache final
size_t GetUsage(Handle *) const noexcept override;
size_t GetPinnedUsage() const noexcept override;
void DisownData() noexcept override;
#ifndef IRCD_DB_HAS_CACHE_ITEMHELPER
void ApplyToAllCacheEntries(callback, bool thread_safe) noexcept override;
#endif
void EraseUnRefEntries() noexcept override;
std::string GetPrintableOptions() const noexcept override;
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE
size_t GetCharge(Handle *) const noexcept override;
#endif
#ifdef IRCD_DB_HAS_CACHE_GETDELETER
#if defined(IRCD_DB_HAS_CACHE_GETDELETER) && !defined(IRCD_DB_HAS_CACHE_ITEMHELPER)
DeleterFn GetDeleter(Handle *) const noexcept override;
#endif
#ifdef IRCD_DB_HAS_CACHE_APPLYTOALL
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
using callbackstd = std::function<void (const Slice &, ObjectPtr, size_t, const CacheItemHelper *)>;
void ApplyToAllEntries(const callbackstd &, const ApplyToAllEntriesOptions &) noexcept override;
#elif defined(IRCD_DB_HAS_CACHE_APPLYTOALL)
using callbackstd = std::function<void (const Slice &, void *, size_t, DeleterFn)>;
void ApplyToAllEntries(const callbackstd &, const ApplyToAllEntriesOptions &) noexcept override;
#endif
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
const CacheItemHelper *GetCacheItemHelper(Handle *) const noexcept override;
#endif
cache(database *const &,
std::shared_ptr<struct database::stats>,

View File

@ -3182,6 +3182,15 @@ const noexcept
c->Name();
}
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
rocksdb::Status
ircd::db::database::cache::Insert(const Slice &key,
ObjectPtr value,
const CacheItemHelper *const helper,
size_t charge,
Handle **const handle,
Priority priority)
#else
rocksdb::Status
ircd::db::database::cache::Insert(const Slice &key,
void *const value,
@ -3189,6 +3198,7 @@ ircd::db::database::cache::Insert(const Slice &key,
deleter del,
Handle **const handle,
Priority priority)
#endif
noexcept
{
using rocksdb::Tickers;
@ -3198,7 +3208,11 @@ noexcept
const rocksdb::Status &ret
{
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
c->Insert(key, value, helper, charge, handle, priority)
#else
c->Insert(key, value, charge, del, handle, priority)
#endif
};
stats->recordTick(Tickers::BLOCK_CACHE_ADD, ret.ok());
@ -3223,9 +3237,19 @@ noexcept
return ret;
}
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
rocksdb::Cache::Handle *
ircd::db::database::cache::Lookup(const Slice &key,
const CacheItemHelper *const helper,
CreateContext *const cc,
Priority pri,
bool wait,
Statistics *const statistics)
#else
rocksdb::Cache::Handle *
ircd::db::database::cache::Lookup(const Slice &key,
Statistics *const statistics)
#endif
noexcept
{
using rocksdb::Tickers;
@ -3247,7 +3271,11 @@ noexcept
auto *const &ret
{
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
c->Lookup(key, helper, cc, pri, wait, statistics)
#else
c->Lookup(key, s)
#endif
};
// Rocksdb's LRUCache stats are broke. The statistics ptr is null and
@ -3379,6 +3407,7 @@ noexcept
return c->DisownData();
}
#ifndef IRCD_DB_HAS_CACHE_ITEMHELPER
void
ircd::db::database::cache::ApplyToAllCacheEntries(callback cb,
bool thread_safe)
@ -3387,6 +3416,7 @@ noexcept
assert(bool(c));
return c->ApplyToAllCacheEntries(cb, thread_safe);
}
#endif
void
ircd::db::database::cache::EraseUnRefEntries()
@ -3414,7 +3444,7 @@ const noexcept
}
#endif
#ifdef IRCD_DB_HAS_CACHE_GETDELETER
#if defined(IRCD_DB_HAS_CACHE_GETDELETER) && !defined(IRCD_DB_HAS_CACHE_ITEMHELPER)
rocksdb::Cache::DeleterFn
ircd::db::database::cache::GetDeleter(Handle *const h)
const noexcept
@ -3435,6 +3465,16 @@ noexcept
}
#endif
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
const rocksdb::Cache::CacheItemHelper *
ircd::db::database::cache::GetCacheItemHelper(Handle *const h)
const noexcept
{
assert(bool(c));
return c->GetCacheItemHelper(h);
}
#endif
///////////////////////////////////////////////////////////////////////////////
//
// database::compaction_filter

View File

@ -151,3 +151,21 @@
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR == 8 && ROCKSDB_PATCH >= 3)
#define IRCD_DB_HAS_ROUND_ROBIN_TTL
#endif
#if ROCKSDB_MAJOR > 7 \
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR > 10) \
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR == 10 && ROCKSDB_PATCH >= 0)
#define IRCD_DB_HAS_CACHE_ITEMHELPER
#endif
#if ROCKSDB_MAJOR > 7 \
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR > 10) \
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR == 10 && ROCKSDB_PATCH >= 2)
#define IRCD_DB_HAS_REFIT_LEVEL
#endif
#if ROCKSDB_MAJOR > 8 \
|| (ROCKSDB_MAJOR == 8 && ROCKSDB_MINOR > 0) \
|| (ROCKSDB_MAJOR == 8 && ROCKSDB_MINOR == 0 && ROCKSDB_PATCH >= 0)
#define IRCD_DB_HAS_CACHE_WRAPPER
#endif