0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-09 05:29:00 +02:00

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() // the argument execution doesn't throw after release()
throw_on_error 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), cache.Insert(slice(key),
mutable_cast(data(value.release())), mutable_cast(data(value.release())),
value_size, value_size,
deleter, deleter,
nullptr) nullptr)
#endif
}; };
return true; return true;
@ -4137,6 +4145,24 @@ ircd::db::insert(rocksdb::Cache &cache,
void void
ircd::db::for_each(const rocksdb::Cache &cache, ircd::db::for_each(const rocksdb::Cache &cache,
const cache_closure &closure) 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 // 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 // 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); true);
} }
#endif
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE #ifdef IRCD_DB_HAS_CACHE_GETCHARGE
size_t size_t
@ -5896,6 +5923,9 @@ ircd::db::reflect(const rocksdb::CompactionReason &r)
#ifdef IRCD_DB_HAS_ROUND_ROBIN_TTL #ifdef IRCD_DB_HAS_ROUND_ROBIN_TTL
case Reason::kRoundRobinTtl: return "kRoundRobinTtl"; case Reason::kRoundRobinTtl: return "kRoundRobinTtl";
#endif #endif
#ifdef IRCD_DB_HAS_REFIT_LEVEL
case Reason::kRefitLevel: return "RefitLevel";
#endif
case Reason::kNumOfReasons: case Reason::kNumOfReasons:
break; break;

View file

@ -61,6 +61,9 @@
#include <rocksdb/compaction_filter.h> #include <rocksdb/compaction_filter.h>
#include <rocksdb/wal_filter.h> #include <rocksdb/wal_filter.h>
#include <rocksdb/rate_limiter.h> #include <rocksdb/rate_limiter.h>
#if __has_include(<rocksdb/advanced_cache.h>)
#include <rocksdb/advanced_cache.h>
#endif
#pragma clang attribute pop #pragma clang attribute pop
#include "db_has.h" #include "db_has.h"
@ -218,8 +221,16 @@ ircd::db::database::cache final
std::shared_ptr<rocksdb::Cache> c; std::shared_ptr<rocksdb::Cache> c;
const char *Name() const noexcept override; 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; 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; Handle *Lookup(const Slice &key, Statistics *) noexcept override;
#endif
bool Ref(Handle *) noexcept override; bool Ref(Handle *) noexcept override;
bool Release(Handle *, bool force_erase) noexcept override; bool Release(Handle *, bool force_erase) noexcept override;
void *Value(Handle *) 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 GetUsage(Handle *) const noexcept override;
size_t GetPinnedUsage() const noexcept override; size_t GetPinnedUsage() const noexcept override;
void DisownData() noexcept override; void DisownData() noexcept override;
#ifndef IRCD_DB_HAS_CACHE_ITEMHELPER
void ApplyToAllCacheEntries(callback, bool thread_safe) noexcept override; void ApplyToAllCacheEntries(callback, bool thread_safe) noexcept override;
#endif
void EraseUnRefEntries() noexcept override; void EraseUnRefEntries() noexcept override;
std::string GetPrintableOptions() const noexcept override; std::string GetPrintableOptions() const noexcept override;
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE #ifdef IRCD_DB_HAS_CACHE_GETCHARGE
size_t GetCharge(Handle *) const noexcept override; size_t GetCharge(Handle *) const noexcept override;
#endif #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; DeleterFn GetDeleter(Handle *) const noexcept override;
#endif #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)>; using callbackstd = std::function<void (const Slice &, void *, size_t, DeleterFn)>;
void ApplyToAllEntries(const callbackstd &, const ApplyToAllEntriesOptions &) noexcept override; void ApplyToAllEntries(const callbackstd &, const ApplyToAllEntriesOptions &) noexcept override;
#endif #endif
#ifdef IRCD_DB_HAS_CACHE_ITEMHELPER
const CacheItemHelper *GetCacheItemHelper(Handle *) const noexcept override;
#endif
cache(database *const &, cache(database *const &,
std::shared_ptr<struct database::stats>, std::shared_ptr<struct database::stats>,

View file

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

View file

@ -151,3 +151,21 @@
|| (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR == 8 && ROCKSDB_PATCH >= 3) || (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR == 8 && ROCKSDB_PATCH >= 3)
#define IRCD_DB_HAS_ROUND_ROBIN_TTL #define IRCD_DB_HAS_ROUND_ROBIN_TTL
#endif #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