0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::db: Add interface to database & column caches.

This commit is contained in:
Jason Volk 2018-05-14 16:17:43 -07:00
parent 507b8e4f1c
commit f97c9fff99
5 changed files with 133 additions and 0 deletions

35
include/ircd/db/cache.h Normal file
View file

@ -0,0 +1,35 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_DB_CACHE_H
// Interface to a cache. This interface is included in the standard include
// stack by forward declaring the rocksdb::Cache symbol.
//
// The interface overloads on a pointer to a cache for developer convenience.
// This is because caches may not always exist for some entity, and accessors
// will return a null pointer. The pointer overloads here will safely accept
// null pointers and provide the appropriate no-op behavior.
namespace ircd::db
{
// Get capacity
size_t capacity(const rocksdb::Cache &);
size_t capacity(const rocksdb::Cache *const &);
// Set capacity
void capacity(rocksdb::Cache &, const size_t &);
bool capacity(rocksdb::Cache *const &, const size_t &);
// Get usage
size_t usage(const rocksdb::Cache &);
size_t usage(const rocksdb::Cache *const &);
}

View file

@ -31,6 +31,12 @@ namespace ircd::db
template<> prop_int property(const column &, const string_view &name); template<> prop_int property(const column &, const string_view &name);
template<> prop_map property(const column &, const string_view &name); template<> prop_map property(const column &, const string_view &name);
// Access to the column's caches (see cache.h interface)
const rocksdb::Cache *cache_compressed(const column &);
const rocksdb::Cache *cache(const column &);
rocksdb::Cache *cache_compressed(column &);
rocksdb::Cache *cache(column &);
// [GET] Tests if key exists // [GET] Tests if key exists
bool has(column &, const string_view &key, const gopts & = {}); bool has(column &, const string_view &key, const gopts & = {});

View file

@ -30,6 +30,10 @@ namespace ircd::db
template<class R = prop_int> R property(const database &, const string_view &name); template<class R = prop_int> R property(const database &, const string_view &name);
template<> prop_int property(const database &, const string_view &name); template<> prop_int property(const database &, const string_view &name);
// Access to the database's row cache (see cache.h interface)
const rocksdb::Cache *cache(const database &);
rocksdb::Cache *cache(database &);
// Ticker // Ticker
extern const uint32_t ticker_max; extern const uint32_t ticker_max;
string_view ticker_id(const uint32_t &id); string_view ticker_id(const uint32_t &id);

View file

@ -68,6 +68,7 @@ enum class ircd::db::pos
#include "database/descriptor.h" #include "database/descriptor.h"
#include "database/options.h" #include "database/options.h"
#include "database/snapshot.h" #include "database/snapshot.h"
#include "cache.h"
#include "opts.h" #include "opts.h"
#include "column.h" #include "column.h"
#include "cell.h" #include "cell.h"

View file

@ -308,6 +308,18 @@ ircd::db::sequence(const database &cd)
return d.d->GetLatestSequenceNumber(); return d.d->GetLatestSequenceNumber();
} }
rocksdb::Cache *
ircd::db::cache(database &d)
{
return d.cache.get();
}
const rocksdb::Cache *
ircd::db::cache(const database &d)
{
return d.cache.get();
}
template<> template<>
ircd::db::prop_int ircd::db::prop_int
ircd::db::property(const database &cd, ircd::db::property(const database &cd,
@ -3906,6 +3918,34 @@ ircd::db::read(column &column,
return ret; return ret;
} }
rocksdb::Cache *
ircd::db::cache(column &column)
{
database::column &c(column);
return c.table_opts.block_cache.get();
}
rocksdb::Cache *
ircd::db::cache_compressed(column &column)
{
database::column &c(column);
return c.table_opts.block_cache_compressed.get();
}
const rocksdb::Cache *
ircd::db::cache(const column &column)
{
const database::column &c(column);
return c.table_opts.block_cache.get();
}
const rocksdb::Cache *
ircd::db::cache_compressed(const column &column)
{
const database::column &c(column);
return c.table_opts.block_cache_compressed.get();
}
template<> template<>
ircd::db::prop_str ircd::db::prop_str
ircd::db::property(const column &column, ircd::db::property(const column &column,
@ -5029,6 +5069,53 @@ ircd::db::_seek_(rocksdb::Iterator &it,
return it; return it;
} }
///////////////////////////////////////////////////////////////////////////////
//
// cache.h
//
size_t
ircd::db::usage(const rocksdb::Cache *const &cache)
{
return cache? usage(*cache) : 0;
}
size_t
ircd::db::usage(const rocksdb::Cache &cache)
{
return cache.GetUsage();
}
bool
ircd::db::capacity(rocksdb::Cache *const &cache,
const size_t &cap)
{
if(!cache)
return false;
capacity(*cache, cap);
return true;
}
void
ircd::db::capacity(rocksdb::Cache &cache,
const size_t &cap)
{
cache.SetCapacity(cap);
}
size_t
ircd::db::capacity(const rocksdb::Cache *const &cache)
{
return cache? capacity(*cache): 0;
}
size_t
ircd::db::capacity(const rocksdb::Cache &cache)
{
return cache.GetCapacity();
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// Misc // Misc