2018-01-19 02:59:22 +01:00
|
|
|
// 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_DATABASE_DESCRIPTOR_H
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
struct descriptor;
|
|
|
|
using description = std::vector<descriptor>;
|
|
|
|
}
|
|
|
|
|
2018-01-19 02:59:22 +01:00
|
|
|
/// Descriptor of a column when opening database. Database must be opened with
|
|
|
|
/// a consistent set of descriptors describing what will be found upon opening.
|
2018-09-20 00:38:37 +02:00
|
|
|
struct ircd::db::descriptor
|
2018-01-19 02:59:22 +01:00
|
|
|
{
|
|
|
|
using typing = std::pair<std::type_index, std::type_index>;
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
/// User given name for this column. Must be consistent.
|
2018-01-19 02:59:22 +01:00
|
|
|
std::string name;
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// User given description of this column; not used by RocksDB
|
2018-01-19 02:59:22 +01:00
|
|
|
std::string explain;
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// Indicate key and value type.
|
2018-01-19 02:59:22 +01:00
|
|
|
typing type { typeid(string_view), typeid(string_view) };
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// RocksDB ColumnFamilyOptions string; can be used for items not
|
|
|
|
/// otherwise specified here.
|
2018-01-19 02:59:22 +01:00
|
|
|
std::string options {};
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// User given comparator. We can automatically set this value for
|
|
|
|
/// some types given for the type.first typeid; otherwise it must be
|
|
|
|
/// set for exotic/unsupported keys.
|
2018-01-19 02:59:22 +01:00
|
|
|
db::comparator cmp {};
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// User given prefix extractor.
|
2018-01-19 02:59:22 +01:00
|
|
|
db::prefix_transform prefix {};
|
2018-04-18 00:28:08 +02:00
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
/// Indicates if this column should be marked for deletion. Users who
|
|
|
|
/// upgrade to the new schema will still require a legacy descriptor
|
|
|
|
/// with most of the essential fields preceding this value to open db.
|
|
|
|
///
|
|
|
|
/// !!! Setting this to true deletes all data for this column !!!
|
|
|
|
bool drop { false };
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
/// Size of the LRU cache for uncompressed blocks
|
2018-09-03 02:31:09 +02:00
|
|
|
ssize_t cache_size { -1 };
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// Size of the LRU cache for compressed blocks
|
2018-09-03 02:31:09 +02:00
|
|
|
ssize_t cache_size_comp { -1 };
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// Bloom filter bits. Filter is still useful even if queries are expected
|
|
|
|
/// to always hit on this column; see `expect_queries_hit` option.
|
2018-04-15 08:00:56 +02:00
|
|
|
size_t bloom_bits { 10 };
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
/// Set this option to true if queries to this column are expected to
|
|
|
|
/// find keys that exist. This is useful for columns with keys that
|
|
|
|
/// were first found from values in another column, where if the first
|
|
|
|
/// column missed there'd be no reason to query this column.
|
|
|
|
bool expect_queries_hit { false };
|
2018-09-18 06:26:55 +02:00
|
|
|
|
|
|
|
/// Data block size for uncompressed data. Compression will make the
|
|
|
|
/// block smaller when it IO's to and from disk. Smaller blocks may be
|
|
|
|
/// more space and query overhead if values exceed this size. Larger
|
|
|
|
/// blocks will read and cache unrelated data if values are smaller
|
|
|
|
/// than this size.
|
|
|
|
size_t block_size { 512 };
|
2018-09-19 00:07:09 +02:00
|
|
|
|
2018-10-16 22:25:45 +02:00
|
|
|
/// Data block size for metadata blocks. Other configuration which may
|
|
|
|
/// not yet be in this descriptor affects the best choice of this param;
|
|
|
|
/// generally these blocks are preloaded on DB open. They can also
|
|
|
|
/// participate in the block cache. At the time this comment was written
|
|
|
|
/// top-level metadata blocks are preloaded and leaf blocks are put in
|
|
|
|
/// the cache.
|
|
|
|
size_t meta_block_size { 512 };
|
|
|
|
|
2018-11-03 02:08:40 +01:00
|
|
|
/// Compression algorithm for this column. Empty string is equal to
|
|
|
|
/// kNoCompression. List is semicolon separated to allow fallbacks in
|
|
|
|
/// case the first algorithms are not supported.
|
2018-12-01 00:20:35 +01:00
|
|
|
std::string compression {"kLZ4Compression;kSnappyCompression"};
|
2018-11-03 02:08:40 +01:00
|
|
|
|
2018-09-19 00:07:09 +02:00
|
|
|
/// User given compaction callback surface.
|
|
|
|
db::compactor compactor {};
|
2019-08-26 21:14:26 +02:00
|
|
|
|
2020-03-13 21:25:20 +01:00
|
|
|
/// Compaction priority algorithm
|
2020-09-12 12:42:16 +02:00
|
|
|
std::string compaction_pri {};
|
2020-03-13 21:25:20 +01:00
|
|
|
|
2019-08-26 21:14:26 +02:00
|
|
|
/// Compaction related parameters. see: rocksdb/advanced_options.h
|
|
|
|
struct
|
|
|
|
{
|
2020-03-19 01:13:33 +01:00
|
|
|
size_t base {128_MiB};
|
|
|
|
size_t multiplier {2};
|
2019-08-26 21:14:26 +02:00
|
|
|
}
|
|
|
|
target_file_size;
|
|
|
|
|
|
|
|
/// Compaction related parameters. see: rocksdb/advanced_options.h
|
|
|
|
struct max_bytes_for_level
|
|
|
|
{
|
|
|
|
size_t base {0};
|
|
|
|
size_t multiplier {1};
|
|
|
|
}
|
|
|
|
max_bytes_for_level[8]
|
|
|
|
{
|
2019-08-27 07:40:13 +02:00
|
|
|
{ 32_MiB, 1L }, // max_bytes_for_level_base
|
|
|
|
{ 0L, 0L }, // max_bytes_for_level[0]
|
2019-08-26 21:14:26 +02:00
|
|
|
{ 0L, 1L }, // max_bytes_for_level[1]
|
|
|
|
{ 0L, 1L }, // max_bytes_for_level[2]
|
2019-08-27 07:40:13 +02:00
|
|
|
{ 0L, 3L }, // max_bytes_for_level[3]
|
|
|
|
{ 0L, 7L }, // max_bytes_for_level[4]
|
|
|
|
{ 0L, 15L }, // max_bytes_for_level[5]
|
|
|
|
{ 0L, 31L }, // max_bytes_for_level[6]
|
2019-08-26 21:14:26 +02:00
|
|
|
};
|
2020-06-07 14:30:17 +02:00
|
|
|
|
|
|
|
/// Forces compaction within a certain limit of time
|
|
|
|
seconds compaction_period
|
|
|
|
{
|
|
|
|
60s * 60 * 24 * 21 // 21 day period
|
|
|
|
};
|
2018-01-19 02:59:22 +01:00
|
|
|
};
|