mirror of
https://github.com/matrix-construct/construct
synced 2024-09-30 04:38:52 +02:00
ircd::db: Add interface to database & column caches.
This commit is contained in:
parent
507b8e4f1c
commit
f97c9fff99
5 changed files with 133 additions and 0 deletions
35
include/ircd/db/cache.h
Normal file
35
include/ircd/db/cache.h
Normal 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 &);
|
||||
}
|
|
@ -31,6 +31,12 @@ namespace ircd::db
|
|||
template<> prop_int 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
|
||||
bool has(column &, const string_view &key, const gopts & = {});
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ namespace ircd::db
|
|||
template<class R = prop_int> R 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
|
||||
extern const uint32_t ticker_max;
|
||||
string_view ticker_id(const uint32_t &id);
|
||||
|
|
|
@ -68,6 +68,7 @@ enum class ircd::db::pos
|
|||
#include "database/descriptor.h"
|
||||
#include "database/options.h"
|
||||
#include "database/snapshot.h"
|
||||
#include "cache.h"
|
||||
#include "opts.h"
|
||||
#include "column.h"
|
||||
#include "cell.h"
|
||||
|
|
87
ircd/db.cc
87
ircd/db.cc
|
@ -308,6 +308,18 @@ ircd::db::sequence(const database &cd)
|
|||
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<>
|
||||
ircd::db::prop_int
|
||||
ircd::db::property(const database &cd,
|
||||
|
@ -3906,6 +3918,34 @@ ircd::db::read(column &column,
|
|||
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<>
|
||||
ircd::db::prop_str
|
||||
ircd::db::property(const column &column,
|
||||
|
@ -5029,6 +5069,53 @@ ircd::db::_seek_(rocksdb::Iterator &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
|
||||
|
|
Loading…
Reference in a new issue