2018-01-18 03:14:13 +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
|
2018-02-04 03:22:01 +01:00
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2020-05-03 04:17:21 +02:00
|
|
|
#include "db.h"
|
2018-05-30 09:14:07 +02:00
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
/// Dedicated logging facility for the database subsystem
|
2018-01-24 00:39:44 +01:00
|
|
|
decltype(ircd::db::log)
|
|
|
|
ircd::db::log
|
2017-09-20 06:40:53 +02:00
|
|
|
{
|
|
|
|
"db", 'D'
|
|
|
|
};
|
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
/// Dedicated logging facility for rocksdb's log callbacks
|
2018-01-24 00:39:44 +01:00
|
|
|
decltype(ircd::db::rog)
|
|
|
|
ircd::db::rog
|
2017-09-30 08:07:55 +02:00
|
|
|
{
|
2019-04-05 23:37:10 +02:00
|
|
|
"db.rocksdb"
|
2018-01-24 00:39:44 +01:00
|
|
|
};
|
2017-09-30 08:07:55 +02:00
|
|
|
|
2020-05-03 04:17:21 +02:00
|
|
|
decltype(ircd::db::version_api)
|
|
|
|
ircd::db::version_api
|
|
|
|
{
|
|
|
|
"RocksDB", info::versions::API, 0,
|
|
|
|
{
|
|
|
|
ROCKSDB_MAJOR, ROCKSDB_MINOR, ROCKSDB_PATCH,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-06 07:42:11 +02:00
|
|
|
extern "C" const char *
|
|
|
|
rocksdb_build_git_sha;
|
|
|
|
|
|
|
|
extern "C" const char *
|
|
|
|
rocksdb_build_compile_date;
|
|
|
|
|
2020-05-03 04:17:21 +02:00
|
|
|
decltype(ircd::db::version_abi)
|
|
|
|
ircd::db::version_abi
|
|
|
|
{
|
2020-05-06 07:42:11 +02:00
|
|
|
"RocksDB", info::versions::ABI, 0, {0}, []
|
|
|
|
(auto &, const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2020-06-19 12:01:17 +02:00
|
|
|
buf, "%s (%s)",
|
2020-05-06 07:42:11 +02:00
|
|
|
lstrip(rocksdb_build_git_sha, "rocksdb_build_git_sha:"),
|
|
|
|
rocksdb_build_compile_date,
|
|
|
|
};
|
|
|
|
}
|
2020-05-03 04:17:21 +02:00
|
|
|
};
|
|
|
|
|
2018-08-22 23:08:27 +02:00
|
|
|
ircd::conf::item<size_t>
|
|
|
|
ircd::db::request_pool_stack_size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.db.request_pool.stack_size" },
|
|
|
|
{ "default", long(128_KiB) },
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::conf::item<size_t>
|
|
|
|
ircd::db::request_pool_size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.db.request_pool.size" },
|
2020-06-09 02:09:22 +02:00
|
|
|
{ "default", 0L },
|
2018-08-22 23:08:27 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
request.set(size_t(request_pool_size));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-28 21:57:32 +01:00
|
|
|
decltype(ircd::db::request_pool_opts)
|
|
|
|
ircd::db::request_pool_opts
|
|
|
|
{
|
|
|
|
size_t(request_pool_stack_size),
|
|
|
|
size_t(request_pool_size),
|
|
|
|
-1, // No hard limit
|
|
|
|
0, // Soft limit at any queued
|
|
|
|
true, // Yield before hitting soft limit
|
|
|
|
};
|
|
|
|
|
2018-08-19 04:30:25 +02:00
|
|
|
/// Concurrent request pool. Requests to seek may be executed on this
|
|
|
|
/// pool in cases where a single context would find it advantageous.
|
|
|
|
/// Some examples are a db::row seek, or asynchronous prefetching.
|
|
|
|
///
|
|
|
|
/// The number of workers in this pool should upper bound at the
|
|
|
|
/// number of concurrent AIO requests which are effective on this
|
|
|
|
/// system. This is a static pool shared by all databases.
|
|
|
|
decltype(ircd::db::request)
|
|
|
|
ircd::db::request
|
|
|
|
{
|
2018-12-28 21:57:32 +01:00
|
|
|
"db req", request_pool_opts
|
2018-08-19 07:10:39 +02:00
|
|
|
};
|
|
|
|
|
2018-08-30 16:21:44 +02:00
|
|
|
/// This mutex is necessary to serialize entry into rocksdb's write impl
|
|
|
|
/// otherwise there's a risk of a deadlock if their internal pthread
|
|
|
|
/// mutexes are contended. This is because a few parts of rocksdb are
|
|
|
|
/// incorrectly using std::mutex directly when they ought to be using their
|
|
|
|
/// rocksdb::port wrapper.
|
2018-08-27 05:24:38 +02:00
|
|
|
decltype(ircd::db::write_mutex)
|
|
|
|
ircd::db::write_mutex;
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
2020-10-11 20:03:45 +02:00
|
|
|
decltype(ircd::db::init::direct_io_test_file_path)
|
|
|
|
ircd::db::init::direct_io_test_file_path
|
2020-06-05 00:51:48 +02:00
|
|
|
{
|
|
|
|
fs::path_string(fs::path_views
|
|
|
|
{
|
|
|
|
fs::base::db, "SUPPORTS_DIRECT_IO"_sv
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2018-06-12 09:24:59 +02:00
|
|
|
ircd::db::init::init()
|
2019-05-24 07:43:41 +02:00
|
|
|
try
|
2018-06-12 09:24:59 +02:00
|
|
|
{
|
2020-05-30 12:59:10 +02:00
|
|
|
#ifdef IRCD_DB_HAS_ALLOCATOR
|
2020-05-30 05:32:20 +02:00
|
|
|
database::allocator::init();
|
2020-05-30 12:59:10 +02:00
|
|
|
#endif
|
2019-06-07 03:43:18 +02:00
|
|
|
compressions();
|
|
|
|
directory();
|
2020-06-09 02:09:22 +02:00
|
|
|
request_pool();
|
2019-06-07 03:43:18 +02:00
|
|
|
test_direct_io();
|
|
|
|
test_hw_crc32();
|
2018-06-12 09:24:59 +02:00
|
|
|
}
|
2019-05-24 07:43:41 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "Cannot start database system :%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2018-06-12 09:24:59 +02:00
|
|
|
|
|
|
|
ircd::db::init::~init()
|
|
|
|
noexcept
|
2017-08-23 23:37:06 +02:00
|
|
|
{
|
2019-08-25 02:40:31 +02:00
|
|
|
delete prefetcher;
|
|
|
|
prefetcher = nullptr;
|
|
|
|
|
2018-08-28 20:51:36 +02:00
|
|
|
if(request.active())
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "Terminating %zu active of %zu client request contexts; %zu pending; %zu queued",
|
|
|
|
request.active(),
|
|
|
|
request.size(),
|
|
|
|
request.pending(),
|
|
|
|
request.queued()
|
|
|
|
};
|
|
|
|
|
|
|
|
request.terminate();
|
2018-08-28 23:04:43 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Waiting for %zu active of %zu client request contexts; %zu pending; %zu queued",
|
|
|
|
request.active(),
|
|
|
|
request.size(),
|
|
|
|
request.pending(),
|
|
|
|
request.queued()
|
|
|
|
};
|
2018-08-28 20:51:36 +02:00
|
|
|
|
2018-08-28 23:04:43 +02:00
|
|
|
request.join();
|
2018-08-28 20:51:36 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "All contexts joined; all requests are clear."
|
|
|
|
};
|
2020-05-30 03:05:16 +02:00
|
|
|
|
2020-05-30 12:59:10 +02:00
|
|
|
#ifdef IRCD_DB_HAS_ALLOCATOR
|
2020-05-30 05:32:20 +02:00
|
|
|
database::allocator::fini();
|
2020-05-30 12:59:10 +02:00
|
|
|
#endif
|
2017-08-23 23:37:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 09:24:59 +02:00
|
|
|
void
|
2019-06-07 03:43:18 +02:00
|
|
|
ircd::db::init::directory()
|
2017-08-23 22:37:47 +02:00
|
|
|
try
|
|
|
|
{
|
2020-04-19 09:26:54 +02:00
|
|
|
const string_view &dbdir
|
2018-04-03 02:18:02 +02:00
|
|
|
{
|
2020-04-19 09:26:54 +02:00
|
|
|
fs::base::db
|
2018-04-03 02:18:02 +02:00
|
|
|
};
|
|
|
|
|
2019-04-15 20:08:40 +02:00
|
|
|
if(!fs::is_dir(dbdir) && (ircd::read_only || ircd::write_avoid))
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "Not creating database directory `%s' in read-only/write-avoid mode.", dbdir
|
|
|
|
};
|
|
|
|
else if(fs::mkdir(dbdir))
|
2018-08-16 10:27:43 +02:00
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
log, "Created new database directory at `%s'", dbdir
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
else
|
2018-08-16 10:27:43 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "Using database directory at `%s'", dbdir
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
2018-12-16 04:50:15 +01:00
|
|
|
catch(const fs::error &e)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-05-24 07:43:41 +02:00
|
|
|
log::error
|
2018-08-16 10:27:43 +02:00
|
|
|
{
|
2019-05-24 07:43:41 +02:00
|
|
|
log, "Database directory error: %s", e.what()
|
2018-08-16 10:27:43 +02:00
|
|
|
};
|
|
|
|
|
2018-12-16 04:50:15 +01:00
|
|
|
throw;
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 11:09:49 +02:00
|
|
|
void
|
2019-06-07 03:43:18 +02:00
|
|
|
ircd::db::init::test_direct_io()
|
2018-09-04 11:09:49 +02:00
|
|
|
try
|
|
|
|
{
|
2020-06-05 00:51:48 +02:00
|
|
|
const auto &test_file_path
|
2018-09-13 14:43:30 +02:00
|
|
|
{
|
2020-06-05 00:51:48 +02:00
|
|
|
direct_io_test_file_path
|
2018-09-13 14:43:30 +02:00
|
|
|
};
|
|
|
|
|
2018-12-03 21:43:42 +01:00
|
|
|
if(fs::support::direct_io(test_file_path))
|
2018-09-04 11:09:49 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Detected Direct-IO works by opening test file at `%s'",
|
2018-09-13 14:43:30 +02:00
|
|
|
test_file_path
|
2018-09-04 11:09:49 +02:00
|
|
|
};
|
|
|
|
else
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "Direct-IO is not supported in the database directory `%s'"
|
|
|
|
"; Concurrent database queries will not be possible.",
|
2020-04-19 09:26:54 +02:00
|
|
|
string_view{fs::base::db}
|
2018-09-04 11:09:49 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Failed to test if Direct-IO possible with test file `%s'"
|
|
|
|
"; Concurrent database queries will not be possible :%s",
|
2020-06-05 00:51:48 +02:00
|
|
|
direct_io_test_file_path,
|
2018-09-04 11:09:49 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-23 00:13:22 +02:00
|
|
|
namespace rocksdb::crc32c
|
|
|
|
{
|
|
|
|
extern std::string IsFastCrc32Supported();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-07 03:43:18 +02:00
|
|
|
ircd::db::init::test_hw_crc32()
|
2019-05-24 07:43:41 +02:00
|
|
|
try
|
2019-04-23 00:13:22 +02:00
|
|
|
{
|
|
|
|
const auto supported_str
|
|
|
|
{
|
|
|
|
rocksdb::crc32c::IsFastCrc32Supported()
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool supported
|
|
|
|
{
|
|
|
|
startswith(supported_str, "Supported")
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(supported || startswith(supported_str, "Not supported"));
|
|
|
|
|
|
|
|
if(!supported)
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "crc32c hardware acceleration is not available on this platform."
|
|
|
|
};
|
|
|
|
}
|
2019-05-24 07:43:41 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Failed to test crc32c hardware acceleration support :%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2019-04-23 00:13:22 +02:00
|
|
|
|
2018-11-03 02:02:27 +01:00
|
|
|
decltype(ircd::db::compressions)
|
|
|
|
ircd::db::compressions;
|
|
|
|
|
2018-06-12 09:24:59 +02:00
|
|
|
void
|
2019-06-07 03:43:18 +02:00
|
|
|
ircd::db::init::compressions()
|
2019-05-24 07:43:41 +02:00
|
|
|
try
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2018-11-03 02:02:27 +01:00
|
|
|
auto supported
|
2018-06-12 09:24:59 +02:00
|
|
|
{
|
|
|
|
rocksdb::GetSupportedCompressions()
|
|
|
|
};
|
|
|
|
|
2019-06-02 10:03:28 +02:00
|
|
|
size_t i(0);
|
|
|
|
for(const rocksdb::CompressionType &type_ : supported) try
|
2018-11-03 02:02:27 +01:00
|
|
|
{
|
2019-06-02 10:03:28 +02:00
|
|
|
auto &[string, type]
|
|
|
|
{
|
2019-06-07 03:43:18 +02:00
|
|
|
db::compressions.at(i++)
|
2019-06-02 10:03:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
type = type_;
|
2018-11-03 02:02:27 +01:00
|
|
|
throw_on_error
|
|
|
|
{
|
2019-06-02 10:03:28 +02:00
|
|
|
rocksdb::GetStringFromCompressionType(&string, type_)
|
|
|
|
};
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Detected supported compression #%zu type:%lu :%s",
|
|
|
|
i,
|
|
|
|
type,
|
|
|
|
string,
|
2018-11-03 02:02:27 +01:00
|
|
|
};
|
|
|
|
}
|
2019-05-24 07:43:41 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Failed to identify compression type:%u :%s",
|
2019-06-02 10:03:28 +02:00
|
|
|
uint(type_),
|
2019-05-24 07:43:41 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-11-03 02:02:27 +01:00
|
|
|
|
|
|
|
if(supported.empty())
|
2018-06-12 09:24:59 +02:00
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
"No compression libraries have been linked with the DB."
|
|
|
|
" This is probably not what you want."
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
2019-05-24 07:43:41 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Failed to initialize database compressions :%s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2020-06-09 02:09:22 +02:00
|
|
|
void
|
|
|
|
ircd::db::init::request_pool()
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
const string_view value
|
|
|
|
{
|
|
|
|
conf::get(buf, "ircd.fs.aio.max_events")
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t aio_max_events
|
|
|
|
{
|
|
|
|
lex_castable<size_t>(value)?
|
|
|
|
lex_cast<size_t>(value):
|
|
|
|
0UL
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t new_size
|
|
|
|
{
|
|
|
|
size_t(request_pool_size)?
|
|
|
|
request_pool_size:
|
|
|
|
aio_max_events?
|
|
|
|
aio_max_events:
|
|
|
|
1UL
|
|
|
|
};
|
|
|
|
|
|
|
|
request_pool_size.set(lex_cast(new_size));
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:19:02 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-09-19 00:15:02 +02:00
|
|
|
// db/stats.h
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::string(const rocksdb::IOStatsContext &ic,
|
|
|
|
const bool &all)
|
2018-03-28 00:21:30 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
const bool exclude_zeros(!all);
|
|
|
|
return ic.ToString(exclude_zeros);
|
2018-03-28 00:21:30 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const rocksdb::IOStatsContext &
|
|
|
|
ircd::db::iostats_current()
|
2018-03-23 04:49:11 +01:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
const auto *const &ret
|
2018-03-23 04:49:11 +01:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::get_iostats_context()
|
|
|
|
};
|
2018-03-23 04:49:11 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
if(unlikely(!ret))
|
|
|
|
throw error
|
2018-08-20 04:30:17 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
"IO counters are not available on this thread."
|
2018-08-20 04:30:17 +02:00
|
|
|
};
|
2018-03-23 04:49:11 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
return *ret;
|
|
|
|
}
|
2018-08-20 04:30:17 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::string(const rocksdb::PerfContext &pc,
|
|
|
|
const bool &all)
|
|
|
|
{
|
|
|
|
const bool exclude_zeros(!all);
|
|
|
|
return pc.ToString(exclude_zeros);
|
|
|
|
}
|
2018-03-23 04:49:11 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const rocksdb::PerfContext &
|
|
|
|
ircd::db::perf_current()
|
|
|
|
{
|
|
|
|
const auto *const &ret
|
|
|
|
{
|
|
|
|
rocksdb::get_perf_context()
|
|
|
|
};
|
2018-03-23 04:49:11 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
if(unlikely(!ret))
|
|
|
|
throw error
|
2018-03-23 04:49:11 +01:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
"Performance counters are not available on this thread."
|
2018-03-23 04:49:11 +01:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
return *ret;
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::perf_level(const uint &level)
|
2017-09-19 05:40:13 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
if(level >= rocksdb::PerfLevel::kOutOfBounds)
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Perf level of '%u' is invalid; maximum is '%u'",
|
|
|
|
level,
|
|
|
|
uint(rocksdb::PerfLevel::kOutOfBounds)
|
|
|
|
};
|
2017-09-19 05:40:13 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::SetPerfLevel(rocksdb::PerfLevel(level));
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
uint
|
|
|
|
ircd::db::perf_level()
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
return rocksdb::GetPerfLevel();
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
//
|
|
|
|
// ticker
|
|
|
|
//
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::ticker(const database &d,
|
|
|
|
const string_view &key)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
return ticker(d, ticker_id(key));
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::ticker(const database &d,
|
|
|
|
const uint32_t &id)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
return d.stats->getTickerCount(id);
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
uint32_t
|
|
|
|
ircd::db::ticker_id(const string_view &key)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
for(const auto &pair : rocksdb::TickersNameMap)
|
|
|
|
if(key == pair.second)
|
|
|
|
return pair.first;
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"No ticker with that key"
|
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::ticker_id(const uint32_t &id)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
for(const auto &pair : rocksdb::TickersNameMap)
|
|
|
|
if(id == pair.first)
|
|
|
|
return pair.second;
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
return {};
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
decltype(ircd::db::ticker_max)
|
|
|
|
ircd::db::ticker_max
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::TICKER_ENUM_MAX
|
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
//
|
|
|
|
// histogram
|
|
|
|
//
|
|
|
|
|
|
|
|
const struct ircd::db::histogram &
|
|
|
|
ircd::db::histogram(const database &d,
|
|
|
|
const string_view &key)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
return histogram(d, histogram_id(key));
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const struct ircd::db::histogram &
|
|
|
|
ircd::db::histogram(const database &d,
|
|
|
|
const uint32_t &id)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
return d.stats->histogram.at(id);
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
uint32_t
|
|
|
|
ircd::db::histogram_id(const string_view &key)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
for(const auto &pair : rocksdb::HistogramsNameMap)
|
|
|
|
if(key == pair.second)
|
|
|
|
return pair.first;
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw std::out_of_range
|
2018-05-29 10:09:15 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
"No histogram with that key"
|
2018-05-29 10:09:15 +02:00
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::histogram_id(const uint32_t &id)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
for(const auto &pair : rocksdb::HistogramsNameMap)
|
|
|
|
if(id == pair.first)
|
|
|
|
return pair.second;
|
|
|
|
|
|
|
|
return {};
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
decltype(ircd::db::histogram_max)
|
|
|
|
ircd::db::histogram_max
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::HISTOGRAM_ENUM_MAX
|
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
2019-09-19 00:15:02 +02:00
|
|
|
// db/prefetcher.h
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
decltype(ircd::db::prefetcher)
|
|
|
|
ircd::db::prefetcher;
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
//
|
|
|
|
// db::prefetcher
|
|
|
|
//
|
|
|
|
ircd::db::prefetcher::prefetcher()
|
2019-09-20 20:08:07 +02:00
|
|
|
:ticker
|
|
|
|
{
|
|
|
|
std::make_unique<struct ticker>()
|
|
|
|
}
|
|
|
|
,context
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
"db.prefetcher",
|
|
|
|
128_KiB,
|
|
|
|
context::POST,
|
|
|
|
std::bind(&prefetcher::worker, this)
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
2018-03-23 04:48:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::prefetcher::~prefetcher()
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
while(!queue.empty())
|
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "Prefetcher waiting for %zu requests to clear...",
|
|
|
|
queue.size(),
|
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
dock.wait_for(seconds(5), [this]
|
|
|
|
{
|
|
|
|
return queue.empty();
|
|
|
|
});
|
|
|
|
}
|
2017-09-19 04:19:02 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
assert(queue.empty());
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
bool
|
|
|
|
ircd::db::prefetcher::operator()(column &c,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &opts)
|
|
|
|
{
|
|
|
|
auto &d
|
|
|
|
{
|
|
|
|
static_cast<database &>(c)
|
|
|
|
};
|
|
|
|
|
2019-09-20 20:08:07 +02:00
|
|
|
assert(ticker);
|
|
|
|
ticker->queries++;
|
2019-09-19 01:28:51 +02:00
|
|
|
if(db::cached(c, key, opts))
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->rejects++;
|
2019-09-19 01:28:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
queue.emplace_back(d, c, key);
|
|
|
|
queue.back().snd = now<steady_point>();
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->request++;
|
2019-09-19 01:28:51 +02:00
|
|
|
|
|
|
|
// Branch here based on whether it's not possible to directly dispatch
|
|
|
|
// a db::request worker. If all request workers are busy we notify our own
|
|
|
|
// prefetcher worker, and then it blocks on submitting to the request
|
|
|
|
// worker instead of us blocking here. This is done to avoid use and growth
|
|
|
|
// of any request pool queue, and allow for more direct submission.
|
|
|
|
if(db::request.wouldblock())
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
dock.notify_one();
|
2019-09-19 05:29:18 +02:00
|
|
|
|
|
|
|
// If the user sets NO_BLOCKING we honor their request to not
|
|
|
|
// context switch for a prefetch. However by default we want to
|
|
|
|
// control queue growth, so we insert voluntary yield here to allow
|
|
|
|
// prefetch operations to at least be processed before returning to
|
|
|
|
// the user submitting more prefetches.
|
|
|
|
if(likely(!test(opts, db::get::NO_BLOCKING)))
|
|
|
|
ctx::yield();
|
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 05:29:18 +02:00
|
|
|
const ctx::critical_assertion ca;
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->directs++;
|
2019-09-19 01:28:51 +02:00
|
|
|
this->handle();
|
2019-09-19 00:15:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::prefetcher::cancel(column &c)
|
|
|
|
{
|
|
|
|
return cancel([&c]
|
|
|
|
(const auto &request)
|
|
|
|
{
|
|
|
|
return request.cid == id(c);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::prefetcher::cancel(database &d)
|
|
|
|
{
|
|
|
|
return cancel([&d]
|
|
|
|
(const auto &request)
|
|
|
|
{
|
|
|
|
return request.d == std::addressof(d);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::prefetcher::cancel(const closure &closure)
|
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
size_t canceled(0);
|
|
|
|
for(auto &request : queue)
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
// already finished
|
|
|
|
if(request.fin != steady_point::min())
|
|
|
|
continue;
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
// in progress; can't cancel
|
|
|
|
if(request.req != steady_point::min())
|
|
|
|
continue;
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
// allow user to accept or reject
|
|
|
|
if(!closure(request))
|
|
|
|
continue;
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
// cancel by precociously setting the finish time.
|
|
|
|
request.fin = now<steady_point>();
|
|
|
|
++canceled;
|
|
|
|
}
|
2019-09-19 00:15:02 +02:00
|
|
|
|
|
|
|
if(canceled)
|
|
|
|
dock.notify_all();
|
|
|
|
|
2019-09-20 20:08:07 +02:00
|
|
|
assert(ticker);
|
|
|
|
ticker->cancels += canceled;
|
2019-09-19 00:15:02 +02:00
|
|
|
return canceled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::prefetcher::worker()
|
|
|
|
try
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
dock.wait([this]
|
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
if(queue.empty())
|
|
|
|
return false;
|
|
|
|
|
2019-09-20 20:08:07 +02:00
|
|
|
assert(ticker);
|
|
|
|
if(ticker->request <= ticker->handles)
|
2019-09-19 01:28:51 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2019-09-19 00:15:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
handle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "prefetcher worker: %s",
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::prefetcher::handle()
|
|
|
|
{
|
|
|
|
auto handler
|
|
|
|
{
|
|
|
|
std::bind(&prefetcher::request_worker, this)
|
|
|
|
};
|
|
|
|
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->handles++;
|
2019-09-19 01:28:51 +02:00
|
|
|
db::request(std::move(handler));
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->handled++;
|
2019-09-19 00:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::prefetcher::request_worker()
|
|
|
|
{
|
|
|
|
const ctx::scope_notify notify
|
|
|
|
{
|
|
|
|
this->dock
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope_count request_workers
|
|
|
|
{
|
|
|
|
this->request_workers
|
|
|
|
};
|
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
// Garbage collection of the queue invoked unconditionally on unwind.
|
|
|
|
const unwind cleanup_on_leave
|
|
|
|
{
|
|
|
|
std::bind(&prefetcher::request_cleanup, this)
|
|
|
|
};
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
// GC the queue here to get rid of any cancelled requests which have
|
|
|
|
// arrived at the front so they don't become our request.
|
|
|
|
const size_t cleanup_on_enter
|
|
|
|
{
|
|
|
|
request_cleanup()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find the first request in the queue which does not have its req
|
|
|
|
// timestamp sent.
|
2019-09-19 00:15:02 +02:00
|
|
|
auto request
|
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
std::find_if(begin(queue), end(queue), []
|
|
|
|
(const auto &request)
|
|
|
|
{
|
|
|
|
return request.req == steady_point::min();
|
|
|
|
})
|
2019-09-19 00:15:02 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
if(request == end(queue))
|
|
|
|
return;
|
|
|
|
|
2019-09-20 20:08:07 +02:00
|
|
|
assert(ticker);
|
2019-09-19 01:28:51 +02:00
|
|
|
assert(request->fin == steady_point::min());
|
2019-09-20 20:08:07 +02:00
|
|
|
request->req = now<steady_point>();
|
|
|
|
ticker->last_snd_req = duration_cast<microseconds>(request->req - request->snd);
|
|
|
|
ticker->accum_snd_req += ticker->last_snd_req;
|
|
|
|
|
|
|
|
ticker->fetches++;
|
2019-09-19 01:28:51 +02:00
|
|
|
request_handle(*request);
|
2019-09-19 07:11:00 +02:00
|
|
|
assert(request->fin != steady_point::min());
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->fetched++;
|
2019-09-19 01:28:51 +02:00
|
|
|
|
|
|
|
#ifdef IRCD_DB_DEBUG_PREFETCH
|
|
|
|
log::debug
|
|
|
|
{
|
2019-09-20 20:08:07 +02:00
|
|
|
log, "prefetcher reject:%zu request:%zu handle:%zu fetch:%zu direct:%zu cancel:%zu queue:%zu rw:%zu",
|
|
|
|
ticker->rejects,
|
|
|
|
ticker->request,
|
|
|
|
ticker->handles,
|
|
|
|
ticker->fetches,
|
|
|
|
ticker->directs,
|
|
|
|
ticker->cancels,
|
2019-09-19 01:28:51 +02:00
|
|
|
queue.size(),
|
|
|
|
this->request_workers,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::prefetcher::request_cleanup()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
size_t removed(0);
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
for(; !queue.empty() && queue.front().fin != steady_point::min(); ++removed)
|
|
|
|
queue.pop_front();
|
|
|
|
|
|
|
|
return removed;
|
2019-09-19 00:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::prefetcher::request_handle(request &request)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
assert(request.d);
|
|
|
|
db::column column
|
|
|
|
{
|
|
|
|
(*request.d)[request.cid]
|
|
|
|
};
|
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
const string_view key
|
|
|
|
{
|
|
|
|
request
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto it
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2019-09-19 01:28:51 +02:00
|
|
|
seek(column, key, gopts{})
|
2019-09-19 00:15:02 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 07:11:00 +02:00
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
request.fin = now<steady_point>();
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->last_req_fin = duration_cast<microseconds>(request.fin - request.req);
|
|
|
|
ticker->accum_req_fin += ticker->last_req_fin;
|
2019-09-19 01:28:51 +02:00
|
|
|
const bool lte
|
|
|
|
{
|
|
|
|
valid_lte(*it, key)
|
|
|
|
};
|
|
|
|
|
2019-09-19 07:11:00 +02:00
|
|
|
if(likely(lte))
|
|
|
|
{
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->fetched_bytes_key += size(it->key());
|
|
|
|
ticker->fetched_bytes_val += size(it->value());
|
2019-09-19 07:11:00 +02:00
|
|
|
}
|
2019-09-19 01:28:51 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
#ifdef IRCD_DB_DEBUG_PREFETCH
|
2019-09-19 01:28:51 +02:00
|
|
|
char pbuf[3][32];
|
2019-09-19 00:15:02 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-19 07:11:00 +02:00
|
|
|
log, "[%s][%s] completed prefetch len:%zu lte:%b k:%zu v:%zu snd-req:%s req-fin:%s snd-fin:%s queue:%zu",
|
2019-09-19 00:15:02 +02:00
|
|
|
name(*request.d),
|
|
|
|
name(column),
|
2019-09-19 01:28:51 +02:00
|
|
|
size(key),
|
|
|
|
lte,
|
2019-09-19 07:11:00 +02:00
|
|
|
lte? size(it->key()) : 0UL,
|
|
|
|
lte? size(it->value()) : 0UL,
|
2019-09-19 01:28:51 +02:00
|
|
|
pretty(pbuf[0], request.req - request.snd, 1),
|
|
|
|
pretty(pbuf[1], request.fin - request.req, 1),
|
|
|
|
pretty(pbuf[2], request.fin - request.snd, 1),
|
2019-09-19 00:15:02 +02:00
|
|
|
queue.size(),
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
assert(request.d);
|
2019-09-19 01:28:51 +02:00
|
|
|
request.fin = now<steady_point>();
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "[%s][%u] :%s",
|
|
|
|
name(*request.d),
|
|
|
|
request.cid,
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
}
|
2019-09-19 01:28:51 +02:00
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
request.fin = now<steady_point>();
|
|
|
|
throw;
|
|
|
|
}
|
2019-09-19 00:15:02 +02:00
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::prefetcher::wait_pending()
|
|
|
|
{
|
|
|
|
const size_t fetched_counter
|
|
|
|
{
|
2019-09-20 20:08:07 +02:00
|
|
|
ticker->fetched
|
2019-09-19 00:15:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const size_t fetched_target
|
|
|
|
{
|
|
|
|
fetched_counter + request_workers
|
|
|
|
};
|
|
|
|
|
|
|
|
dock.wait([this, &fetched_target]
|
|
|
|
{
|
2019-09-20 20:08:07 +02:00
|
|
|
return this->ticker->fetched >= fetched_target;
|
2019-09-19 00:15:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
assert(fetched_target >= fetched_counter);
|
|
|
|
return fetched_target - fetched_counter;
|
|
|
|
}
|
|
|
|
|
2019-09-19 01:28:51 +02:00
|
|
|
//
|
|
|
|
// prefetcher::request
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::prefetcher::request::request(database &d,
|
|
|
|
const column &c,
|
|
|
|
const string_view &key)
|
|
|
|
noexcept
|
|
|
|
:d
|
|
|
|
{
|
|
|
|
std::addressof(d)
|
|
|
|
}
|
|
|
|
,cid
|
|
|
|
{
|
|
|
|
db::id(c)
|
|
|
|
}
|
|
|
|
,len
|
|
|
|
{
|
|
|
|
uint32_t(std::min(size(key), sizeof(this->key)))
|
|
|
|
}
|
|
|
|
,snd
|
|
|
|
{
|
|
|
|
steady_point::min()
|
|
|
|
}
|
|
|
|
,req
|
|
|
|
{
|
|
|
|
steady_point::min()
|
|
|
|
}
|
|
|
|
,fin
|
|
|
|
{
|
|
|
|
steady_point::min()
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const size_t &len
|
|
|
|
{
|
|
|
|
buffer::copy(this->key, key)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(this->len == len);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::prefetcher::request::operator
|
|
|
|
ircd::string_view()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
key, len
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// db/txn.h
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::get(database &d,
|
|
|
|
const uint64_t &seq,
|
|
|
|
const seq_closure &closure)
|
|
|
|
{
|
|
|
|
for_each(d, seq, seq_closure_bool{[&closure]
|
|
|
|
(txn &txn, const uint64_t &seq)
|
|
|
|
{
|
|
|
|
closure(txn, seq);
|
|
|
|
return false;
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::for_each(database &d,
|
|
|
|
const uint64_t &seq,
|
|
|
|
const seq_closure &closure)
|
|
|
|
{
|
|
|
|
for_each(d, seq, seq_closure_bool{[&closure]
|
|
|
|
(txn &txn, const uint64_t &seq)
|
|
|
|
{
|
|
|
|
closure(txn, seq);
|
|
|
|
return true;
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::for_each(database &d,
|
|
|
|
const uint64_t &seq,
|
|
|
|
const seq_closure_bool &closure)
|
|
|
|
{
|
|
|
|
std::unique_ptr<rocksdb::TransactionLogIterator> tit;
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->GetUpdatesSince(seq, &tit)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(bool(tit));
|
|
|
|
for(; tit->Valid(); tit->Next())
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
|
|
|
auto batchres
|
|
|
|
{
|
|
|
|
tit->GetBatch()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
tit->status()
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn txn
|
|
|
|
{
|
|
|
|
d, std::move(batchres.writeBatchPtr)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(bool(txn.wb));
|
|
|
|
if(!closure(txn, batchres.sequence))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-28 06:00:35 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::debug(const mutable_buffer &buf,
|
|
|
|
database &d,
|
|
|
|
const rocksdb::WriteBatch &wb_,
|
|
|
|
const ulong &fmt)
|
|
|
|
{
|
|
|
|
auto &wb
|
|
|
|
{
|
|
|
|
mutable_cast(wb_)
|
|
|
|
};
|
|
|
|
|
|
|
|
txn t
|
|
|
|
{
|
|
|
|
d, std::unique_ptr<rocksdb::WriteBatch>{&wb}
|
|
|
|
};
|
|
|
|
|
|
|
|
const unwind release
|
|
|
|
{
|
|
|
|
std::bind(&txn::release, &t)
|
|
|
|
};
|
|
|
|
|
|
|
|
return debug(buf, t, fmt);
|
|
|
|
}
|
|
|
|
|
2020-08-23 12:22:33 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::debug(const mutable_buffer &buf,
|
2020-08-26 01:02:53 +02:00
|
|
|
const txn &t,
|
|
|
|
const ulong &fmt)
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2020-08-26 01:02:53 +02:00
|
|
|
size_t len(0);
|
|
|
|
|
|
|
|
if(fmt >= 0)
|
|
|
|
{
|
|
|
|
const rocksdb::WriteBatch &wb(t);
|
|
|
|
len += size(db::debug(buf, wb));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fmt == 1)
|
|
|
|
{
|
|
|
|
for_each(t, [&buf, &len]
|
|
|
|
(const delta &d)
|
|
|
|
{
|
|
|
|
char pbuf[2][64];
|
|
|
|
len += copy(buf + len, '\n');
|
|
|
|
len += fmt::sprintf
|
|
|
|
{
|
|
|
|
buf + len, "%18s %-12s | [%s...] %-20s => [%s...] %-20s",
|
|
|
|
std::get<delta::COL>(d),
|
|
|
|
reflect(std::get<delta::OP>(d)),
|
|
|
|
"????????"_sv, //std::get<d.KEY>(d),
|
|
|
|
pretty(pbuf[0], iec(size(std::get<delta::KEY>(d)))),
|
|
|
|
"????????"_sv, //std::get<d.VAL>(d),
|
|
|
|
pretty(pbuf[1], iec(size(std::get<delta::VAL>(d)))),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
len += copy(buf + len, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(buf), len
|
|
|
|
};
|
2019-09-19 00:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::for_each(const txn &t,
|
|
|
|
const delta_closure &closure)
|
|
|
|
{
|
|
|
|
const auto re{[&closure]
|
|
|
|
(const delta &delta)
|
|
|
|
{
|
|
|
|
closure(delta);
|
|
|
|
return true;
|
|
|
|
}};
|
|
|
|
|
|
|
|
const database &d(t);
|
|
|
|
const rocksdb::WriteBatch &wb(t);
|
|
|
|
txn::handler h{d, re};
|
|
|
|
wb.Iterate(&h);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::for_each(const txn &t,
|
|
|
|
const delta_closure_bool &closure)
|
|
|
|
{
|
|
|
|
const database &d(t);
|
|
|
|
const rocksdb::WriteBatch &wb(t);
|
|
|
|
txn::handler h{d, closure};
|
|
|
|
wb.Iterate(&h);
|
|
|
|
return h._continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// handler (db/database/txn.h)
|
|
|
|
///
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::PutCF(const uint32_t cfid,
|
|
|
|
const Slice &key,
|
|
|
|
const Slice &val)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::SET, key, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::DeleteCF(const uint32_t cfid,
|
|
|
|
const Slice &key)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::DELETE, key, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::DeleteRangeCF(const uint32_t cfid,
|
|
|
|
const Slice &begin,
|
|
|
|
const Slice &end)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::DELETE_RANGE, begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::SingleDeleteCF(const uint32_t cfid,
|
|
|
|
const Slice &key)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::SINGLE_DELETE, key, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::MergeCF(const uint32_t cfid,
|
|
|
|
const Slice &key,
|
|
|
|
const Slice &value)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::MERGE, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::MarkBeginPrepare(bool b)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
ircd::not_implemented{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::MarkEndPrepare(const Slice &xid)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
ircd::not_implemented{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::MarkCommit(const Slice &xid)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
ircd::not_implemented{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::MarkRollback(const Slice &xid)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
ircd::not_implemented{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::callback(const uint32_t &cfid,
|
|
|
|
const op &op,
|
|
|
|
const Slice &a,
|
|
|
|
const Slice &b)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
auto &c{d[cfid]};
|
|
|
|
const delta delta
|
|
|
|
{
|
|
|
|
op,
|
|
|
|
db::name(c),
|
|
|
|
slice(a),
|
|
|
|
slice(b)
|
|
|
|
};
|
|
|
|
|
|
|
|
return callback(delta);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
_continue = false;
|
|
|
|
log::critical
|
|
|
|
{
|
2020-01-13 02:38:45 +01:00
|
|
|
log, "txn::handler: cfid[%u]: %s",
|
|
|
|
cfid,
|
|
|
|
e.what()
|
2019-09-19 00:15:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ircd::terminate();
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::txn::handler::callback(const delta &delta)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
_continue = cb(delta);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
_continue = false;
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::txn::handler::Continue()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return _continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// txn
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::txn::txn(database &d)
|
|
|
|
:txn{d, opts{}}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::txn::txn(database &d,
|
|
|
|
const opts &opts)
|
|
|
|
:d{&d}
|
|
|
|
,wb
|
|
|
|
{
|
|
|
|
std::make_unique<rocksdb::WriteBatch>(opts.reserve_bytes, opts.max_bytes)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::txn::txn(database &d,
|
|
|
|
std::unique_ptr<rocksdb::WriteBatch> &&wb)
|
|
|
|
:d{&d}
|
|
|
|
,wb{std::move(wb)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::txn::~txn()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::txn::operator()(const sopts &opts)
|
|
|
|
{
|
|
|
|
assert(bool(d));
|
|
|
|
operator()(*d, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::txn::operator()(database &d,
|
|
|
|
const sopts &opts)
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
assert(this->state == state::BUILD);
|
|
|
|
this->state = state::COMMIT;
|
|
|
|
commit(d, *wb, opts);
|
|
|
|
this->state = state::COMMITTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::txn::clear()
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
wb->Clear();
|
2019-03-19 21:13:16 +01:00
|
|
|
this->state = state::BUILD;
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::size()
|
2017-09-19 04:19:02 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
return wb->Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::bytes()
|
2017-09-19 04:19:02 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
return wb->GetDataSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::has(const op &op)
|
2017-09-19 04:19:02 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
switch(op)
|
|
|
|
{
|
|
|
|
case op::GET: assert(0); return false;
|
|
|
|
case op::SET: return wb->HasPut();
|
|
|
|
case op::MERGE: return wb->HasMerge();
|
|
|
|
case op::DELETE: return wb->HasDelete();
|
|
|
|
case op::DELETE_RANGE: return wb->HasDeleteRange();
|
|
|
|
case op::SINGLE_DELETE: return wb->HasSingleDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-19 05:40:13 +02:00
|
|
|
bool
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::has(const op &op,
|
2017-09-19 05:40:13 +02:00
|
|
|
const string_view &col)
|
|
|
|
const
|
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
return !for_each(*this, delta_closure_bool{[&op, &col]
|
2017-09-19 05:40:13 +02:00
|
|
|
(const auto &delta)
|
|
|
|
{
|
2020-05-13 04:03:54 +02:00
|
|
|
return std::get<delta::OP>(delta) != op &&
|
|
|
|
std::get<delta::COL>(delta) != col;
|
2018-04-17 00:16:51 +02:00
|
|
|
}});
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 00:16:51 +02:00
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::at(const op &op,
|
2018-04-17 00:16:51 +02:00
|
|
|
const string_view &col,
|
|
|
|
const delta_closure &closure)
|
2017-09-19 05:40:13 +02:00
|
|
|
const
|
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
if(!get(op, col, closure))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"db::txn::at(%s, %s): no matching delta in transaction",
|
|
|
|
reflect(op),
|
|
|
|
col
|
|
|
|
};
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 00:16:51 +02:00
|
|
|
bool
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::get(const op &op,
|
2018-04-17 00:16:51 +02:00
|
|
|
const string_view &col,
|
|
|
|
const delta_closure &closure)
|
2017-09-19 05:40:13 +02:00
|
|
|
const
|
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
return !for_each(*this, delta_closure_bool{[&op, &col, &closure]
|
2017-09-19 05:40:13 +02:00
|
|
|
(const delta &delta)
|
|
|
|
{
|
2019-06-23 08:28:24 +02:00
|
|
|
if(std::get<delta::OP>(delta) == op &&
|
|
|
|
std::get<delta::COL>(delta) == col)
|
2017-09-19 05:40:13 +02:00
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
closure(delta);
|
|
|
|
return false;
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
2018-04-17 00:16:51 +02:00
|
|
|
else return true;
|
|
|
|
}});
|
|
|
|
}
|
2017-09-19 05:40:13 +02:00
|
|
|
|
2018-04-17 00:16:51 +02:00
|
|
|
bool
|
|
|
|
ircd::db::txn::has(const op &op,
|
|
|
|
const string_view &col,
|
|
|
|
const string_view &key)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return !for_each(*this, delta_closure_bool{[&op, &col, &key]
|
|
|
|
(const auto &delta)
|
|
|
|
{
|
2020-05-13 04:03:54 +02:00
|
|
|
return std::get<delta::OP>(delta) != op &&
|
|
|
|
std::get<delta::COL>(delta) != col &&
|
|
|
|
std::get<delta::KEY>(delta) != key;
|
2018-04-17 00:16:51 +02:00
|
|
|
}});
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 00:16:51 +02:00
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::at(const op &op,
|
2017-09-19 05:40:13 +02:00
|
|
|
const string_view &col,
|
2018-04-17 00:16:51 +02:00
|
|
|
const string_view &key,
|
|
|
|
const value_closure &closure)
|
2017-09-19 05:40:13 +02:00
|
|
|
const
|
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
if(!get(op, col, key, closure))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"db::txn::at(%s, %s, %s): no matching delta in transaction",
|
|
|
|
reflect(op),
|
|
|
|
col,
|
|
|
|
key
|
|
|
|
};
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 00:16:51 +02:00
|
|
|
bool
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::get(const op &op,
|
2017-09-19 05:40:13 +02:00
|
|
|
const string_view &col,
|
2018-04-17 00:16:51 +02:00
|
|
|
const string_view &key,
|
|
|
|
const value_closure &closure)
|
2017-09-19 05:40:13 +02:00
|
|
|
const
|
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
return !for_each(*this, delta_closure_bool{[&op, &col, &key, &closure]
|
2017-09-19 05:40:13 +02:00
|
|
|
(const delta &delta)
|
|
|
|
{
|
2019-06-23 08:28:24 +02:00
|
|
|
if(std::get<delta::OP>(delta) == op &&
|
|
|
|
std::get<delta::COL>(delta) == col &&
|
|
|
|
std::get<delta::KEY>(delta) == key)
|
2017-09-19 05:40:13 +02:00
|
|
|
{
|
2019-06-23 08:28:24 +02:00
|
|
|
closure(std::get<delta::VAL>(delta));
|
2018-04-17 00:16:51 +02:00
|
|
|
return false;
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
2018-04-17 00:16:51 +02:00
|
|
|
else return true;
|
|
|
|
}});
|
2017-09-19 05:40:13 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator
|
2017-09-19 04:19:02 +02:00
|
|
|
ircd::db::database &()
|
|
|
|
{
|
|
|
|
assert(bool(d));
|
|
|
|
return *d;
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator
|
2017-09-19 04:19:02 +02:00
|
|
|
rocksdb::WriteBatch &()
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
return *wb;
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator
|
2017-09-19 04:19:02 +02:00
|
|
|
const ircd::db::database &()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(bool(d));
|
|
|
|
return *d;
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator
|
2017-09-19 04:19:02 +02:00
|
|
|
const rocksdb::WriteBatch &()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
return *wb;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-24 00:05:12 +01:00
|
|
|
// txn::checkpoint
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::checkpoint::checkpoint(txn &t)
|
2017-09-19 04:19:02 +02:00
|
|
|
:t{t}
|
|
|
|
{
|
|
|
|
assert(bool(t.wb));
|
|
|
|
t.wb->SetSavePoint();
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::checkpoint::~checkpoint()
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2018-09-13 11:50:01 +02:00
|
|
|
if(likely(!std::uncaught_exceptions()))
|
2017-09-19 04:19:02 +02:00
|
|
|
throw_on_error { t.wb->PopSavePoint() };
|
|
|
|
else
|
|
|
|
throw_on_error { t.wb->RollbackToSavePoint() };
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:05:12 +01:00
|
|
|
//
|
|
|
|
// txn::append
|
|
|
|
//
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
const string_view &key,
|
|
|
|
const json::iov &iov)
|
|
|
|
{
|
|
|
|
std::for_each(std::begin(iov), std::end(iov), [&t, &key]
|
|
|
|
(const auto &member)
|
|
|
|
{
|
|
|
|
append
|
|
|
|
{
|
|
|
|
t, delta
|
|
|
|
{
|
|
|
|
member.first, // col
|
|
|
|
key, // key
|
|
|
|
member.second // val
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
const delta &delta)
|
|
|
|
{
|
|
|
|
assert(bool(t.d));
|
|
|
|
append(t, *t.d, delta);
|
|
|
|
}
|
|
|
|
|
2019-06-24 07:09:41 +02:00
|
|
|
__attribute__((noreturn))
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
const row::delta &delta)
|
|
|
|
{
|
2019-02-16 22:51:55 +01:00
|
|
|
throw ircd::not_implemented
|
|
|
|
{
|
|
|
|
"db::txn::append (row::delta)"
|
|
|
|
};
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
const cell::delta &delta)
|
|
|
|
{
|
|
|
|
db::append(*t.wb, delta);
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
column &c,
|
|
|
|
const column::delta &delta)
|
|
|
|
{
|
|
|
|
db::append(*t.wb, c, delta);
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::append::append(txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
database &d,
|
|
|
|
const delta &delta)
|
|
|
|
{
|
2019-01-16 22:46:15 +01:00
|
|
|
db::column c
|
|
|
|
{
|
|
|
|
d[std::get<1>(delta)]
|
|
|
|
};
|
|
|
|
|
2017-09-19 04:19:02 +02:00
|
|
|
db::append(*t.wb, c, db::column::delta
|
|
|
|
{
|
|
|
|
std::get<op>(delta),
|
|
|
|
std::get<2>(delta),
|
|
|
|
std::get<3>(delta)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// db/row.h
|
2017-03-24 02:36:49 +01:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
namespace ircd::db
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
static std::vector<rocksdb::Iterator *>
|
|
|
|
_make_iterators(database &d,
|
|
|
|
database::column *const *const &columns,
|
|
|
|
const size_t &columns_size,
|
|
|
|
const rocksdb::ReadOptions &opts);
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::del(row &row,
|
|
|
|
const sopts &sopts)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
write(row::delta{op::DELETE, row}, sopts);
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const row::delta &delta,
|
2017-08-23 22:37:47 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(&delta, &delta + 1, sopts);
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
void
|
|
|
|
ircd::db::write(const sopts &sopts,
|
2019-01-29 20:13:58 +01:00
|
|
|
const std::initializer_list<row::delta> &deltas)
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
write(deltas, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const std::initializer_list<row::delta> &deltas,
|
2017-04-03 06:02:32 +02:00
|
|
|
const sopts &sopts)
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-08-23 22:37:47 +02:00
|
|
|
write(std::begin(deltas), std::end(deltas), sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const row::delta *const &begin,
|
|
|
|
const row::delta *const &end,
|
2017-08-23 22:37:47 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
// Count the total number of cells for this transaction.
|
|
|
|
const auto cells
|
|
|
|
{
|
|
|
|
std::accumulate(begin, end, size_t(0), []
|
|
|
|
(auto ret, const row::delta &delta)
|
|
|
|
{
|
|
|
|
const auto &row(std::get<row *>(delta));
|
|
|
|
return ret += row->size();
|
|
|
|
})
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//TODO: allocator?
|
|
|
|
std::vector<cell::delta> deltas;
|
|
|
|
deltas.reserve(cells);
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Compose all of the cells from all of the rows into a single txn
|
|
|
|
std::for_each(begin, end, [&deltas]
|
|
|
|
(const auto &delta)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto &op(std::get<op>(delta));
|
|
|
|
const auto &row(std::get<row *>(delta));
|
|
|
|
std::for_each(std::begin(*row), std::end(*row), [&deltas, &op]
|
|
|
|
(auto &cell)
|
|
|
|
{
|
|
|
|
// For operations like DELETE which don't require a value in
|
|
|
|
// the delta, we can skip a potentially expensive load of the cell.
|
|
|
|
const auto value
|
|
|
|
{
|
|
|
|
value_required(op)? cell.val() : string_view{}
|
|
|
|
};
|
|
|
|
|
|
|
|
deltas.emplace_back(op, cell, value);
|
|
|
|
});
|
2017-08-23 22:37:47 +02:00
|
|
|
});
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Commitment
|
|
|
|
write(&deltas.front(), &deltas.front() + deltas.size(), sopts);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::seek(row &r,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &opts)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
// The following closure performs the seek() for a single cell in the row.
|
|
|
|
// It may be executed on another ircd::ctx if the data isn't cached and
|
|
|
|
// blocking IO is required. This frame can't be interrupted because it may
|
|
|
|
// have requests pending in the request pool which must synchronize back
|
|
|
|
// here.
|
|
|
|
size_t ret{0};
|
|
|
|
std::exception_ptr eptr;
|
|
|
|
ctx::latch latch{r.size()};
|
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
const auto closure{[&opts, &latch, &ret, &key, &eptr]
|
|
|
|
(auto &cell) noexcept
|
|
|
|
{
|
|
|
|
// If there's a pending error from another cell by the time this
|
|
|
|
// closure is executed we don't perform the seek() unless the user
|
|
|
|
// specifies db::get::NO_THROW to suppress it.
|
|
|
|
if(!eptr || test(opts, get::NO_THROW)) try
|
|
|
|
{
|
|
|
|
if(!seek(cell, key))
|
|
|
|
{
|
|
|
|
// If the cell is not_found that's not a thrown exception here;
|
|
|
|
// the cell will just be !valid(). The user can specify
|
|
|
|
// get::THROW to propagate a not_found from the seek(row);
|
|
|
|
if(test(opts, get::THROW))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"column '%s' key '%s'", cell.col(), key
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else ++ret;
|
|
|
|
}
|
|
|
|
catch(const not_found &e)
|
|
|
|
{
|
|
|
|
eptr = std::current_exception();
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "row seek: column '%s' key '%s' :%s",
|
|
|
|
cell.col(),
|
|
|
|
key,
|
|
|
|
e.what()
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
eptr = std::make_exception_ptr(e);
|
|
|
|
}
|
2017-09-14 21:59:20 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// The latch must always be hit here. No exception should propagate
|
|
|
|
// to prevent this from being reached or beyond.
|
|
|
|
latch.count_down();
|
|
|
|
}};
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK_ROW
|
|
|
|
const ircd::timer timer;
|
|
|
|
size_t submits{0};
|
|
|
|
#endif
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Submit all the requests
|
|
|
|
for(auto &cell : r)
|
|
|
|
{
|
|
|
|
db::column &column(cell);
|
|
|
|
const auto reclosure{[&closure, &cell]
|
|
|
|
() noexcept
|
|
|
|
{
|
|
|
|
closure(cell);
|
|
|
|
}};
|
2017-09-23 06:55:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Whether to submit the request to another ctx or execute it here.
|
|
|
|
// Explicit option to prevent submitting must not be set. If there
|
|
|
|
// is a chance the data is already in the cache, we can avoid the
|
|
|
|
// context switching and occupation of the request pool.
|
|
|
|
//TODO: should check a bloom filter on the cache for this branch
|
|
|
|
//TODO: because right now double-querying the cache is gross.
|
|
|
|
const bool submit
|
|
|
|
{
|
|
|
|
r.size() > 1 &&
|
|
|
|
!test(opts, get::NO_PARALLEL) &&
|
|
|
|
!db::cached(column, key, opts)
|
|
|
|
};
|
2017-09-14 21:59:20 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK_ROW
|
|
|
|
submits += submit;
|
|
|
|
#endif
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
if(submit)
|
|
|
|
request(reclosure);
|
|
|
|
else
|
|
|
|
reclosure();
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Wait for responses.
|
|
|
|
latch.wait();
|
|
|
|
assert(ret <= r.size());
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK_ROW
|
|
|
|
if(likely(!r.empty()))
|
|
|
|
{
|
|
|
|
const column &c(r[0]);
|
|
|
|
const database &d(c);
|
|
|
|
thread_local char tmbuf[32];
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s' SEEK ROW seq:%lu:%-10lu cnt:%-2zu req:%-2zu ret:%-2zu in %s %s",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
|
|
|
r.size(),
|
|
|
|
submits,
|
|
|
|
ret,
|
|
|
|
pretty(tmbuf, timer.at<microseconds>(), true),
|
|
|
|
what(eptr)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
if(eptr && !test(opts, get::NO_THROW))
|
|
|
|
std::rethrow_exception(eptr);
|
|
|
|
|
|
|
|
return ret;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// row
|
|
|
|
//
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wstack-usage="
|
2019-05-08 08:05:18 +02:00
|
|
|
__attribute__((stack_protect))
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::row(database &d,
|
|
|
|
const string_view &key,
|
|
|
|
const vector_view<const string_view> &colnames,
|
|
|
|
const vector_view<cell> &buf,
|
|
|
|
gopts opts)
|
|
|
|
:vector_view<cell>{[&d, &colnames, &buf, &opts]
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
using std::end;
|
|
|
|
using std::begin;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
if(!opts.snapshot)
|
|
|
|
opts.snapshot = database::snapshot(d);
|
|
|
|
|
|
|
|
const rocksdb::ReadOptions options
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
make_opts(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(buf.size() >= colnames.size());
|
|
|
|
const size_t request_count
|
|
|
|
{
|
|
|
|
std::min(colnames.size(), buf.size())
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t count(0);
|
|
|
|
database::column *colptr[request_count];
|
|
|
|
for(size_t i(0); i < request_count; ++i)
|
|
|
|
{
|
|
|
|
const auto cfid
|
|
|
|
{
|
|
|
|
d.cfid(std::nothrow, colnames.at(i))
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cfid >= 0)
|
|
|
|
colptr[count++] = &d[cfid];
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// All pointers returned by rocksdb in this vector must be free'd.
|
|
|
|
const auto iterators
|
|
|
|
{
|
|
|
|
_make_iterators(d, colptr, count, options)
|
|
|
|
};
|
2019-01-16 04:03:03 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
assert(iterators.size() == count);
|
|
|
|
for(size_t i(0); i < iterators.size(); ++i)
|
|
|
|
{
|
|
|
|
std::unique_ptr<rocksdb::Iterator> it
|
|
|
|
{
|
|
|
|
iterators.at(i)
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
buf[i] = cell
|
|
|
|
{
|
|
|
|
*colptr[i], std::move(it), opts
|
|
|
|
};
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return vector_view<cell>
|
|
|
|
{
|
|
|
|
buf.data(), iterators.size()
|
|
|
|
};
|
|
|
|
}()}
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
if(key)
|
|
|
|
seek(*this, key, opts);
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
#pragma GCC diagnostic pop
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
static std::vector<rocksdb::Iterator *>
|
|
|
|
ircd::db::_make_iterators(database &d,
|
|
|
|
database::column *const *const &column,
|
|
|
|
const size_t &column_count,
|
|
|
|
const rocksdb::ReadOptions &opts)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
using rocksdb::Iterator;
|
|
|
|
using rocksdb::ColumnFamilyHandle;
|
|
|
|
assert(column_count <= d.columns.size());
|
|
|
|
|
|
|
|
//const ctx::critical_assertion ca;
|
|
|
|
// NewIterators() has been seen to lead to IO and block the ircd::ctx;
|
|
|
|
// specifically when background options are aggressive and shortly
|
|
|
|
// after db opens. It would be nice if we could maintain the
|
|
|
|
// critical_assertion for this function, as we could eliminate the
|
|
|
|
// vector allocation for ColumnFamilyHandle pointers.
|
|
|
|
|
|
|
|
std::vector<ColumnFamilyHandle *> handles(column_count);
|
|
|
|
std::transform(column, column + column_count, begin(handles), []
|
|
|
|
(database::column *const &ptr)
|
|
|
|
{
|
|
|
|
assert(ptr);
|
|
|
|
return ptr->handle.get();
|
|
|
|
});
|
|
|
|
|
|
|
|
std::vector<Iterator *> ret;
|
2019-09-13 02:38:43 +02:00
|
|
|
const ctx::stack_usage_assertion sua;
|
2019-01-29 20:13:58 +01:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->NewIterators(opts, handles, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::row::operator()(const op &op,
|
|
|
|
const string_view &col,
|
|
|
|
const string_view &val,
|
|
|
|
const sopts &sopts)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
write(cell::delta{op, (*this)[col], val}, sopts);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::row::operator[](const string_view &column)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto it(find(column));
|
|
|
|
if(unlikely(it == end()))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"column '%s' not specified in the descriptor schema", column
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return *it;
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
const ircd::db::cell &
|
|
|
|
ircd::db::row::operator[](const string_view &column)
|
|
|
|
const
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto it(find(column));
|
|
|
|
if(unlikely(it == end()))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"column '%s' not specified in the descriptor schema", column
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return *it;
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::iterator
|
|
|
|
ircd::db::row::find(const string_view &col)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return std::find_if(std::begin(*this), std::end(*this), [&col]
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return name(cell.c) == col;
|
|
|
|
});
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::const_iterator
|
|
|
|
ircd::db::row::find(const string_view &col)
|
2017-04-03 06:02:32 +02:00
|
|
|
const
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return std::find_if(std::begin(*this), std::end(*this), [&col]
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return name(cell.c) == col;
|
|
|
|
});
|
2017-09-14 21:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::cached()
|
2017-09-14 21:59:20 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return std::all_of(std::begin(*this), std::end(*this), []
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
db::column &column(mutable_cast(cell));
|
2019-01-29 20:13:58 +01:00
|
|
|
return cell.valid() && db::cached(column, cell.key());
|
|
|
|
});
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::cached(const string_view &key)
|
2017-04-03 06:02:32 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return std::all_of(std::begin(*this), std::end(*this), [&key]
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
db::column &column(mutable_cast(cell));
|
2019-01-29 20:13:58 +01:00
|
|
|
return db::cached(column, key);
|
|
|
|
});
|
2017-09-16 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-06-07 12:26:31 +02:00
|
|
|
ircd::db::row::valid_all(const string_view &s)
|
2017-09-16 20:48:09 +02:00
|
|
|
const
|
|
|
|
{
|
2020-06-07 12:26:31 +02:00
|
|
|
return !empty() && std::all_of(std::begin(*this), std::end(*this), [&s]
|
2019-01-29 20:13:58 +01:00
|
|
|
(const auto &cell)
|
|
|
|
{
|
2020-06-07 12:26:31 +02:00
|
|
|
return cell.valid(s);
|
2019-01-29 20:13:58 +01:00
|
|
|
});
|
2017-09-16 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::row::valid(const string_view &s)
|
2017-09-16 20:48:09 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return std::any_of(std::begin(*this), std::end(*this), [&s]
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return cell.valid(s);
|
|
|
|
});
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 12:26:31 +02:00
|
|
|
bool
|
|
|
|
ircd::db::row::valid_all()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return !empty() && std::all_of(std::begin(*this), std::end(*this), []
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return cell.valid();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::row::valid()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return std::any_of(std::begin(*this), std::end(*this), []
|
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return cell.valid();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-03-31 00:57:08 +02:00
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// db/cell.h
|
2017-03-31 00:57:08 +02:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
uint64_t
|
|
|
|
ircd::db::sequence(const cell &c)
|
2019-01-24 19:52:05 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const database::snapshot &ss(c);
|
|
|
|
return sequence(database::snapshot(c));
|
2019-01-24 19:52:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const cell &c)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return name(c.c);
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const cell::delta &delta,
|
2017-08-23 22:37:47 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(&delta, &delta + 1, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const sopts &sopts,
|
2019-01-29 20:13:58 +01:00
|
|
|
const std::initializer_list<cell::delta> &deltas)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
|
|
|
write(deltas, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const std::initializer_list<cell::delta> &deltas,
|
2017-08-23 22:37:47 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(std::begin(deltas), std::end(deltas), sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::write(const cell::delta *const &begin,
|
|
|
|
const cell::delta *const &end,
|
2017-08-23 22:37:47 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
if(begin == end)
|
|
|
|
return;
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Find the database through one of the cell's columns. cell::deltas
|
|
|
|
// may come from different columns so we do nothing else with this.
|
|
|
|
auto &front(*begin);
|
|
|
|
column &c(std::get<cell *>(front)->c);
|
|
|
|
database &d(c);
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::WriteBatch batch;
|
|
|
|
std::for_each(begin, end, [&batch]
|
|
|
|
(const cell::delta &delta)
|
2017-08-23 22:37:47 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
append(batch, delta);
|
2017-08-23 22:37:47 +02:00
|
|
|
});
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
commit(d, batch, sopts);
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
template<class pos>
|
|
|
|
bool
|
|
|
|
ircd::db::seek(cell &c,
|
|
|
|
const pos &p,
|
|
|
|
gopts opts)
|
2018-08-19 05:59:28 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
column &cc(c);
|
|
|
|
database::column &dc(cc);
|
2018-05-29 10:42:48 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
if(!opts.snapshot)
|
|
|
|
opts.snapshot = c.ss;
|
2018-12-24 23:33:35 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto ropts(make_opts(opts));
|
|
|
|
return seek(dc, p, ropts, c.it);
|
2017-08-30 23:05:15 +02:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
template bool ircd::db::seek<ircd::db::pos>(cell &, const pos &, gopts);
|
|
|
|
template bool ircd::db::seek<ircd::string_view>(cell &, const string_view &, gopts);
|
2017-08-30 23:05:15 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::cell()
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::cell(database &d,
|
|
|
|
const string_view &colname,
|
|
|
|
const gopts &opts)
|
|
|
|
:cell
|
|
|
|
{
|
|
|
|
column(d[colname]), std::unique_ptr<rocksdb::Iterator>{}, opts
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::cell(database &d,
|
|
|
|
const string_view &colname,
|
|
|
|
const string_view &index,
|
|
|
|
const gopts &opts)
|
|
|
|
:cell
|
|
|
|
{
|
|
|
|
column(d[colname]), index, opts
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
const string_view &index,
|
|
|
|
const gopts &opts)
|
|
|
|
:c{std::move(column)}
|
|
|
|
,ss{opts.snapshot}
|
|
|
|
,it
|
|
|
|
{
|
|
|
|
!index.empty()?
|
|
|
|
seek(this->c, index, opts):
|
|
|
|
std::unique_ptr<rocksdb::Iterator>{}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if(bool(this->it))
|
|
|
|
if(!valid_eq(*this->it, index))
|
|
|
|
this->it.reset();
|
|
|
|
}
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
const string_view &index,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> it,
|
|
|
|
const gopts &opts)
|
|
|
|
:c{std::move(column)}
|
|
|
|
,ss{opts.snapshot}
|
|
|
|
,it{std::move(it)}
|
|
|
|
{
|
|
|
|
if(index.empty())
|
|
|
|
return;
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
seek(*this, index, opts);
|
|
|
|
if(!valid_eq(*this->it, index))
|
|
|
|
this->it.reset();
|
|
|
|
}
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> it,
|
|
|
|
const gopts &opts)
|
|
|
|
:c{std::move(column)}
|
|
|
|
,ss{opts.snapshot}
|
|
|
|
,it{std::move(it)}
|
|
|
|
{
|
|
|
|
}
|
2019-01-18 00:33:20 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::cell(cell &&o)
|
|
|
|
noexcept
|
|
|
|
:c{std::move(o.c)}
|
|
|
|
,ss{std::move(o.ss)}
|
|
|
|
,it{std::move(o.it)}
|
|
|
|
{
|
|
|
|
}
|
2018-08-19 05:59:28 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::cell::operator=(cell &&o)
|
|
|
|
noexcept
|
2019-01-24 19:52:05 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
c = std::move(o.c);
|
|
|
|
ss = std::move(o.ss);
|
|
|
|
it = std::move(o.it);
|
|
|
|
|
|
|
|
return *this;
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::~cell()
|
|
|
|
noexcept
|
2019-01-24 19:52:05 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::cell::load(const string_view &index,
|
|
|
|
gopts opts)
|
|
|
|
{
|
|
|
|
database &d(c);
|
|
|
|
if(valid(index) && !opts.snapshot && sequence(ss) == sequence(d))
|
|
|
|
return true;
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
if(bool(opts.snapshot))
|
2019-01-24 19:52:05 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
this->it.reset();
|
|
|
|
this->ss = std::move(opts.snapshot);
|
|
|
|
}
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
database::column &c(this->c);
|
2019-09-19 04:14:06 +02:00
|
|
|
const auto _opts
|
|
|
|
{
|
|
|
|
make_opts(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!seek(c, index, _opts, this->it))
|
2019-01-29 20:13:58 +01:00
|
|
|
return false;
|
2019-01-24 19:52:05 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid(index);
|
2019-01-24 19:52:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::cell::operator=(const string_view &s)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
write(c, key(), s);
|
|
|
|
return *this;
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::cell::operator()(const op &op,
|
|
|
|
const string_view &val,
|
|
|
|
const sopts &sopts)
|
2017-09-22 02:00:48 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
write(cell::delta{op, *this, val}, sopts);
|
|
|
|
}
|
2017-09-22 02:00:48 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::val()
|
|
|
|
{
|
|
|
|
if(!valid())
|
|
|
|
load();
|
|
|
|
|
|
|
|
return likely(valid())? db::val(*it) : string_view{};
|
2017-09-22 02:00:48 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::key()
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
if(!valid())
|
|
|
|
load();
|
|
|
|
|
|
|
|
return likely(valid())? db::key(*it) : string_view{};
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::val()
|
2017-04-03 06:02:32 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return likely(valid())? db::val(*it) : string_view{};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::key()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return likely(valid())? db::key(*it) : string_view{};
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2018-12-27 04:45:04 +01:00
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::valid(const string_view &s)
|
2018-12-27 04:45:04 +01:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid() && db::valid_eq(*it, s);
|
2018-12-27 04:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::valid_gt(const string_view &s)
|
2018-12-27 04:45:04 +01:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid() && db::valid_gt(*it, s);
|
2018-12-27 04:45:04 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 23:22:19 +02:00
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::valid_lte(const string_view &s)
|
2017-08-30 23:22:19 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid() && db::valid_lte(*it, s);
|
2017-08-30 23:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 20:48:09 +02:00
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cell::valid()
|
2017-09-16 20:48:09 +02:00
|
|
|
const
|
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return bool(it) && db::valid(*it);
|
2017-09-16 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-02-07 01:38:42 +01:00
|
|
|
//
|
2019-08-13 06:01:44 +02:00
|
|
|
// db/domain.h
|
2019-02-07 01:38:42 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
const ircd::db::gopts
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::applied_opts
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
2019-06-24 07:09:41 +02:00
|
|
|
get::PREFIX
|
2019-02-07 01:38:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::seek(domain::const_iterator_base &it,
|
2019-02-07 01:38:42 +01:00
|
|
|
const pos &p)
|
|
|
|
{
|
|
|
|
switch(p)
|
|
|
|
{
|
|
|
|
case pos::BACK:
|
|
|
|
{
|
|
|
|
// This is inefficient as per RocksDB's prefix impl. unknown why
|
|
|
|
// a seek to NEXT is still needed after walking back one.
|
|
|
|
while(seek(it, pos::NEXT));
|
|
|
|
if(seek(it, pos::PREV))
|
|
|
|
seek(it, pos::NEXT);
|
|
|
|
|
|
|
|
return bool(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
it.opts |= domain::applied_opts;
|
2019-02-07 01:38:42 +01:00
|
|
|
return seek(static_cast<column::const_iterator_base &>(it), p);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::seek(domain::const_iterator_base &it,
|
2019-02-07 01:38:42 +01:00
|
|
|
const string_view &p)
|
|
|
|
{
|
2019-06-11 21:55:14 +02:00
|
|
|
it.opts |= domain::applied_opts;
|
2019-02-07 01:38:42 +01:00
|
|
|
return seek(static_cast<column::const_iterator_base &>(it), p);
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_iterator
|
|
|
|
ircd::db::domain::begin(const string_view &key,
|
|
|
|
gopts opts)
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
const_iterator ret
|
|
|
|
{
|
|
|
|
c, {}, std::move(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
seek(ret, key);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_iterator
|
|
|
|
ircd::db::domain::end(const string_view &key,
|
|
|
|
gopts opts)
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
const_iterator ret
|
|
|
|
{
|
|
|
|
c, {}, std::move(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(seek(ret, key))
|
|
|
|
seek(ret, pos::END);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// NOTE: RocksDB says they don't support reverse iteration over a prefix range
|
|
|
|
/// This means we have to forward scan to the end and then walk back! Reverse
|
2019-06-11 21:55:14 +02:00
|
|
|
/// iterations of a domain should only be used for debugging and statistics! The
|
|
|
|
/// domain should be ordered the way it will be primarily accessed using the
|
2019-02-07 01:38:42 +01:00
|
|
|
/// comparator. If it will be accessed in different directions, make another
|
2019-06-11 21:55:14 +02:00
|
|
|
/// domain column.
|
|
|
|
ircd::db::domain::const_reverse_iterator
|
|
|
|
ircd::db::domain::rbegin(const string_view &key,
|
|
|
|
gopts opts)
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
|
|
|
c, {}, std::move(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(seek(ret, key))
|
|
|
|
seek(ret, pos::BACK);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_reverse_iterator
|
|
|
|
ircd::db::domain::rend(const string_view &key,
|
|
|
|
gopts opts)
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
|
|
|
c, {}, std::move(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(seek(ret, key))
|
|
|
|
seek(ret, pos::END);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// const_iterator
|
|
|
|
//
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_iterator &
|
|
|
|
ircd::db::domain::const_iterator::operator--()
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_iterator &
|
|
|
|
ircd::db::domain::const_iterator::operator++()
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_reverse_iterator &
|
|
|
|
ircd::db::domain::const_reverse_iterator::operator--()
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
ircd::db::domain::const_reverse_iterator &
|
|
|
|
ircd::db::domain::const_reverse_iterator::operator++()
|
2019-02-07 01:38:42 +01:00
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
const ircd::db::domain::const_iterator_base::value_type &
|
|
|
|
ircd::db::domain::const_iterator_base::operator*()
|
2019-02-07 01:38:42 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto &prefix
|
|
|
|
{
|
|
|
|
describe(*c).prefix
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fetch the full value like a standard column first
|
|
|
|
column::const_iterator_base::operator*();
|
|
|
|
string_view &key{val.first};
|
|
|
|
|
2019-06-11 21:55:14 +02:00
|
|
|
// When there's no prefixing this domain column is just
|
2019-02-07 01:38:42 +01:00
|
|
|
// like a normal column. Otherwise, we remove the prefix
|
|
|
|
// from the key the user will end up seeing.
|
|
|
|
if(prefix.has && prefix.has(key))
|
|
|
|
{
|
|
|
|
const auto &first(prefix.get(key));
|
|
|
|
const auto &second(key.substr(first.size()));
|
|
|
|
key = second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-04-03 06:02:32 +02:00
|
|
|
//
|
|
|
|
// db/column.h
|
|
|
|
//
|
|
|
|
|
2016-09-24 06:01:57 +02:00
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::drop(column &column)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
database::column &c(column);
|
2019-09-19 00:15:02 +02:00
|
|
|
drop(c);
|
2016-09-25 06:12:43 +02:00
|
|
|
}
|
|
|
|
|
2020-01-08 20:24:27 +01:00
|
|
|
void
|
|
|
|
ircd::db::check(column &column)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
const auto &files
|
|
|
|
{
|
|
|
|
db::files(column)
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &file : files)
|
|
|
|
{
|
|
|
|
const auto &path
|
|
|
|
{
|
|
|
|
// remove false leading slash; the rest is relative to db.
|
|
|
|
lstrip(file, '/')
|
|
|
|
};
|
|
|
|
|
|
|
|
db::check(d, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-25 06:12:43 +02:00
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::sort(column &column,
|
|
|
|
const bool &blocking,
|
|
|
|
const bool &now)
|
2016-09-25 06:12:43 +02:00
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
database::column &c(column);
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(*c.d);
|
|
|
|
|
|
|
|
rocksdb::FlushOptions opts;
|
|
|
|
opts.wait = blocking;
|
|
|
|
opts.allow_write_stall = now;
|
2018-08-29 06:53:17 +02:00
|
|
|
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2019-09-19 00:15:02 +02:00
|
|
|
const std::lock_guard lock{write_mutex};
|
2018-08-20 04:30:17 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "[%s]'%s' @%lu FLUSH (sort) %s %s",
|
2018-08-20 04:30:17 +02:00
|
|
|
name(d),
|
|
|
|
name(c),
|
2019-09-19 00:15:02 +02:00
|
|
|
sequence(d),
|
|
|
|
blocking? "blocking"_sv: "non-blocking"_sv,
|
|
|
|
now? "now"_sv: "later"_sv
|
2018-08-20 04:30:17 +02:00
|
|
|
};
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->Flush(opts, c)
|
2017-04-03 06:02:32 +02:00
|
|
|
};
|
2016-09-25 06:12:43 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
void
|
|
|
|
ircd::db::compact(column &column,
|
|
|
|
const std::pair<int, int> &level,
|
|
|
|
const compactor &cb)
|
2019-02-25 23:46:21 +01:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database::column &c(column);
|
|
|
|
database &d(*c.d);
|
2019-02-25 23:46:21 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const auto &dst_level{level.second};
|
|
|
|
const auto &src_level{level.first};
|
2019-02-25 23:46:21 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::ColumnFamilyMetaData cfmd;
|
|
|
|
d.d->GetColumnFamilyMetaData(c, &cfmd);
|
|
|
|
for(const auto &level : cfmd.levels)
|
2019-02-25 23:46:21 +01:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
if(src_level != -1 && src_level != level.level)
|
|
|
|
continue;
|
2019-02-25 23:46:21 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
if(level.files.empty())
|
|
|
|
continue;
|
2019-02-25 23:46:21 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
const std::lock_guard lock
|
|
|
|
{
|
|
|
|
write_mutex
|
|
|
|
};
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const auto &to_level
|
|
|
|
{
|
|
|
|
dst_level > -1? dst_level : level.level
|
|
|
|
};
|
2018-09-01 13:38:30 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::CompactionOptions opts;
|
|
|
|
opts.output_file_size_limit = 1_GiB; //TODO: conf
|
2018-12-28 01:13:49 +01:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
// RocksDB sez that setting this to Disable means that the column's
|
|
|
|
// compression options are read instead. If we don't set this here,
|
|
|
|
// rocksdb defaults to "snappy" (which is strange).
|
|
|
|
opts.compression = rocksdb::kDisableCompressionOption;
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
std::vector<std::string> files(level.files.size());
|
|
|
|
std::transform(level.files.begin(), level.files.end(), files.begin(), []
|
|
|
|
(auto &metadata)
|
|
|
|
{
|
|
|
|
return std::move(metadata.name);
|
|
|
|
});
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
// Save and restore the existing filter callback so we can allow our
|
|
|
|
// caller to use theirs. Note that this manual compaction should be
|
|
|
|
// exclusive for this column (no background compaction should be
|
|
|
|
// occurring, at least one relying on this filter).
|
|
|
|
auto their_filter(std::move(c.cfilter.user));
|
|
|
|
const unwind unfilter{[&c, &their_filter]
|
|
|
|
{
|
|
|
|
c.cfilter.user = std::move(their_filter);
|
|
|
|
}};
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
c.cfilter.user = cb;
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
log::debug
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "[%s]'%s' COMPACT L%d -> L%d files:%zu size:%zu",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
level.level,
|
|
|
|
to_level,
|
|
|
|
level.files.size(),
|
|
|
|
level.size
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->CompactFiles(opts, c, files, to_level)
|
|
|
|
};
|
2019-08-25 02:40:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
void
|
|
|
|
ircd::db::compact(column &column,
|
|
|
|
const std::pair<string_view, string_view> &range,
|
|
|
|
const int &to_level,
|
|
|
|
const compactor &cb)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
const ctx::uninterruptible ui;
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const auto begin(slice(range.first));
|
|
|
|
const rocksdb::Slice *const b
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
empty(range.first)? nullptr : &begin
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const auto end(slice(range.second));
|
|
|
|
const rocksdb::Slice *const e
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
empty(range.second)? nullptr : &end
|
|
|
|
};
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
rocksdb::CompactRangeOptions opts;
|
|
|
|
opts.exclusive_manual_compaction = true;
|
|
|
|
opts.allow_write_stall = true;
|
|
|
|
opts.change_level = true;
|
|
|
|
opts.target_level = std::max(to_level, -1);
|
|
|
|
opts.bottommost_level_compaction = rocksdb::BottommostLevelCompaction::kForce;
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
// Save and restore the existing filter callback so we can allow our
|
|
|
|
// caller to use theirs. Note that this manual compaction should be
|
|
|
|
// exclusive for this column (no background compaction should be
|
|
|
|
// occurring, at least one relying on this filter).
|
|
|
|
auto their_filter(std::move(c.cfilter.user));
|
|
|
|
const unwind unfilter{[&c, &their_filter]
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
c.cfilter.user = std::move(their_filter);
|
|
|
|
}};
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
c.cfilter.user = cb;
|
|
|
|
|
|
|
|
log::debug
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "[%s]'%s' @%lu COMPACT [%s, %s] -> L:%d (Lmax:%d Lbase:%d)",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d),
|
|
|
|
range.first,
|
|
|
|
range.second,
|
|
|
|
opts.target_level,
|
|
|
|
d.d->NumberLevels(c),
|
|
|
|
d.d->MaxMemCompactionLevel(c),
|
2019-09-08 22:31:41 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw_on_error
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->CompactRange(opts, c, b, e)
|
2019-09-08 22:31:41 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-25 02:40:31 +02:00
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::setopt(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &val)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
const std::unordered_map<std::string, std::string> options
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
{ std::string{key}, std::string{val} }
|
|
|
|
};
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->SetOptions(c, options)
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::ingest(column &column,
|
|
|
|
const string_view &path)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
|
|
|
|
rocksdb::IngestExternalFileOptions opts;
|
|
|
|
opts.allow_global_seqno = true;
|
|
|
|
opts.allow_blocking_flush = true;
|
|
|
|
|
|
|
|
// Automatically determine if we can avoid issuing new sequence
|
|
|
|
// numbers by considering this ingestion as "backfill" of missing
|
|
|
|
// data which did actually exist but was physically removed.
|
|
|
|
const auto &copts{d.d->GetOptions(c)};
|
|
|
|
opts.ingest_behind = copts.allow_ingest_behind;
|
|
|
|
|
|
|
|
const std::vector<std::string> files
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
{ std::string{path} }
|
2019-09-08 22:31:41 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const std::lock_guard lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->IngestExternalFile(c, files, opts)
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::del(column &column,
|
|
|
|
const std::pair<string_view, string_view> &range,
|
|
|
|
const sopts &sopts)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
auto opts(make_opts(sopts));
|
2019-09-11 02:11:23 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
const std::lock_guard lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
log::debug
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "'%s' %lu '%s' RANGE DELETE",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
name(c),
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->DeleteRange(opts, c, slice(range.first), slice(range.second))
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-09-19 00:15:02 +02:00
|
|
|
ircd::db::del(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const sopts &sopts)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
auto opts(make_opts(sopts));
|
|
|
|
|
|
|
|
const std::lock_guard lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
log::debug
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "'%s' %lu '%s' DELETE key(%zu B)",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
name(c),
|
|
|
|
key.size()
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->Delete(opts, c, slice(key))
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
2019-09-19 00:15:02 +02:00
|
|
|
}
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2019-09-19 00:15:02 +02:00
|
|
|
void
|
|
|
|
ircd::db::write(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const const_buffer &val,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
auto opts(make_opts(sopts));
|
|
|
|
|
|
|
|
const std::lock_guard lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const ctx::stack_usage_assertion sua;
|
2019-08-25 02:40:31 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
log, "'%s' %lu '%s' PUT key(%zu B) val(%zu B)",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
name(c),
|
|
|
|
size(key),
|
|
|
|
size(val)
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
2019-09-19 00:15:02 +02:00
|
|
|
|
|
|
|
throw_on_error
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2019-09-19 00:15:02 +02:00
|
|
|
d.d->Put(opts, c, slice(key), slice(val))
|
2019-08-25 02:40:31 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-19 00:15:02 +02:00
|
|
|
|
2020-09-17 07:25:40 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const keys &keys,
|
|
|
|
const bufs &bufs,
|
|
|
|
const gopts &opts)
|
|
|
|
{
|
|
|
|
const columns columns
|
|
|
|
{
|
|
|
|
&column, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
return read(columns, keys, bufs, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::read(const columns &c,
|
|
|
|
const keys &key,
|
|
|
|
const bufs &buf,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
if(c.empty())
|
|
|
|
return 0UL;
|
|
|
|
|
|
|
|
const auto &num
|
|
|
|
{
|
|
|
|
key.size()
|
|
|
|
};
|
|
|
|
|
|
|
|
if(unlikely(!num || num > 64 || num > buf.size()))
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"db::read() :too many columns or vector size mismatch"
|
|
|
|
};
|
|
|
|
|
|
|
|
_read_op op[num];
|
|
|
|
for(size_t i(0); i < num; ++i)
|
|
|
|
op[i] =
|
|
|
|
{
|
|
|
|
c[std::min(c.size() - 1, i)], key[i]
|
|
|
|
};
|
|
|
|
|
|
|
|
uint64_t i(0), ret(0);
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
_read({op, num}, opts, [&i, &ret, &buf]
|
|
|
|
(column &, const column::delta &d, const rocksdb::Status &s)
|
|
|
|
{
|
|
|
|
const auto &val
|
|
|
|
{
|
|
|
|
std::get<column::delta::VAL>(d)
|
|
|
|
};
|
|
|
|
|
|
|
|
buf[i] = mutable_buffer
|
|
|
|
{
|
|
|
|
buf[i], size(val)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto copied
|
|
|
|
{
|
|
|
|
copy(buf[i], val)
|
|
|
|
};
|
|
|
|
|
|
|
|
ret |= (uint64_t(s.ok()) << i++);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
std::string ret;
|
|
|
|
const auto closure([&ret]
|
|
|
|
(const string_view &src)
|
2019-08-25 02:40:31 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
ret.assign(begin(src), end(src));
|
2019-09-19 00:15:02 +02:00
|
|
|
});
|
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
column(key, closure, gopts);
|
2019-09-19 00:15:02 +02:00
|
|
|
return ret;
|
2019-08-25 02:40:31 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
const gopts &gopts)
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
string_view ret;
|
|
|
|
const auto closure([&ret, &buf]
|
|
|
|
(const string_view &src)
|
|
|
|
{
|
|
|
|
ret = { data(buf), copy(buf, src) };
|
|
|
|
});
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
column(key, closure, gopts);
|
|
|
|
return ret;
|
2019-09-19 00:15:02 +02:00
|
|
|
}
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
bool &found,
|
|
|
|
const gopts &gopts)
|
2019-09-19 00:15:02 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
std::string ret;
|
|
|
|
const auto closure([&ret]
|
|
|
|
(const string_view &src)
|
2019-09-08 22:31:41 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
ret.assign(begin(src), end(src));
|
|
|
|
});
|
2019-09-08 22:31:41 +02:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
found = column(key, std::nothrow, closure, gopts);
|
|
|
|
return ret;
|
2019-09-08 22:31:41 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
bool &found,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
string_view ret;
|
|
|
|
const auto closure([&buf, &ret]
|
|
|
|
(const string_view &src)
|
|
|
|
{
|
|
|
|
ret = { data(buf), copy(buf, src) };
|
|
|
|
});
|
2019-08-25 02:40:31 +02:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
found = column(key, std::nothrow, closure, gopts);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::bytes_value(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
2018-08-19 05:40:23 +02:00
|
|
|
{
|
2020-09-17 07:12:11 +02:00
|
|
|
size_t ret{0};
|
|
|
|
column(key, std::nothrow, gopts, [&ret]
|
|
|
|
(const string_view &value)
|
|
|
|
{
|
|
|
|
ret = value.size();
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
2018-12-27 04:44:26 +01:00
|
|
|
}
|
2018-08-19 05:40:23 +02:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::bytes(column &column,
|
|
|
|
const std::pair<string_view, string_view> &key,
|
|
|
|
const gopts &gopts)
|
2018-12-27 04:44:26 +01:00
|
|
|
{
|
2019-01-12 02:36:05 +01:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
2020-09-17 07:12:11 +02:00
|
|
|
const rocksdb::Range range[1]
|
|
|
|
{
|
|
|
|
{ slice(key.first), slice(key.second) }
|
|
|
|
};
|
2019-01-12 02:36:05 +01:00
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
uint64_t ret[1] {0};
|
|
|
|
d.d->GetApproximateSizes(c, range, 1, ret);
|
|
|
|
return ret[0];
|
2018-08-19 05:40:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:20:01 +02:00
|
|
|
bool
|
|
|
|
ircd::db::has(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
|
2018-09-01 13:06:13 +02:00
|
|
|
// Perform a co-RP query to the filtration
|
2020-06-07 06:45:41 +02:00
|
|
|
//
|
2018-10-16 11:20:49 +02:00
|
|
|
// NOTE disabled for rocksdb >= v5.15 due to a regression
|
|
|
|
// where rocksdb does not init SuperVersion data in the column
|
|
|
|
// family handle and this codepath triggers null derefs and ub.
|
2020-06-07 06:45:41 +02:00
|
|
|
//
|
|
|
|
// NOTE works on rocksdb 6.6.4 but unconditionally copies value.
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
if(c.table_opts.filter_policy && (false))
|
2018-10-16 10:21:42 +02:00
|
|
|
{
|
|
|
|
auto opts(make_opts(gopts));
|
2020-06-07 06:45:41 +02:00
|
|
|
const scope_restore read_tier
|
|
|
|
{
|
|
|
|
opts.read_tier, NON_BLOCKING
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope_restore fill_cache
|
|
|
|
{
|
|
|
|
opts.fill_cache, false
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string discard;
|
|
|
|
bool value_found {false};
|
|
|
|
const bool key_may_exist
|
|
|
|
{
|
|
|
|
d.d->KeyMayExist(opts, c, slice(key), &discard, &value_found)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!key_may_exist)
|
2018-10-16 10:21:42 +02:00
|
|
|
return false;
|
2020-06-07 06:45:41 +02:00
|
|
|
|
|
|
|
if(value_found)
|
|
|
|
return true;
|
2018-10-16 10:21:42 +02:00
|
|
|
}
|
2017-10-28 01:48:27 +02:00
|
|
|
|
2020-06-07 06:45:41 +02:00
|
|
|
std::unique_ptr<rocksdb::Iterator> it;
|
|
|
|
if(!seek(c, key, opts, it))
|
|
|
|
return false;
|
2018-04-10 01:57:13 +02:00
|
|
|
|
2020-06-07 06:45:41 +02:00
|
|
|
assert(bool(it));
|
2018-09-01 13:06:13 +02:00
|
|
|
return valid_eq(*it, key);
|
2017-03-31 01:20:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 06:40:54 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::has(column &column,
|
2020-09-17 07:05:47 +02:00
|
|
|
const keys &key,
|
2020-06-09 06:40:54 +02:00
|
|
|
const gopts &opts)
|
|
|
|
{
|
2020-09-17 07:05:47 +02:00
|
|
|
const columns columns
|
|
|
|
{
|
|
|
|
&column, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
return has(columns, key, opts);
|
2020-06-09 06:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2020-09-17 07:05:47 +02:00
|
|
|
ircd::db::has(const columns &c,
|
|
|
|
const keys &key,
|
2020-06-09 06:40:54 +02:00
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
if(c.empty())
|
|
|
|
return 0UL;
|
|
|
|
|
2020-09-17 07:05:47 +02:00
|
|
|
const auto &num
|
|
|
|
{
|
|
|
|
key.size()
|
|
|
|
};
|
|
|
|
|
2020-06-09 06:40:54 +02:00
|
|
|
if(unlikely(!num || num > 64))
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"db::has() :too many columns or vector size mismatch"
|
|
|
|
};
|
|
|
|
|
|
|
|
_read_op op[num];
|
|
|
|
for(size_t i(0); i < num; ++i)
|
|
|
|
op[i] =
|
|
|
|
{
|
|
|
|
c[std::min(c.size() - 1, i)], key[i]
|
|
|
|
};
|
|
|
|
|
|
|
|
uint64_t i(0), ret(0);
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
_read({op, num}, opts, [&i, &ret, &opts]
|
|
|
|
(column &, const column::delta &, const rocksdb::Status &s)
|
|
|
|
{
|
|
|
|
uint64_t found {0};
|
|
|
|
found |= s.ok();
|
|
|
|
found |= s.IsIncomplete() & (opts.read_tier == NON_BLOCKING);
|
|
|
|
ret |= (found << i++);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-17 07:12:11 +02:00
|
|
|
bool
|
|
|
|
ircd::db::prefetch(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
static construction instance
|
|
|
|
{
|
|
|
|
[] { prefetcher = new struct prefetcher(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(prefetcher);
|
|
|
|
return (*prefetcher)(column, key, gopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
bool
|
|
|
|
ircd::db::cached(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
return exists(cache(column), key);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::cached(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
2020-12-05 14:51:10 +01:00
|
|
|
using rocksdb::Status;
|
2020-09-17 07:12:11 +02:00
|
|
|
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
opts.read_tier = NON_BLOCKING;
|
|
|
|
opts.fill_cache = false;
|
2020-12-05 14:51:10 +01:00
|
|
|
const auto status
|
|
|
|
{
|
|
|
|
_read(column, key, opts)
|
|
|
|
};
|
2020-09-17 07:12:11 +02:00
|
|
|
|
2020-12-05 14:51:10 +01:00
|
|
|
return false
|
|
|
|
|| status.code() == Status::kOk
|
|
|
|
|| status.code() == Status::kNotFound
|
|
|
|
;
|
2020-09-17 07:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
const string_view &name)
|
|
|
|
{
|
|
|
|
std::string ret;
|
2020-11-03 20:30:15 +01:00
|
|
|
database::column &c(mutable_cast(column));
|
|
|
|
database &d(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
if(!d.d->GetProperty(c, slice(name), &ret))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"'property '%s' for column '%s' in '%s' not found.",
|
|
|
|
name,
|
|
|
|
db::name(column),
|
|
|
|
db::name(d)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ircd::db::prop_int
|
|
|
|
ircd::db::property(const column &column,
|
|
|
|
const string_view &name)
|
|
|
|
{
|
|
|
|
uint64_t ret(0);
|
2020-11-03 20:30:15 +01:00
|
|
|
database::column &c(mutable_cast(column));
|
|
|
|
database &d(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
if(!d.d->GetIntProperty(c, slice(name), &ret))
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"property '%s' for column '%s' in '%s' not found or not an integer.",
|
|
|
|
name,
|
|
|
|
db::name(column),
|
|
|
|
db::name(d)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ircd::db::prop_map
|
|
|
|
ircd::db::property(const column &column,
|
|
|
|
const string_view &name)
|
|
|
|
{
|
|
|
|
std::map<std::string, std::string> ret;
|
2020-11-03 20:30:15 +01:00
|
|
|
database::column &c(mutable_cast(column));
|
|
|
|
database &d(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
if(!d.d->GetMapProperty(c, slice(name), &ret))
|
|
|
|
ret.emplace(std::string{name}, property<std::string>(column, name));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options
|
|
|
|
ircd::db::getopt(const column &column)
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
database &d(mutable_cast(column));
|
|
|
|
database::column &c(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
return options
|
|
|
|
{
|
|
|
|
static_cast<rocksdb::ColumnFamilyOptions>(d.d->GetOptions(c))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::bytes(const column &column)
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyMetaData cfm;
|
2020-11-03 20:30:15 +01:00
|
|
|
database &d(mutable_cast(column));
|
|
|
|
database::column &c(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
assert(bool(c.handle));
|
|
|
|
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
|
|
|
return cfm.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::file_count(const column &column)
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyMetaData cfm;
|
2020-11-03 20:30:15 +01:00
|
|
|
database &d(mutable_cast(column));
|
|
|
|
database::column &c(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
assert(bool(c.handle));
|
|
|
|
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
|
|
|
return cfm.file_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::files(const column &column)
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
database::column &c(mutable_cast(column));
|
2020-09-17 07:12:11 +02:00
|
|
|
database &d(*c.d);
|
|
|
|
|
|
|
|
rocksdb::ColumnFamilyMetaData cfmd;
|
|
|
|
d.d->GetColumnFamilyMetaData(c, &cfmd);
|
|
|
|
|
|
|
|
size_t count(0);
|
|
|
|
for(const auto &level : cfmd.levels)
|
|
|
|
count += level.files.size();
|
|
|
|
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
ret.reserve(count);
|
|
|
|
for(auto &level : cfmd.levels)
|
|
|
|
for(auto &file : level.files)
|
|
|
|
ret.emplace_back(std::move(file.name));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::descriptor &
|
|
|
|
ircd::db::describe(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return describe(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return name(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ircd::db::id(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return id(c);
|
|
|
|
}
|
|
|
|
|
2017-08-31 07:13:50 +02:00
|
|
|
//
|
|
|
|
// column
|
|
|
|
//
|
|
|
|
|
2019-01-16 22:21:54 +01:00
|
|
|
ircd::db::column::column(database &d,
|
|
|
|
const string_view &column_name,
|
|
|
|
const std::nothrow_t)
|
|
|
|
:c{[&d, &column_name]
|
|
|
|
{
|
|
|
|
const int32_t cfid
|
|
|
|
{
|
|
|
|
d.cfid(std::nothrow, column_name)
|
|
|
|
};
|
|
|
|
|
|
|
|
return cfid >= 0?
|
|
|
|
&d[cfid]:
|
|
|
|
nullptr;
|
|
|
|
}()}
|
2017-08-31 07:13:50 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::column(database &d,
|
|
|
|
const string_view &column_name)
|
2019-01-16 22:21:54 +01:00
|
|
|
:column
|
|
|
|
{
|
|
|
|
d[column_name]
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::column(database::column &c)
|
|
|
|
:c{&c}
|
|
|
|
{
|
|
|
|
}
|
2017-08-31 07:13:50 +02:00
|
|
|
|
2017-03-23 22:58:24 +01:00
|
|
|
void
|
2017-08-23 22:37:47 +02:00
|
|
|
ircd::db::column::operator()(const delta &delta,
|
2017-03-31 00:57:08 +02:00
|
|
|
const sopts &sopts)
|
2017-03-23 22:58:24 +01:00
|
|
|
{
|
2017-08-23 22:37:47 +02:00
|
|
|
operator()(&delta, &delta + 1, sopts);
|
2017-03-23 22:58:24 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
void
|
|
|
|
ircd::db::column::operator()(const sopts &sopts,
|
|
|
|
const std::initializer_list<delta> &deltas)
|
|
|
|
{
|
|
|
|
operator()(deltas, sopts);
|
|
|
|
}
|
|
|
|
|
2017-03-21 07:28:20 +01:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::operator()(const std::initializer_list<delta> &deltas,
|
|
|
|
const sopts &sopts)
|
2017-03-21 07:28:20 +01:00
|
|
|
{
|
2017-08-23 22:37:47 +02:00
|
|
|
operator()(std::begin(deltas), std::end(deltas), sopts);
|
2017-03-21 07:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-23 22:37:47 +02:00
|
|
|
ircd::db::column::operator()(const delta *const &begin,
|
|
|
|
const delta *const &end,
|
2017-03-31 00:57:08 +02:00
|
|
|
const sopts &sopts)
|
2017-03-21 07:28:20 +01:00
|
|
|
{
|
2017-08-23 22:37:47 +02:00
|
|
|
database &d(*this);
|
|
|
|
|
2017-03-21 07:28:20 +01:00
|
|
|
rocksdb::WriteBatch batch;
|
2017-08-23 22:37:47 +02:00
|
|
|
std::for_each(begin, end, [this, &batch]
|
|
|
|
(const delta &delta)
|
|
|
|
{
|
|
|
|
append(batch, *this, delta);
|
|
|
|
});
|
2017-03-21 07:28:20 +01:00
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
commit(d, batch, sopts);
|
2017-03-21 07:28:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-24 06:01:57 +02:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::operator()(const string_view &key,
|
|
|
|
const gopts &gopts,
|
|
|
|
const view_closure &func)
|
2016-11-29 16:23:38 +01:00
|
|
|
{
|
|
|
|
return operator()(key, func, gopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::operator()(const string_view &key,
|
|
|
|
const view_closure &func,
|
|
|
|
const gopts &gopts)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2017-03-31 00:57:08 +02:00
|
|
|
const auto it(seek(*this, key, gopts));
|
2017-09-16 20:48:09 +02:00
|
|
|
valid_eq_or_throw(*it, key);
|
2017-04-03 06:02:32 +02:00
|
|
|
func(val(*it));
|
|
|
|
}
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2018-01-27 19:07:08 +01:00
|
|
|
bool
|
|
|
|
ircd::db::column::operator()(const string_view &key,
|
|
|
|
const std::nothrow_t,
|
|
|
|
const gopts &gopts,
|
|
|
|
const view_closure &func)
|
|
|
|
{
|
|
|
|
return operator()(key, std::nothrow, func, gopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::column::operator()(const string_view &key,
|
|
|
|
const std::nothrow_t,
|
|
|
|
const view_closure &func,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
const auto it(seek(*this, key, gopts));
|
|
|
|
if(!valid_eq(*it, key))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
func(val(*it));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::cell
|
|
|
|
ircd::db::column::operator[](const string_view &key)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return { *this, key };
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 01:00:22 +01:00
|
|
|
ircd::db::column::operator
|
|
|
|
bool()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return c?
|
|
|
|
!dropped(*c):
|
|
|
|
false;
|
|
|
|
}
|
|
|
|
|
2017-09-08 10:33:41 +02:00
|
|
|
ircd::db::column::operator
|
2018-09-20 00:38:37 +02:00
|
|
|
const descriptor &()
|
2017-09-08 10:33:41 +02:00
|
|
|
const
|
|
|
|
{
|
2018-10-22 16:09:16 +02:00
|
|
|
assert(c->descriptor);
|
|
|
|
return *c->descriptor;
|
2017-09-08 10:33:41 +02:00
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2017-03-23 22:58:24 +01:00
|
|
|
//
|
2017-03-31 00:57:08 +02:00
|
|
|
// column::const_iterator
|
2017-03-23 22:58:24 +01:00
|
|
|
//
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::const_iterator
|
2018-05-25 11:34:44 +02:00
|
|
|
ircd::db::column::end(gopts gopts)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-09-22 12:31:44 +02:00
|
|
|
const_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(gopts)
|
2017-09-22 12:31:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, pos::END);
|
2017-09-22 12:31:44 +02:00
|
|
|
return ret;
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
|
2019-02-05 03:41:00 +01:00
|
|
|
ircd::db::column::const_iterator
|
|
|
|
ircd::db::column::last(gopts gopts)
|
|
|
|
{
|
|
|
|
const_iterator ret
|
|
|
|
{
|
|
|
|
c, {}, std::move(gopts)
|
|
|
|
};
|
|
|
|
|
|
|
|
seek(ret, pos::BACK);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::const_iterator
|
2018-05-25 11:34:44 +02:00
|
|
|
ircd::db::column::begin(gopts gopts)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2016-09-26 06:07:22 +02:00
|
|
|
const_iterator ret
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(gopts)
|
2016-09-26 06:07:22 +02:00
|
|
|
};
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, pos::FRONT);
|
2017-09-22 12:31:44 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_reverse_iterator
|
2018-05-25 11:34:44 +02:00
|
|
|
ircd::db::column::rend(gopts gopts)
|
2017-09-22 12:31:44 +02:00
|
|
|
{
|
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(gopts)
|
2017-09-22 12:31:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, pos::END);
|
2017-09-22 12:31:44 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_reverse_iterator
|
2018-05-25 11:34:44 +02:00
|
|
|
ircd::db::column::rbegin(gopts gopts)
|
2017-09-22 12:31:44 +02:00
|
|
|
{
|
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(gopts)
|
2017-09-22 12:31:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, pos::BACK);
|
2017-09-22 12:31:44 +02:00
|
|
|
return ret;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::const_iterator
|
|
|
|
ircd::db::column::upper_bound(const string_view &key,
|
2018-05-25 11:34:44 +02:00
|
|
|
gopts gopts)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
auto it(lower_bound(key, std::move(gopts)));
|
2017-03-31 00:57:08 +02:00
|
|
|
if(it && it.it->key().compare(slice(key)) == 0)
|
2016-09-26 06:07:22 +02:00
|
|
|
++it;
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
return it;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::const_iterator
|
|
|
|
ircd::db::column::find(const string_view &key,
|
2018-05-25 11:34:44 +02:00
|
|
|
gopts gopts)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-03-31 00:57:08 +02:00
|
|
|
auto it(lower_bound(key, gopts));
|
|
|
|
if(!it || it.it->key().compare(slice(key)) != 0)
|
2017-09-22 05:08:11 +02:00
|
|
|
return end(gopts);
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
2016-09-26 06:07:22 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::column::const_iterator
|
|
|
|
ircd::db::column::lower_bound(const string_view &key,
|
2018-05-25 11:34:44 +02:00
|
|
|
gopts gopts)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2016-09-26 06:07:22 +02:00
|
|
|
const_iterator ret
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(gopts)
|
2016-09-26 06:07:22 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, key);
|
2017-09-22 12:31:44 +02:00
|
|
|
return ret;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::column::const_iterator &
|
|
|
|
ircd::db::column::const_iterator::operator--()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_iterator &
|
|
|
|
ircd::db::column::const_iterator::operator++()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_reverse_iterator &
|
|
|
|
ircd::db::column::const_reverse_iterator::operator--()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_reverse_iterator &
|
|
|
|
ircd::db::column::const_reverse_iterator::operator++()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_iterator_base::const_iterator_base(const_iterator_base &&o)
|
2017-03-31 00:57:08 +02:00
|
|
|
noexcept
|
2017-09-08 10:33:41 +02:00
|
|
|
:c{std::move(o.c)}
|
2018-05-25 11:34:44 +02:00
|
|
|
,opts{std::move(o.opts)}
|
2017-03-31 00:57:08 +02:00
|
|
|
,it{std::move(o.it)}
|
|
|
|
,val{std::move(o.val)}
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
|
|
|
}
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::column::const_iterator_base &
|
|
|
|
ircd::db::column::const_iterator_base::operator=(const_iterator_base &&o)
|
2017-03-31 00:57:08 +02:00
|
|
|
noexcept
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-03-31 00:57:08 +02:00
|
|
|
c = std::move(o.c);
|
2018-05-25 11:34:44 +02:00
|
|
|
opts = std::move(o.opts);
|
2017-03-31 00:57:08 +02:00
|
|
|
it = std::move(o.it);
|
|
|
|
val = std::move(o.val);
|
|
|
|
return *this;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
// linkage for incmplete rocksdb::Iterator
|
|
|
|
ircd::db::column::const_iterator_base::const_iterator_base()
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
// linkage for incmplete rocksdb::Iterator
|
|
|
|
ircd::db::column::const_iterator_base::~const_iterator_base()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::const_iterator_base::const_iterator_base(database::column *const &c,
|
2018-05-25 11:34:44 +02:00
|
|
|
std::unique_ptr<rocksdb::Iterator> &&it,
|
2018-11-16 05:54:50 +01:00
|
|
|
gopts opts)
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2017-09-08 10:33:41 +02:00
|
|
|
:c{c}
|
2018-05-25 11:34:44 +02:00
|
|
|
,opts{std::move(opts)}
|
2017-03-31 00:57:08 +02:00
|
|
|
,it{std::move(it)}
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
const ircd::db::column::const_iterator_base::value_type &
|
|
|
|
ircd::db::column::const_iterator_base::operator*()
|
2016-09-26 06:07:22 +02:00
|
|
|
const
|
|
|
|
{
|
2017-09-16 20:48:09 +02:00
|
|
|
assert(it && valid(*it));
|
2017-04-03 06:02:32 +02:00
|
|
|
val.first = db::key(*it);
|
|
|
|
val.second = db::val(*it);
|
2016-09-26 06:07:22 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::column::const_iterator_base::operator bool()
|
2020-08-05 08:17:56 +02:00
|
|
|
const noexcept
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-09-16 20:48:09 +02:00
|
|
|
if(!it)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!valid(*it))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::operator!=(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2020-09-22 03:48:08 +02:00
|
|
|
const uint operands
|
|
|
|
{
|
|
|
|
uint(bool(a)) +
|
|
|
|
uint(bool(b))
|
|
|
|
};
|
|
|
|
|
|
|
|
// Two invalid iterators are equal; one invalid iterator is not.
|
|
|
|
if(likely(operands <= 1))
|
|
|
|
return operands == 1;
|
|
|
|
|
|
|
|
// Two valid iterators are compared
|
|
|
|
assert(operands == 2);
|
|
|
|
const auto &ak(a.it->key());
|
|
|
|
const auto &bk(b.it->key());
|
|
|
|
return ak.compare(bk) != 0;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::operator==(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2020-09-22 03:48:08 +02:00
|
|
|
const uint operands
|
|
|
|
{
|
|
|
|
uint(bool(a)) +
|
|
|
|
uint(bool(b))
|
|
|
|
};
|
|
|
|
|
|
|
|
// Two valid iterators are compared
|
|
|
|
if(likely(operands > 1))
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
const auto &ak(a.it->key());
|
|
|
|
const auto &bk(b.it->key());
|
|
|
|
return ak.compare(bk) == 0;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 03:48:08 +02:00
|
|
|
// Two invalid iterators are equal; one invalid iterator is not.
|
|
|
|
return operands == 0;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::operator>(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
if(a && b)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
const auto &ak(a.it->key());
|
|
|
|
const auto &bk(b.it->key());
|
|
|
|
return ak.compare(bk) == 1;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
if(!a && b)
|
2016-09-26 06:07:22 +02:00
|
|
|
return true;
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
if(!a && !b)
|
2016-09-26 06:07:22 +02:00
|
|
|
return false;
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
assert(!a && b);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::operator<(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
2020-08-05 08:17:56 +02:00
|
|
|
noexcept
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
if(a && b)
|
|
|
|
{
|
|
|
|
const auto &ak(a.it->key());
|
|
|
|
const auto &bk(b.it->key());
|
|
|
|
return ak.compare(bk) == -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!a && b)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!a && !b)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(a && !b);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class pos>
|
2017-08-30 23:05:15 +02:00
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::seek(column::const_iterator_base &it,
|
2018-05-25 11:34:44 +02:00
|
|
|
const pos &p)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
database::column &c(it);
|
2019-09-19 04:14:06 +02:00
|
|
|
return seek(c, p, make_opts(it.opts), it.it);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2018-05-25 11:34:44 +02:00
|
|
|
template bool ircd::db::seek<ircd::db::pos>(column::const_iterator_base &, const pos &);
|
|
|
|
template bool ircd::db::seek<ircd::string_view>(column::const_iterator_base &, const string_view &);
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2018-09-25 07:00:21 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// opts.h
|
2018-09-25 07:00:21 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// options
|
2018-09-25 07:00:21 +02:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::options::options(const database &d)
|
|
|
|
:options{d.d->GetDBOptions()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::options(const database::column &c)
|
|
|
|
:options
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyOptions
|
|
|
|
{
|
|
|
|
c.d->d->GetOptions(c.handle.get())
|
|
|
|
}
|
|
|
|
}{}
|
|
|
|
|
|
|
|
ircd::db::options::options(const rocksdb::DBOptions &opts)
|
|
|
|
{
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetStringFromDBOptions(this, opts)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::options(const rocksdb::ColumnFamilyOptions &opts)
|
|
|
|
{
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetStringFromColumnFamilyOptions(this, opts)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::operator rocksdb::PlainTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::PlainTableOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetPlainTableOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::operator rocksdb::BlockBasedTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::BlockBasedTableOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetBlockBasedTableOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::operator rocksdb::ColumnFamilyOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetColumnFamilyOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::operator rocksdb::DBOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::DBOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetDBOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::options::operator rocksdb::Options()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::Options ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// options::map
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::options::map::map(const options &o)
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::StringToMap(o, this)
|
|
|
|
};
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::options::map::operator rocksdb::PlainTableOptions()
|
|
|
|
const
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::PlainTableOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetPlainTableOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
2018-09-25 07:00:21 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return ret;
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::options::map::operator rocksdb::BlockBasedTableOptions()
|
|
|
|
const
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::BlockBasedTableOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetBlockBasedTableOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
2018-09-25 07:00:21 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return ret;
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::options::map::operator rocksdb::ColumnFamilyOptions()
|
|
|
|
const
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::ColumnFamilyOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetColumnFamilyOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
2018-09-25 07:00:21 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return ret;
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::options::map::operator rocksdb::DBOptions()
|
|
|
|
const
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::DBOptions ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetDBOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-09-25 07:00:21 +02:00
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// cache.h
|
2018-09-25 07:00:21 +02:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::clear(rocksdb::Cache &cache)
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
cache.EraseUnRefEntries();
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::remove(rocksdb::Cache &cache,
|
|
|
|
const string_view &key)
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
cache.Erase(slice(key));
|
|
|
|
return true;
|
2018-09-25 07:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::insert(rocksdb::Cache &cache,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &value)
|
2018-09-25 07:00:21 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
unique_buffer<const_buffer> buf
|
|
|
|
{
|
|
|
|
const_buffer{value}
|
|
|
|
};
|
2018-09-25 07:00:21 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return insert(cache, key, std::move(buf));
|
|
|
|
}
|
2017-09-14 20:30:06 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::insert(rocksdb::Cache &cache,
|
|
|
|
const string_view &key,
|
2019-04-12 18:36:53 +02:00
|
|
|
unique_buffer<const_buffer> &&value)
|
2017-09-08 11:14:17 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const size_t value_size
|
2019-01-16 22:46:15 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
size(value)
|
2019-01-16 22:46:15 +01:00
|
|
|
};
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
static const auto deleter{[]
|
|
|
|
(const rocksdb::Slice &key, void *const value)
|
2017-09-08 11:14:17 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
delete[] reinterpret_cast<const char *>(value);
|
|
|
|
}};
|
|
|
|
|
|
|
|
// Note that because of the nullptr handle argument below, rocksdb
|
|
|
|
// will run the deleter if the insert throws; just make sure
|
|
|
|
// the argument execution doesn't throw after release()
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
cache.Insert(slice(key),
|
2020-11-03 20:30:15 +01:00
|
|
|
mutable_cast(data(value.release())),
|
2019-01-29 20:13:58 +01:00
|
|
|
value_size,
|
|
|
|
deleter,
|
|
|
|
nullptr)
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
2017-09-08 11:14:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::for_each(const rocksdb::Cache &cache,
|
|
|
|
const cache_closure &closure)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
// exclusive for different contexts.
|
|
|
|
thread_local ctx::mutex mutex;
|
2019-03-02 21:33:32 +01:00
|
|
|
const std::lock_guard lock{mutex};
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
thread_local rocksdb::Cache *_cache;
|
2020-11-03 20:30:15 +01:00
|
|
|
_cache = mutable_cast(&cache);
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
thread_local const cache_closure *_closure;
|
|
|
|
_closure = &closure;
|
|
|
|
|
|
|
|
_cache->ApplyToAllCacheEntries([]
|
|
|
|
(void *const value_buffer, const size_t buffer_size)
|
|
|
|
noexcept
|
2019-01-16 22:46:15 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
assert(_cache);
|
|
|
|
assert(_closure);
|
|
|
|
const const_buffer buf
|
2019-01-16 22:46:15 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
reinterpret_cast<const char *>(value_buffer), buffer_size
|
2019-01-16 22:46:15 +01:00
|
|
|
};
|
2017-09-08 11:14:17 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
(*_closure)(buf);
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
}
|
2019-01-16 22:46:15 +01:00
|
|
|
|
2020-05-05 22:06:39 +02:00
|
|
|
#ifdef IRCD_DB_HAS_CACHE_GETCHARGE
|
|
|
|
size_t
|
|
|
|
ircd::db::charge(const rocksdb::Cache &cache_,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
auto &cache
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
mutable_cast(cache_)
|
2020-05-05 22:06:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const custom_ptr<rocksdb::Cache::Handle> handle
|
|
|
|
{
|
|
|
|
cache.Lookup(slice(key)), [&cache](auto *const &handle)
|
|
|
|
{
|
|
|
|
cache.Release(handle);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return cache.GetCharge(handle);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
size_t
|
|
|
|
ircd::db::charge(const rocksdb::Cache &cache,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
return 0UL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-19 17:49:33 +01:00
|
|
|
[[gnu::hot]]
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::exists(const rocksdb::Cache &cache_,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
auto &cache
|
2017-09-08 11:14:17 +02:00
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
mutable_cast(cache_)
|
2019-01-29 20:13:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const custom_ptr<rocksdb::Cache::Handle> handle
|
|
|
|
{
|
|
|
|
cache.Lookup(slice(key)), [&cache](auto *const &handle)
|
|
|
|
{
|
|
|
|
cache.Release(handle);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return bool(handle);
|
2017-09-08 11:14:17 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 02:21:10 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::count(const rocksdb::Cache &cache)
|
|
|
|
{
|
|
|
|
size_t ret(0);
|
|
|
|
for_each(cache, [&ret]
|
|
|
|
(const const_buffer &)
|
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::pinned(const rocksdb::Cache &cache)
|
2017-09-08 11:14:17 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return cache.GetPinnedUsage();
|
|
|
|
}
|
2018-03-14 01:32:13 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::usage(const rocksdb::Cache &cache)
|
2017-09-19 04:17:36 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return cache.GetUsage();
|
2017-09-19 04:17:36 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::capacity(rocksdb::Cache &cache,
|
|
|
|
const size_t &cap)
|
|
|
|
{
|
|
|
|
cache.SetCapacity(cap);
|
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::capacity(const rocksdb::Cache &cache)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return cache.GetCapacity();
|
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
const uint64_t &
|
|
|
|
ircd::db::ticker(const rocksdb::Cache &cache,
|
|
|
|
const uint32_t &ticker_id)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto &c
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
dynamic_cast<const database::cache &>(cache)
|
2017-04-03 06:02:32 +02:00
|
|
|
};
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
static const uint64_t &zero
|
|
|
|
{
|
|
|
|
0ULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return c.stats?
|
|
|
|
c.stats->ticker.at(ticker_id):
|
|
|
|
zero;
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// error.h
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// error::not_found
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::db::error::not_found::_not_found_)
|
|
|
|
ircd::db::error::not_found::_not_found_
|
2017-09-23 10:13:26 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::Status::NotFound()
|
|
|
|
};
|
2018-08-20 04:30:17 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// error::not_found::not_found
|
|
|
|
//
|
2017-09-23 10:13:26 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error::not_found::not_found()
|
|
|
|
:error
|
|
|
|
{
|
|
|
|
generate_skip, _not_found_
|
2017-09-23 10:13:26 +02:00
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
strlcpy(buf, "NotFound");
|
|
|
|
}
|
2017-08-19 00:13:15 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// error
|
|
|
|
//
|
2017-08-19 00:13:15 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
decltype(ircd::db::error::_no_code_)
|
|
|
|
ircd::db::error::_no_code_
|
|
|
|
{
|
|
|
|
rocksdb::Status::OK()
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// error::error
|
|
|
|
//
|
2017-09-23 10:13:26 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error::error(internal_t,
|
|
|
|
const rocksdb::Status &s,
|
|
|
|
const string_view &fmt,
|
|
|
|
const va_rtti &ap)
|
|
|
|
:error
|
2017-09-23 10:13:26 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
s
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const string_view &msg{buf};
|
|
|
|
const mutable_buffer remain
|
2017-09-23 10:13:26 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
buf + size(msg), sizeof(buf) - size(msg)
|
2017-09-23 10:13:26 +02:00
|
|
|
};
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
fmt::vsprintf
|
2018-05-29 10:42:48 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
remain, fmt, ap
|
2018-05-29 10:42:48 +02:00
|
|
|
};
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2018-05-29 10:42:48 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error::error(const rocksdb::Status &s)
|
|
|
|
:error
|
|
|
|
{
|
|
|
|
generate_skip, s
|
|
|
|
}
|
|
|
|
{
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2020-02-27 23:48:19 +01:00
|
|
|
buf, "(%u:%u:%u) %s %s :%s",
|
2019-01-29 20:13:58 +01:00
|
|
|
this->code,
|
|
|
|
this->subcode,
|
|
|
|
this->severity,
|
2020-02-27 23:48:19 +01:00
|
|
|
reflect(rocksdb::Status::Severity(this->severity)),
|
|
|
|
reflect(rocksdb::Status::Code(this->code)),
|
2019-01-29 20:13:58 +01:00
|
|
|
s.getState(),
|
|
|
|
};
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error::error(generate_skip_t,
|
|
|
|
const rocksdb::Status &s)
|
|
|
|
:ircd::error
|
2017-09-24 04:47:36 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
generate_skip
|
2017-09-24 04:47:36 +02:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
,code
|
2017-09-24 04:47:36 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
s.code()
|
2017-09-24 04:47:36 +02:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
,subcode
|
2017-09-24 04:47:36 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
s.subcode()
|
2017-09-24 04:47:36 +02:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
,severity
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2020-02-27 23:48:19 +01:00
|
|
|
s.severity()?
|
|
|
|
s.severity():
|
|
|
|
|
|
|
|
code == rocksdb::Status::kCorruption?
|
|
|
|
rocksdb::Status::kHardError:
|
|
|
|
|
|
|
|
rocksdb::Status::kNoError
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
2016-09-26 06:07:22 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// merge.h
|
|
|
|
//
|
2017-09-08 11:14:17 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
std::string
|
2019-02-16 22:51:55 +01:00
|
|
|
__attribute__((noreturn))
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::merge_operator(const string_view &key,
|
|
|
|
const std::pair<string_view, string_view> &delta)
|
|
|
|
{
|
|
|
|
//ircd::json::index index{delta.first};
|
|
|
|
//index += delta.second;
|
|
|
|
//return index;
|
2019-02-16 22:51:55 +01:00
|
|
|
|
|
|
|
throw ircd::not_implemented
|
|
|
|
{
|
|
|
|
"db::merge_operator()"
|
|
|
|
};
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:53:16 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// comparator.h
|
2018-12-12 18:53:16 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// linkage placements for integer comparators so they all have the same addr
|
2018-12-12 18:53:16 +01:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cmp_int64_t::cmp_int64_t()
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cmp_int64_t::~cmp_int64_t()
|
|
|
|
noexcept
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2018-12-12 18:53:16 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cmp_uint64_t::cmp_uint64_t()
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::cmp_uint64_t::~cmp_uint64_t()
|
|
|
|
noexcept
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::reverse_cmp_int64_t::reverse_cmp_int64_t()
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::reverse_cmp_int64_t::~reverse_cmp_int64_t()
|
|
|
|
noexcept
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::reverse_cmp_uint64_t::reverse_cmp_uint64_t()
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::reverse_cmp_uint64_t::~reverse_cmp_uint64_t()
|
|
|
|
noexcept
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2018-12-12 18:53:16 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// cmp_string_view
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::cmp_string_view::cmp_string_view()
|
|
|
|
:db::comparator{"string_view", &less, &equal}
|
|
|
|
{
|
2018-12-12 18:53:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// reverse_cmp_string_view
|
2018-12-12 18:53:16 +01:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::reverse_cmp_string_view::reverse_cmp_string_view()
|
|
|
|
:db::comparator{"reverse_string_view", &less, &equal}
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::reverse_cmp_string_view::less(const string_view &a,
|
|
|
|
const string_view &b)
|
2020-07-28 06:28:13 +02:00
|
|
|
noexcept
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
/// RocksDB sez things will not work correctly unless a shorter string
|
|
|
|
/// result returns less than a longer string even if one intends some
|
|
|
|
/// reverse ordering
|
|
|
|
if(a.size() < b.size())
|
|
|
|
return true;
|
2018-12-12 18:53:16 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
/// Furthermore, b.size() < a.size() returning false from this function
|
|
|
|
/// appears to not be correct. The reversal also has to also come in
|
|
|
|
/// the form of a bytewise forward iteration.
|
|
|
|
return std::memcmp(a.data(), b.data(), std::min(a.size(), b.size())) > 0;
|
2018-12-12 18:53:16 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// delta.h
|
|
|
|
//
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::value_required(const op &op)
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
switch(op)
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
case op::SET:
|
|
|
|
case op::MERGE:
|
|
|
|
case op::DELETE_RANGE:
|
|
|
|
return true;
|
2018-12-12 18:53:16 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
case op::GET:
|
|
|
|
case op::DELETE:
|
|
|
|
case op::SINGLE_DELETE:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return false;
|
2018-12-12 18:53:16 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// db.h (internal)
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// throw_on_error
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::throw_on_error::throw_on_error(const rocksdb::Status &status)
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
using rocksdb::Status;
|
|
|
|
|
|
|
|
switch(status.code())
|
2018-12-12 18:53:16 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
case Status::kOk:
|
|
|
|
return;
|
2018-12-12 18:53:16 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
case Status::kNotFound:
|
|
|
|
throw not_found{};
|
|
|
|
|
2020-01-11 00:23:48 +01:00
|
|
|
#ifdef RB_DEBUG
|
2020-02-27 23:49:26 +01:00
|
|
|
//case Status::kCorruption:
|
2020-01-11 00:23:48 +01:00
|
|
|
case Status::kNotSupported:
|
|
|
|
case Status::kInvalidArgument:
|
|
|
|
debugtrap();
|
|
|
|
[[fallthrough]];
|
|
|
|
#endif
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
default:
|
2020-01-11 00:23:48 +01:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
status
|
|
|
|
};
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2018-12-12 18:53:16 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:17:43 +02:00
|
|
|
//
|
2019-01-29 20:13:58 +01:00
|
|
|
// error_to_status
|
2018-05-15 01:17:43 +02:00
|
|
|
//
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error_to_status::error_to_status(const std::exception &e)
|
|
|
|
:rocksdb::Status
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
Status::Aborted(slice(string_view(e.what())))
|
2018-08-19 02:59:31 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error_to_status::error_to_status(const std::system_error &e)
|
|
|
|
:error_to_status{e.code()}
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::error_to_status::error_to_status(const std::error_code &e)
|
|
|
|
:rocksdb::Status{[&e]
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
using std::errc;
|
2018-08-19 02:59:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
switch(e.value())
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
case 0:
|
|
|
|
return Status::OK();
|
2018-08-19 02:59:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
case int(errc::no_such_file_or_directory):
|
|
|
|
return Status::NotFound();
|
2018-08-19 02:59:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
case int(errc::not_supported):
|
|
|
|
return Status::NotSupported();
|
|
|
|
|
|
|
|
case int(errc::invalid_argument):
|
|
|
|
return Status::InvalidArgument();
|
|
|
|
|
|
|
|
case int(errc::io_error):
|
|
|
|
return Status::IOError();
|
|
|
|
|
|
|
|
case int(errc::timed_out):
|
|
|
|
return Status::TimedOut();
|
|
|
|
|
|
|
|
case int(errc::device_or_resource_busy):
|
|
|
|
return Status::Busy();
|
|
|
|
|
|
|
|
case int(errc::resource_unavailable_try_again):
|
|
|
|
return Status::TryAgain();
|
|
|
|
|
|
|
|
case int(errc::no_space_on_device):
|
|
|
|
return Status::NoSpace();
|
|
|
|
|
|
|
|
case int(errc::not_enough_memory):
|
|
|
|
return Status::MemoryLimit();
|
|
|
|
|
|
|
|
default:
|
2020-10-28 06:25:20 +01:00
|
|
|
{
|
|
|
|
const auto &message(e.message());
|
|
|
|
return Status::Aborted(slice(string_view(message)));
|
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
|
|
|
}()}
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// writebatch suite
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::append(rocksdb::WriteBatch &batch,
|
|
|
|
const cell::delta &delta)
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
auto &column
|
2018-08-21 09:47:05 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
std::get<cell *>(delta)->c
|
2018-08-21 09:47:05 +02:00
|
|
|
};
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
append(batch, column, column::delta
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
std::get<op>(delta),
|
|
|
|
std::get<cell *>(delta)->key(),
|
|
|
|
std::get<string_view>(delta)
|
|
|
|
});
|
|
|
|
}
|
2018-08-19 02:59:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::append(rocksdb::WriteBatch &batch,
|
|
|
|
column &column,
|
|
|
|
const column::delta &delta)
|
|
|
|
{
|
|
|
|
if(unlikely(!column))
|
2018-08-19 02:59:31 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
// Note: Unknown at this time whether allowing attempts at writing
|
|
|
|
// to a null column should be erroneous or silently ignored. It's
|
|
|
|
// highly likely this log message will be removed soon to allow
|
|
|
|
// toggling database columns for optimization without touching calls.
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "Attempting to transact a delta for a null column"
|
|
|
|
};
|
2018-08-19 02:59:31 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
database::column &c(column);
|
|
|
|
const auto k(slice(std::get<1>(delta)));
|
|
|
|
const auto v(slice(std::get<2>(delta)));
|
|
|
|
switch(std::get<0>(delta))
|
|
|
|
{
|
|
|
|
case op::GET: assert(0); break;
|
|
|
|
case op::SET: batch.Put(c, k, v); break;
|
|
|
|
case op::MERGE: batch.Merge(c, k, v); break;
|
|
|
|
case op::DELETE: batch.Delete(c, k); break;
|
|
|
|
case op::DELETE_RANGE: batch.DeleteRange(c, k, v); break;
|
|
|
|
case op::SINGLE_DELETE: batch.SingleDelete(c, k); break;
|
|
|
|
}
|
2018-08-19 02:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::commit(database &d,
|
|
|
|
rocksdb::WriteBatch &batch,
|
|
|
|
const sopts &sopts)
|
2018-05-15 01:53:28 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
const auto opts(make_opts(sopts));
|
|
|
|
commit(d, batch, opts);
|
2018-05-15 01:53:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::commit(database &d,
|
|
|
|
rocksdb::WriteBatch &batch,
|
|
|
|
const rocksdb::WriteOptions &opts)
|
2018-05-15 01:53:28 +02:00
|
|
|
{
|
2019-04-19 09:15:14 +02:00
|
|
|
#ifdef RB_DEBUG
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::timer timer;
|
|
|
|
#endif
|
2018-05-15 01:53:28 +02:00
|
|
|
|
2019-03-02 21:33:32 +01:00
|
|
|
const std::lock_guard lock{write_mutex};
|
2019-01-29 20:13:58 +01:00
|
|
|
const ctx::uninterruptible ui;
|
2019-09-13 02:38:43 +02:00
|
|
|
const ctx::stack_usage_assertion sua;
|
2019-01-29 20:13:58 +01:00
|
|
|
throw_on_error
|
2018-05-15 01:53:28 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
d.d->Write(opts, &batch)
|
|
|
|
};
|
2018-05-15 01:53:28 +02:00
|
|
|
|
2019-04-19 09:15:14 +02:00
|
|
|
#ifdef RB_DEBUG
|
2020-08-23 12:22:33 +02:00
|
|
|
char dbuf[192];
|
2019-01-29 20:13:58 +01:00
|
|
|
log::debug
|
|
|
|
{
|
2019-07-24 02:21:17 +02:00
|
|
|
log, "[%s] %lu COMMIT %s in %ld$us",
|
2019-01-29 20:13:58 +01:00
|
|
|
d.name,
|
|
|
|
sequence(d),
|
2020-08-23 12:22:33 +02:00
|
|
|
debug(dbuf, batch),
|
2019-01-29 20:13:58 +01:00
|
|
|
timer.at<microseconds>().count()
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-15 01:53:28 +02:00
|
|
|
}
|
|
|
|
|
2020-08-23 12:22:33 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::debug(const mutable_buffer &buf,
|
|
|
|
const rocksdb::WriteBatch &batch)
|
|
|
|
{
|
2020-08-26 01:02:53 +02:00
|
|
|
char pbuf[48] {0};
|
2020-08-23 12:22:33 +02:00
|
|
|
const auto len(snprintf
|
|
|
|
(
|
|
|
|
data(buf), size(buf),
|
2020-08-26 01:02:53 +02:00
|
|
|
"%d deltas; %s %s+%s+%s+%s+%s+%s+%s+%s+%s"
|
2020-08-23 12:22:33 +02:00
|
|
|
,batch.Count()
|
2020-08-26 01:02:53 +02:00
|
|
|
,pretty(pbuf, iec(batch.GetDataSize())).data()
|
2020-08-23 12:22:33 +02:00
|
|
|
,batch.HasPut()? "PUT": ""
|
|
|
|
,batch.HasDelete()? "DEL": ""
|
|
|
|
,batch.HasSingleDelete()? "SDL": ""
|
|
|
|
,batch.HasDeleteRange()? "DRG": ""
|
|
|
|
,batch.HasMerge()? "MRG": ""
|
|
|
|
,batch.HasBeginPrepare()? "BEG": ""
|
|
|
|
,batch.HasEndPrepare()? "END": ""
|
|
|
|
,batch.HasCommit()? "COM-": ""
|
|
|
|
,batch.HasRollback()? "RB^": ""
|
|
|
|
));
|
|
|
|
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(buf), len
|
|
|
|
};
|
2018-05-15 01:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-01-29 20:13:58 +01:00
|
|
|
ircd::db::has(const rocksdb::WriteBatch &wb,
|
|
|
|
const op &op)
|
2018-05-15 01:36:48 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
switch(op)
|
2018-05-15 01:36:48 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
case op::GET: assert(0); return false;
|
|
|
|
case op::SET: return wb.HasPut();
|
|
|
|
case op::MERGE: return wb.HasMerge();
|
|
|
|
case op::DELETE: return wb.HasDelete();
|
|
|
|
case op::DELETE_RANGE: return wb.HasDeleteRange();
|
|
|
|
case op::SINGLE_DELETE: return wb.HasSingleDelete();
|
|
|
|
}
|
2018-05-15 01:36:48 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return false;
|
2018-09-26 11:34:47 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
2020-06-07 04:59:12 +02:00
|
|
|
// read suite
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
static rocksdb::Status _seek(database::column &, rocksdb::PinnableSlice &, const string_view &, const rocksdb::ReadOptions &);
|
|
|
|
}
|
|
|
|
|
2020-06-16 06:54:30 +02:00
|
|
|
rocksdb::Status
|
2020-06-07 04:59:12 +02:00
|
|
|
ircd::db::_read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
|
|
|
const column::view_closure &closure)
|
|
|
|
{
|
|
|
|
std::string buf;
|
|
|
|
rocksdb::PinnableSlice ps
|
|
|
|
{
|
|
|
|
&buf
|
|
|
|
};
|
|
|
|
|
|
|
|
database::column &c(column);
|
2020-06-16 06:54:30 +02:00
|
|
|
const rocksdb::Status ret
|
2020-06-07 04:59:12 +02:00
|
|
|
{
|
|
|
|
_seek(c, ps, key, opts)
|
|
|
|
};
|
|
|
|
|
2020-06-16 06:54:30 +02:00
|
|
|
if(!valid(ret))
|
|
|
|
return ret;
|
2020-06-07 04:59:12 +02:00
|
|
|
|
|
|
|
const string_view value
|
|
|
|
{
|
|
|
|
slice(ps)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(likely(closure))
|
|
|
|
closure(value);
|
|
|
|
|
2020-06-18 03:51:35 +02:00
|
|
|
// Update stats about whether the pinnable slices we obtained have internal
|
|
|
|
// copies or referencing the cache copy.
|
2020-06-18 06:36:05 +02:00
|
|
|
database &d(column);
|
|
|
|
c.stats->get_referenced += buf.empty();
|
|
|
|
d.stats->get_referenced += buf.empty();
|
|
|
|
c.stats->get_copied += !buf.empty();
|
|
|
|
d.stats->get_copied += !buf.empty();
|
2020-06-16 06:54:30 +02:00
|
|
|
return ret;
|
2020-06-07 04:59:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::_seek(database::column &c,
|
|
|
|
rocksdb::PinnableSlice &s,
|
|
|
|
const string_view &key,
|
|
|
|
const rocksdb::ReadOptions &ropts)
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
|
|
|
|
rocksdb::ColumnFamilyHandle *const &cf(c);
|
|
|
|
database &d(*c.d);
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
const ircd::timer timer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const rocksdb::Status ret
|
|
|
|
{
|
|
|
|
d.d->Get(ropts, cf, slice(key), &s)
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "[%s] %lu:%lu SEEK %s in %ld$us '%s'",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
2020-06-09 08:53:01 +02:00
|
|
|
sequence(ropts.snapshot),
|
2020-06-07 04:59:12 +02:00
|
|
|
ret.ToString(),
|
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
name(c)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:19:55 +02:00
|
|
|
//
|
|
|
|
// parallel read suite
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
static void _seek(const vector_view<_read_op> &, const vector_view<rocksdb::Status> &, const vector_view<rocksdb::PinnableSlice> &, const rocksdb::ReadOptions &);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::_read(const vector_view<_read_op> &op,
|
|
|
|
const rocksdb::ReadOptions &ropts,
|
|
|
|
const _read_closure &closure)
|
|
|
|
{
|
|
|
|
assert(op.size() >= 1);
|
|
|
|
assert(op.size() <= IOV_MAX);
|
|
|
|
const size_t &num
|
|
|
|
{
|
|
|
|
op.size()
|
|
|
|
};
|
|
|
|
|
2020-06-11 17:35:57 +02:00
|
|
|
std::string buf[num];
|
2020-06-09 03:19:55 +02:00
|
|
|
rocksdb::PinnableSlice val[num];
|
2020-06-11 17:35:57 +02:00
|
|
|
for(size_t i(0); i < num; ++i)
|
|
|
|
new (val + i) rocksdb::PinnableSlice
|
|
|
|
{
|
|
|
|
buf + i
|
|
|
|
};
|
|
|
|
|
2020-06-14 15:09:44 +02:00
|
|
|
const bool parallelize
|
2020-06-11 21:34:47 +02:00
|
|
|
{
|
2020-06-16 07:34:08 +02:00
|
|
|
#ifdef IRCD_DB_HAS_MULTIGET_DIRECT
|
2020-06-14 15:09:44 +02:00
|
|
|
true && num > 1
|
|
|
|
#else
|
|
|
|
false
|
|
|
|
#endif
|
|
|
|
};
|
2020-06-11 17:35:57 +02:00
|
|
|
|
2020-06-14 15:09:44 +02:00
|
|
|
rocksdb::Status status[num];
|
|
|
|
if(!parallelize)
|
|
|
|
for(size_t i(0); i < num; ++i)
|
2020-06-09 03:19:55 +02:00
|
|
|
{
|
2020-06-14 15:09:44 +02:00
|
|
|
database::column &column(std::get<column>(op[i]));
|
|
|
|
status[i] = _seek(column, val[i], std::get<1>(op[i]), ropts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_seek(op, {status, num}, {val, num}, ropts);
|
2020-06-09 03:19:55 +02:00
|
|
|
|
2020-06-18 06:36:05 +02:00
|
|
|
bool ret(true);
|
2020-06-14 15:09:44 +02:00
|
|
|
if(closure)
|
2020-06-18 06:36:05 +02:00
|
|
|
for(size_t i(0); i < num && ret; ++i)
|
2020-06-14 15:09:44 +02:00
|
|
|
{
|
|
|
|
const column::delta delta(std::get<1>(op[i]), slice(val[i]));
|
2020-06-18 06:36:05 +02:00
|
|
|
ret = closure(std::get<column>(op[i]), delta, status[i]);
|
2020-06-14 15:09:44 +02:00
|
|
|
}
|
2020-06-09 03:19:55 +02:00
|
|
|
|
2020-06-18 03:51:35 +02:00
|
|
|
// Update stats about whether the pinnable slices we obtained have internal
|
|
|
|
// copies or referencing the cache copy.
|
2020-06-18 06:36:05 +02:00
|
|
|
for(size_t i(0); i < num; ++i)
|
2020-06-18 03:51:35 +02:00
|
|
|
{
|
2020-06-18 06:36:05 +02:00
|
|
|
database &d(std::get<column>(op[i]));
|
|
|
|
database::column &c(std::get<column>(op[i]));
|
2020-06-18 03:51:35 +02:00
|
|
|
|
2020-06-18 06:36:05 +02:00
|
|
|
// Find the correct stats to update, one for the specific column and
|
|
|
|
// one for the database total.
|
|
|
|
ircd::stats::item<uint64_t *> *item_[2]
|
2020-06-18 03:51:35 +02:00
|
|
|
{
|
2020-06-18 06:36:05 +02:00
|
|
|
parallelize && buf[i].empty()? &c.stats->multiget_referenced:
|
|
|
|
parallelize? &c.stats->multiget_copied:
|
|
|
|
buf[i].empty()? &c.stats->get_referenced:
|
|
|
|
&c.stats->get_copied,
|
|
|
|
|
|
|
|
parallelize && buf[i].empty()? &d.stats->multiget_referenced:
|
|
|
|
parallelize? &d.stats->multiget_copied:
|
|
|
|
buf[i].empty()? &d.stats->get_referenced:
|
|
|
|
&d.stats->get_copied,
|
2020-06-18 03:51:35 +02:00
|
|
|
};
|
|
|
|
|
2020-06-18 06:36:05 +02:00
|
|
|
for(auto *const &item : item_)
|
|
|
|
++(*item);
|
2020-06-18 03:51:35 +02:00
|
|
|
}
|
2020-06-11 17:35:57 +02:00
|
|
|
|
2020-06-18 06:36:05 +02:00
|
|
|
return ret;
|
2020-06-09 03:19:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::_seek(const vector_view<_read_op> &op,
|
|
|
|
const vector_view<rocksdb::Status> &ret,
|
|
|
|
const vector_view<rocksdb::PinnableSlice> &val,
|
|
|
|
const rocksdb::ReadOptions &ropts)
|
|
|
|
{
|
|
|
|
assert(ret.size() == op.size());
|
|
|
|
assert(ret.size() == val.size());
|
|
|
|
|
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
assert(op.size() >= 1);
|
|
|
|
database &d(std::get<0>(op[0]));
|
|
|
|
const size_t &num
|
|
|
|
{
|
|
|
|
op.size()
|
|
|
|
};
|
|
|
|
|
|
|
|
rocksdb::Slice key[num];
|
|
|
|
std::transform(begin(op), end(op), key, []
|
|
|
|
(const auto &op)
|
|
|
|
{
|
|
|
|
return slice(std::get<1>(op));
|
|
|
|
});
|
|
|
|
|
|
|
|
rocksdb::ColumnFamilyHandle *cf[num];
|
|
|
|
std::transform(begin(op), end(op), cf, []
|
|
|
|
(auto &op_)
|
|
|
|
{
|
2020-11-03 20:30:15 +01:00
|
|
|
auto &op(mutable_cast(op_));
|
2020-06-09 03:19:55 +02:00
|
|
|
database::column &c(std::get<column>(op));
|
|
|
|
return static_cast<rocksdb::ColumnFamilyHandle *>(c);
|
|
|
|
});
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
const ircd::timer timer;
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 07:34:08 +02:00
|
|
|
#ifdef IRCD_DB_HAS_MULTIGET_BATCHED
|
2020-06-09 03:19:55 +02:00
|
|
|
d.d->MultiGet(ropts, num, cf, key, val.data(), ret.data());
|
2020-06-16 07:34:08 +02:00
|
|
|
#endif
|
2020-06-09 03:19:55 +02:00
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
|
|
|
{
|
2020-06-11 17:35:57 +02:00
|
|
|
log, "[%s] %lu:%lu SEEK parallel:%zu ok:%zu nf:%zu inc:%zu in %ld$us",
|
2020-06-09 03:19:55 +02:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
2020-06-09 08:53:01 +02:00
|
|
|
sequence(ropts.snapshot),
|
2020-06-09 03:19:55 +02:00
|
|
|
ret.size(),
|
2020-06-11 17:35:57 +02:00
|
|
|
std::count_if(begin(ret), end(ret), [](auto&& s) { return s.ok(); }),
|
|
|
|
std::count_if(begin(ret), end(ret), [](auto&& s) { return s.IsNotFound(); }),
|
|
|
|
std::count_if(begin(ret), end(ret), [](auto&& s) { return s.IsIncomplete(); }),
|
2020-06-09 03:19:55 +02:00
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
2020-06-07 04:59:12 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// iterator seek suite
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
2018-09-26 11:34:47 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
namespace ircd::db
|
2018-05-15 01:17:43 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
static rocksdb::Iterator &_seek_(rocksdb::Iterator &, const pos &);
|
|
|
|
static rocksdb::Iterator &_seek_(rocksdb::Iterator &, const string_view &);
|
|
|
|
static rocksdb::Iterator &_seek_lower_(rocksdb::Iterator &, const string_view &);
|
|
|
|
static rocksdb::Iterator &_seek_upper_(rocksdb::Iterator &, const string_view &);
|
|
|
|
static bool _seek(database::column &, const pos &, const rocksdb::ReadOptions &, rocksdb::Iterator &it);
|
|
|
|
static bool _seek(database::column &, const string_view &, const rocksdb::ReadOptions &, rocksdb::Iterator &it);
|
2018-05-15 01:17:43 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
std::unique_ptr<rocksdb::Iterator>
|
|
|
|
ircd::db::seek(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &opts)
|
2018-05-15 01:17:43 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
|
|
|
|
std::unique_ptr<rocksdb::Iterator> ret;
|
2019-09-19 04:14:06 +02:00
|
|
|
seek(c, key, make_opts(opts), ret);
|
2019-06-23 01:04:36 +02:00
|
|
|
return ret;
|
2018-05-15 01:17:43 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
template<class pos>
|
|
|
|
bool
|
|
|
|
ircd::db::seek(database::column &c,
|
|
|
|
const pos &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> &it)
|
2018-05-15 01:17:43 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
if(!it)
|
|
|
|
{
|
2019-02-08 05:57:44 +01:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
database &d(*c.d);
|
|
|
|
rocksdb::ColumnFamilyHandle *const &cf(c);
|
|
|
|
it.reset(d.d->NewIterator(opts, cf));
|
|
|
|
}
|
2018-05-15 01:17:43 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return _seek(c, p, opts, *it);
|
2018-05-15 01:17:43 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::_seek(database::column &c,
|
|
|
|
const string_view &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
|
|
|
rocksdb::Iterator &it)
|
2020-02-27 23:49:26 +01:00
|
|
|
try
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
2019-02-08 05:57:44 +01:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
database &d(*c.d);
|
|
|
|
const ircd::timer timer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_seek_(it, p);
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
|
|
|
{
|
2019-07-24 02:21:17 +02:00
|
|
|
log, "[%s] %lu:%lu SEEK %s %s in %ld$us '%s'",
|
2019-01-29 20:13:58 +01:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
2019-07-22 01:16:30 +02:00
|
|
|
valid(it)? "VALID" : "INVALID",
|
2019-01-29 20:13:58 +01:00
|
|
|
it.status().ToString(),
|
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
name(c)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return valid(it);
|
2018-09-05 11:56:50 +02:00
|
|
|
}
|
2020-02-27 23:49:26 +01:00
|
|
|
catch(const error &e)
|
|
|
|
{
|
|
|
|
const database &d(*c.d);
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "[%s][%s] %lu:%lu SEEK key :%s",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2018-09-05 11:56:50 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::_seek(database::column &c,
|
|
|
|
const pos &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
|
|
|
rocksdb::Iterator &it)
|
2020-02-27 23:49:26 +01:00
|
|
|
try
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
2019-09-13 02:38:43 +02:00
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
database &d(*c.d);
|
|
|
|
const ircd::timer timer;
|
|
|
|
const bool valid_it
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
valid(it)
|
2018-09-05 11:56:50 +02:00
|
|
|
};
|
2019-01-29 20:13:58 +01:00
|
|
|
#endif
|
2018-09-05 11:56:50 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
_seek_(it, p);
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
2018-10-21 08:30:27 +02:00
|
|
|
{
|
2019-07-24 02:21:17 +02:00
|
|
|
log, "[%s] %lu:%lu SEEK[%s] %s -> %s in %ld$us '%s'",
|
2019-01-29 20:13:58 +01:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
|
|
|
reflect(p),
|
|
|
|
valid_it? "VALID" : "INVALID",
|
|
|
|
it.status().ToString(),
|
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
name(c)
|
2018-10-21 08:30:27 +02:00
|
|
|
};
|
2019-01-29 20:13:58 +01:00
|
|
|
#endif
|
2018-10-21 08:30:27 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid(it);
|
2018-09-05 11:56:50 +02:00
|
|
|
}
|
2020-02-27 23:49:26 +01:00
|
|
|
catch(const error &e)
|
|
|
|
{
|
|
|
|
const database &d(*c.d);
|
|
|
|
log::critical
|
|
|
|
{
|
2020-02-29 02:15:25 +01:00
|
|
|
log, "[%s][%s] %lu:%lu SEEK %s %s :%s",
|
2020-02-27 23:49:26 +01:00
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
|
|
|
reflect(p),
|
2020-02-29 02:15:25 +01:00
|
|
|
it.Valid()? "VALID" : "INVALID",
|
2020-02-27 23:49:26 +01:00
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2018-09-05 11:56:50 +02:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
/// Seek to entry NOT GREATER THAN key. That is, equal to or less than key
|
|
|
|
rocksdb::Iterator &
|
|
|
|
ircd::db::_seek_lower_(rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
it.SeekForPrev(slice(sv));
|
|
|
|
return it;
|
|
|
|
}
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
/// Seek to entry NOT LESS THAN key. That is, equal to or greater than key
|
|
|
|
rocksdb::Iterator &
|
|
|
|
ircd::db::_seek_upper_(rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
it.Seek(slice(sv));
|
|
|
|
return it;
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
/// Defaults to _seek_upper_ because it has better support from RocksDB.
|
|
|
|
rocksdb::Iterator &
|
|
|
|
ircd::db::_seek_(rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return _seek_upper_(it, sv);
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
rocksdb::Iterator &
|
|
|
|
ircd::db::_seek_(rocksdb::Iterator &it,
|
|
|
|
const pos &p)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
switch(p)
|
|
|
|
{
|
|
|
|
case pos::NEXT: it.Next(); break;
|
|
|
|
case pos::PREV: it.Prev(); break;
|
|
|
|
case pos::FRONT: it.SeekToFirst(); break;
|
|
|
|
case pos::BACK: it.SeekToLast(); break;
|
|
|
|
default:
|
|
|
|
case pos::END:
|
|
|
|
{
|
|
|
|
it.SeekToLast();
|
|
|
|
if(it.Valid())
|
|
|
|
it.Next();
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
return it;
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// validation suite
|
|
|
|
//
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::valid_eq_or_throw(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
assert(!empty(sv));
|
|
|
|
if(!valid_eq(it, sv))
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
throw_on_error(it.status());
|
|
|
|
throw not_found{};
|
|
|
|
}
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
void
|
|
|
|
ircd::db::valid_or_throw(const rocksdb::Iterator &it)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
if(!valid(it))
|
|
|
|
{
|
|
|
|
throw_on_error(it.status());
|
|
|
|
throw not_found{};
|
|
|
|
//assert(0); // status == ok + !Valid() == ???
|
|
|
|
}
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid_lte(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) <= 0;
|
|
|
|
});
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid_gt(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) > 0;
|
|
|
|
});
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid_eq(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) == 0;
|
|
|
|
});
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
2019-01-29 20:13:58 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid(const rocksdb::Iterator &it,
|
|
|
|
const valid_proffer &proffer)
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2020-10-12 01:06:20 +02:00
|
|
|
return valid(it) && proffer(it);
|
2019-01-29 20:13:58 +01:00
|
|
|
}
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
bool
|
|
|
|
ircd::db::valid(const rocksdb::Iterator &it)
|
|
|
|
{
|
2020-10-13 03:45:19 +02:00
|
|
|
if(likely(it.Valid()))
|
|
|
|
return true;
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
switch(it.status().code())
|
2018-12-24 22:32:22 +01:00
|
|
|
{
|
2019-01-29 20:13:58 +01:00
|
|
|
using rocksdb::Status;
|
2018-12-24 22:32:22 +01:00
|
|
|
|
2020-01-11 00:51:59 +01:00
|
|
|
case Status::kOk:
|
|
|
|
case Status::kNotFound:
|
|
|
|
case Status::kIncomplete:
|
2020-02-27 23:49:26 +01:00
|
|
|
return it.Valid();
|
2020-01-11 00:51:59 +01:00
|
|
|
|
2018-12-24 22:32:22 +01:00
|
|
|
default:
|
2020-01-11 00:51:59 +01:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
it.status()
|
|
|
|
};
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
__builtin_unreachable();
|
2020-06-07 04:53:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid(const rocksdb::Status &s)
|
|
|
|
{
|
|
|
|
switch(s.code())
|
|
|
|
{
|
|
|
|
using rocksdb::Status;
|
|
|
|
|
|
|
|
case Status::kOk:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Status::kNotFound:
|
|
|
|
case Status::kIncomplete:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw_on_error{s};
|
|
|
|
__builtin_unreachable();
|
2018-12-24 22:32:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// column_names
|
|
|
|
//
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::column_names(const std::string &path,
|
2017-03-31 00:57:08 +02:00
|
|
|
const std::string &options)
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2019-06-24 07:06:50 +02:00
|
|
|
const rocksdb::DBOptions opts
|
|
|
|
{
|
|
|
|
db::options(options)
|
|
|
|
};
|
|
|
|
|
|
|
|
return column_names(path, opts);
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 03:41:37 +01:00
|
|
|
/// Note that if there is no database found at path we still return a
|
|
|
|
/// vector containing the column name "default". This function is not
|
|
|
|
/// to be used as a test for whether the database exists. It returns
|
|
|
|
/// the columns required to be described at `path`. That will always
|
|
|
|
/// include the default column (RocksDB sez) even if database doesn't
|
|
|
|
/// exist yet.
|
2017-03-24 02:36:49 +01:00
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::column_names(const std::string &path,
|
|
|
|
const rocksdb::DBOptions &opts)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::vector<std::string> ret;
|
2018-12-16 03:41:37 +01:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::DB::ListColumnFamilies(opts, path, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2018-12-16 03:41:37 +01:00
|
|
|
catch(const not_found &)
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-12-16 03:41:37 +01:00
|
|
|
return // No database found at path.
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
{ rocksdb::kDefaultColumnFamilyName }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-16 18:41:10 +02:00
|
|
|
//
|
|
|
|
// Misc
|
|
|
|
//
|
|
|
|
|
2020-09-20 21:43:26 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
extern conf::item<std::string> compression_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::db::compression_default)
|
|
|
|
ircd::db::compression_default
|
|
|
|
{
|
2020-09-20 21:48:03 +02:00
|
|
|
{ "name", "ircd.db.compression.default" },
|
|
|
|
{ "default", "kZSTD;kLZ4Compression;kSnappyCompression" },
|
2020-09-20 21:43:26 +02:00
|
|
|
};
|
|
|
|
|
2018-11-03 02:08:40 +01:00
|
|
|
rocksdb::CompressionType
|
2020-09-20 21:43:26 +02:00
|
|
|
ircd::db::find_supported_compression(const std::string &input)
|
2018-11-03 02:08:40 +01:00
|
|
|
{
|
|
|
|
rocksdb::CompressionType ret
|
|
|
|
{
|
|
|
|
rocksdb::kNoCompression
|
|
|
|
};
|
|
|
|
|
2020-09-20 21:43:26 +02:00
|
|
|
const auto &list
|
|
|
|
{
|
|
|
|
input == "default"?
|
|
|
|
string_view{compression_default}:
|
|
|
|
string_view{input}
|
|
|
|
};
|
|
|
|
|
2018-11-03 02:08:40 +01:00
|
|
|
tokens(list, ';', [&ret]
|
2019-06-02 10:03:28 +02:00
|
|
|
(const string_view &requested)
|
2018-11-03 02:08:40 +01:00
|
|
|
{
|
2018-12-01 00:07:51 +01:00
|
|
|
if(ret != rocksdb::kNoCompression)
|
|
|
|
return;
|
|
|
|
|
2019-06-02 10:03:28 +02:00
|
|
|
for(const auto &[name, type] : db::compressions)
|
|
|
|
if(type != 0L && name == requested)
|
|
|
|
{
|
|
|
|
ret = rocksdb::CompressionType(type);
|
|
|
|
break;
|
|
|
|
}
|
2018-11-03 02:08:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
rocksdb::DBOptions
|
2018-04-09 20:51:36 +02:00
|
|
|
ircd::db::make_dbopts(std::string optstr,
|
|
|
|
std::string *const &out,
|
2017-09-19 04:17:36 +02:00
|
|
|
bool *const read_only,
|
|
|
|
bool *const fsck)
|
|
|
|
{
|
|
|
|
// RocksDB doesn't parse a read_only option, so we allow that to be added
|
|
|
|
// to open the database as read_only and then remove that from the string.
|
|
|
|
if(read_only)
|
2019-04-15 20:08:40 +02:00
|
|
|
*read_only |= optstr_find_and_remove(optstr, "read_only=true;"s);
|
2018-04-09 20:51:36 +02:00
|
|
|
else
|
|
|
|
optstr_find_and_remove(optstr, "read_only=true;"s);
|
2017-09-19 04:17:36 +02:00
|
|
|
|
|
|
|
// We also allow the user to specify fsck=true to run a repair operation on
|
|
|
|
// the db. This may be expensive to do by default every startup.
|
|
|
|
if(fsck)
|
2019-04-15 20:08:40 +02:00
|
|
|
*fsck |= optstr_find_and_remove(optstr, "fsck=true;"s);
|
2018-04-09 20:51:36 +02:00
|
|
|
else
|
|
|
|
optstr_find_and_remove(optstr, "fsck=true;"s);
|
2017-09-19 04:17:36 +02:00
|
|
|
|
|
|
|
// Generate RocksDB options from string
|
|
|
|
rocksdb::DBOptions opts
|
|
|
|
{
|
2018-12-12 18:53:16 +01:00
|
|
|
db::options(optstr)
|
2017-09-19 04:17:36 +02:00
|
|
|
};
|
|
|
|
|
2018-04-09 20:51:36 +02:00
|
|
|
if(out)
|
|
|
|
*out = std::move(optstr);
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
bool
|
|
|
|
ircd::db::optstr_find_and_remove(std::string &optstr,
|
|
|
|
const std::string &what)
|
|
|
|
{
|
|
|
|
const auto pos(optstr.find(what));
|
|
|
|
if(pos == std::string::npos)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
optstr.erase(pos, what.size());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
decltype(ircd::db::read_checksum)
|
|
|
|
ircd::db::read_checksum
|
|
|
|
{
|
|
|
|
{ "name", "ircd.db.read.checksum" },
|
|
|
|
{ "default", false }
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
static const rocksdb::ReadOptions default_read_options;
|
|
|
|
}
|
|
|
|
|
2018-11-16 05:54:50 +01:00
|
|
|
/// Convert our options structure into RocksDB's options structure.
|
2016-09-25 03:18:54 +02:00
|
|
|
rocksdb::ReadOptions
|
2017-09-22 05:08:11 +02:00
|
|
|
ircd::db::make_opts(const gopts &opts)
|
2016-09-25 03:18:54 +02:00
|
|
|
{
|
|
|
|
rocksdb::ReadOptions ret;
|
2020-10-12 22:47:52 +02:00
|
|
|
assume(ret.iterate_lower_bound == nullptr);
|
|
|
|
assume(ret.iterate_upper_bound == nullptr);
|
|
|
|
assume(ret.iter_start_seqnum == 0);
|
|
|
|
assume(ret.pin_data == false);
|
|
|
|
assume(ret.fill_cache == true);
|
|
|
|
assume(ret.total_order_seek == false);
|
|
|
|
assume(ret.verify_checksums == true);
|
|
|
|
assume(ret.tailing == false);
|
|
|
|
assume(ret.read_tier == rocksdb::ReadTier::kReadAllTier);
|
|
|
|
assume(ret.readahead_size == 0);
|
|
|
|
assume(ret.prefix_same_as_start == false);
|
|
|
|
|
|
|
|
ret.snapshot = opts.snapshot;
|
|
|
|
ret.readahead_size = opts.readahead;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
// slice* for exclusive upper bound. when prefixes are used this value must
|
|
|
|
// have the same prefix because ordering is not guaranteed between prefixes
|
2018-04-14 07:08:57 +02:00
|
|
|
ret.iterate_lower_bound = opts.lower_bound;
|
|
|
|
ret.iterate_upper_bound = opts.upper_bound;
|
2020-10-12 22:47:52 +02:00
|
|
|
ret.iter_start_seqnum = opts.seqnum;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
ret.verify_checksums = bool(read_checksum);
|
|
|
|
if(test(opts, get::CHECKSUM) & !test(opts, get::NO_CHECKSUM))
|
|
|
|
ret.verify_checksums = true;
|
2017-08-31 07:12:58 +02:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(test(opts, get::NO_SNAPSHOT))
|
|
|
|
ret.tailing = true;
|
2018-05-24 03:43:47 +02:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(test(opts, get::ORDERED))
|
|
|
|
ret.total_order_seek = true;
|
2018-11-16 05:54:50 +01:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(test(opts, get::PIN))
|
|
|
|
ret.pin_data = true;
|
2018-11-16 05:54:50 +01:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(test(opts, get::CACHE))
|
|
|
|
ret.fill_cache = true;
|
2018-12-28 19:55:57 +01:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(likely(test(opts, get::NO_CACHE)))
|
|
|
|
ret.fill_cache = false;
|
2018-11-16 05:54:50 +01:00
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
if(likely(test(opts, get::PREFIX)))
|
|
|
|
ret.prefix_same_as_start = true;
|
|
|
|
|
|
|
|
if(likely(test(opts, get::NO_BLOCKING)))
|
|
|
|
ret.read_tier = rocksdb::ReadTier::kBlockCacheTier;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2020-09-15 10:53:30 +02:00
|
|
|
decltype(ircd::db::enable_wal)
|
|
|
|
ircd::db::enable_wal
|
|
|
|
{
|
|
|
|
{ "name", "ircd.db.wal.enable" },
|
|
|
|
{ "default", true },
|
|
|
|
{ "persist", false },
|
|
|
|
};
|
|
|
|
|
2020-10-12 22:47:52 +02:00
|
|
|
rocksdb::WriteOptions
|
|
|
|
ircd::db::make_opts(const sopts &opts)
|
2017-09-22 05:08:11 +02:00
|
|
|
{
|
2020-10-12 22:47:52 +02:00
|
|
|
rocksdb::WriteOptions ret;
|
|
|
|
//ret.no_slowdown = true; // read_tier = NON_BLOCKING for writes
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
ret.sync = test(opts, set::FSYNC);
|
2020-09-15 10:53:30 +02:00
|
|
|
ret.disableWAL = !enable_wal || test(opts, set::NO_JOURNAL);
|
2018-12-28 19:55:57 +01:00
|
|
|
ret.ignore_missing_column_families = test(opts, set::NO_COLUMN_ERR);
|
|
|
|
ret.no_slowdown = test(opts, set::NO_BLOCKING);
|
|
|
|
ret.low_pri = test(opts, set::PRIO_LOW);
|
2016-09-25 03:18:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:02:12 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::available()
|
|
|
|
{
|
2020-04-19 09:26:54 +02:00
|
|
|
const string_view &prefix
|
2018-05-25 05:01:52 +02:00
|
|
|
{
|
2020-04-19 09:26:54 +02:00
|
|
|
fs::base::db
|
2018-05-25 05:01:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto dirs
|
|
|
|
{
|
|
|
|
fs::ls(prefix)
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
for(const auto &dir : dirs)
|
|
|
|
{
|
2018-09-04 11:28:04 +02:00
|
|
|
if(!fs::is_dir(dir))
|
|
|
|
continue;
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
const auto name
|
|
|
|
{
|
|
|
|
lstrip(dir, prefix)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto checkpoints
|
|
|
|
{
|
|
|
|
fs::ls(dir)
|
|
|
|
};
|
|
|
|
|
2020-07-11 05:19:18 +02:00
|
|
|
for(const auto &cpdir : checkpoints) try
|
2018-05-25 05:01:52 +02:00
|
|
|
{
|
|
|
|
const auto checkpoint
|
|
|
|
{
|
|
|
|
lstrip(lstrip(cpdir, dir), '/') //TODO: x-platform
|
|
|
|
};
|
|
|
|
|
|
|
|
auto path
|
|
|
|
{
|
|
|
|
db::path(name, lex_cast<uint64_t>(checkpoint))
|
|
|
|
};
|
|
|
|
|
|
|
|
ret.emplace_back(std::move(path));
|
|
|
|
}
|
|
|
|
catch(const bad_lex_cast &e)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::path(const string_view &name)
|
|
|
|
{
|
|
|
|
const auto pair
|
|
|
|
{
|
|
|
|
namepoint(name)
|
|
|
|
};
|
|
|
|
|
|
|
|
return path(pair.first, pair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::path(const string_view &name,
|
|
|
|
const uint64_t &checkpoint)
|
|
|
|
{
|
2018-12-30 00:27:58 +01:00
|
|
|
const auto &prefix
|
2018-05-25 05:01:52 +02:00
|
|
|
{
|
2020-04-19 09:26:54 +02:00
|
|
|
fs::base::db
|
2018-05-25 05:01:52 +02:00
|
|
|
};
|
|
|
|
|
2018-09-13 14:43:30 +02:00
|
|
|
const string_view parts[]
|
2018-05-25 05:01:52 +02:00
|
|
|
{
|
|
|
|
prefix, name, lex_cast(checkpoint)
|
2018-09-13 14:43:30 +02:00
|
|
|
};
|
|
|
|
|
2019-02-08 05:56:48 +01:00
|
|
|
return fs::path_string(parts);
|
2018-05-25 05:01:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<ircd::string_view, uint64_t>
|
|
|
|
ircd::db::namepoint(const string_view &name_)
|
|
|
|
{
|
|
|
|
const auto s
|
|
|
|
{
|
|
|
|
split(name_, ':')
|
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
s.first,
|
|
|
|
s.second? lex_cast<uint64_t>(s.second) : uint64_t(-1)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-26 06:07:22 +02:00
|
|
|
std::string
|
2018-05-25 05:01:52 +02:00
|
|
|
ircd::db::namepoint(const string_view &name,
|
|
|
|
const uint64_t &checkpoint)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
return std::string{name} + ':' + std::string{lex_cast(checkpoint)};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 04:03:04 +02:00
|
|
|
//
|
|
|
|
// Iterator
|
|
|
|
//
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
std::pair<ircd::string_view, ircd::string_view>
|
|
|
|
ircd::db::operator*(const rocksdb::Iterator &it)
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return { key(it), val(it) };
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::key(const rocksdb::Iterator &it)
|
|
|
|
{
|
|
|
|
return slice(it.key());
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::val(const rocksdb::Iterator &it)
|
|
|
|
{
|
|
|
|
return slice(it.value());
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
2020-06-19 04:03:04 +02:00
|
|
|
// PinnableSlice
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
|
2020-06-19 04:03:04 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::size(const rocksdb::PinnableSlice &ps)
|
|
|
|
{
|
|
|
|
return size(static_cast<const rocksdb::Slice &>(ps));
|
|
|
|
}
|
|
|
|
|
2018-01-18 05:28:34 +01:00
|
|
|
const char *
|
2020-06-19 04:03:04 +02:00
|
|
|
ircd::db::data(const rocksdb::PinnableSlice &ps)
|
2018-01-18 05:28:34 +01:00
|
|
|
{
|
2020-06-19 04:03:04 +02:00
|
|
|
return data(static_cast<const rocksdb::Slice &>(ps));
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::slice(const rocksdb::PinnableSlice &ps)
|
|
|
|
{
|
|
|
|
return slice(static_cast<const rocksdb::Slice &>(ps));
|
2018-01-18 05:28:34 +01:00
|
|
|
}
|
|
|
|
|
2020-06-19 04:03:04 +02:00
|
|
|
//
|
|
|
|
// Slice
|
|
|
|
//
|
|
|
|
|
2018-01-18 05:15:13 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::size(const rocksdb::Slice &slice)
|
|
|
|
{
|
|
|
|
return slice.size();
|
|
|
|
}
|
|
|
|
|
2020-06-19 04:03:04 +02:00
|
|
|
const char *
|
|
|
|
ircd::db::data(const rocksdb::Slice &slice)
|
|
|
|
{
|
|
|
|
return slice.data();
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
rocksdb::Slice
|
|
|
|
ircd::db::slice(const string_view &sv)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-03-31 00:57:08 +02:00
|
|
|
return { sv.data(), sv.size() };
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
2017-03-23 22:58:24 +01:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::slice(const rocksdb::Slice &sk)
|
|
|
|
{
|
|
|
|
return { sk.data(), sk.size() };
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:13:58 +01:00
|
|
|
//
|
|
|
|
// reflect
|
|
|
|
//
|
|
|
|
|
2017-03-23 22:58:24 +01:00
|
|
|
const std::string &
|
|
|
|
ircd::db::reflect(const rocksdb::Tickers &type)
|
|
|
|
{
|
|
|
|
const auto &names(rocksdb::TickersNameMap);
|
|
|
|
const auto it(std::find_if(begin(names), end(names), [&type]
|
|
|
|
(const auto &pair)
|
|
|
|
{
|
|
|
|
return pair.first == type;
|
|
|
|
}));
|
|
|
|
|
|
|
|
static const auto empty{"<ticker>?????"s};
|
|
|
|
return it != end(names)? it->second : empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &
|
|
|
|
ircd::db::reflect(const rocksdb::Histograms &type)
|
|
|
|
{
|
|
|
|
const auto &names(rocksdb::HistogramsNameMap);
|
|
|
|
const auto it(std::find_if(begin(names), end(names), [&type]
|
|
|
|
(const auto &pair)
|
|
|
|
{
|
|
|
|
return pair.first == type;
|
|
|
|
}));
|
|
|
|
|
|
|
|
static const auto empty{"<histogram>?????"s};
|
|
|
|
return it != end(names)? it->second : empty;
|
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2017-09-16 20:51:52 +02:00
|
|
|
ircd::string_view
|
2017-08-30 23:06:34 +02:00
|
|
|
ircd::db::reflect(const pos &pos)
|
|
|
|
{
|
|
|
|
switch(pos)
|
|
|
|
{
|
2017-09-19 04:17:36 +02:00
|
|
|
case pos::NEXT: return "NEXT";
|
|
|
|
case pos::PREV: return "PREV";
|
|
|
|
case pos::FRONT: return "FRONT";
|
|
|
|
case pos::BACK: return "BACK";
|
|
|
|
case pos::END: return "END";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "?????";
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const op &op)
|
|
|
|
{
|
|
|
|
switch(op)
|
|
|
|
{
|
|
|
|
case op::GET: return "GET";
|
|
|
|
case op::SET: return "SET";
|
|
|
|
case op::MERGE: return "MERGE";
|
|
|
|
case op::DELETE_RANGE: return "DELETE_RANGE";
|
|
|
|
case op::DELETE: return "DELETE";
|
|
|
|
case op::SINGLE_DELETE: return "SINGLE_DELETE";
|
2017-08-30 23:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
return "?????";
|
2017-08-30 23:06:34 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 22:40:00 +01:00
|
|
|
ircd::string_view
|
2018-12-19 22:39:06 +01:00
|
|
|
ircd::db::reflect(const rocksdb::FlushReason &r)
|
2018-10-31 22:40:00 +01:00
|
|
|
{
|
2018-12-19 22:39:06 +01:00
|
|
|
using FlushReason = rocksdb::FlushReason;
|
2018-10-31 22:40:00 +01:00
|
|
|
|
2018-12-19 22:39:06 +01:00
|
|
|
switch(r)
|
2018-10-31 22:40:00 +01:00
|
|
|
{
|
2018-12-19 22:39:06 +01:00
|
|
|
case FlushReason::kOthers: return "Others";
|
|
|
|
case FlushReason::kGetLiveFiles: return "GetLiveFiles";
|
|
|
|
case FlushReason::kShutDown: return "ShutDown";
|
|
|
|
case FlushReason::kExternalFileIngestion: return "ExternalFileIngestion";
|
|
|
|
case FlushReason::kManualCompaction: return "ManualCompaction";
|
|
|
|
case FlushReason::kWriteBufferManager: return "WriteBufferManager";
|
|
|
|
case FlushReason::kWriteBufferFull: return "WriteBufferFull";
|
|
|
|
case FlushReason::kTest: return "Test";
|
|
|
|
case FlushReason::kDeleteFiles: return "DeleteFiles";
|
|
|
|
case FlushReason::kAutoCompaction: return "AutoCompaction";
|
|
|
|
case FlushReason::kManualFlush: return "ManualFlush";
|
2020-05-05 05:40:52 +02:00
|
|
|
case FlushReason::kErrorRecovery: return "kErrorRecovery";
|
2018-12-19 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::CompactionReason &r)
|
|
|
|
{
|
|
|
|
using CompactionReason = rocksdb::CompactionReason;
|
|
|
|
|
|
|
|
switch(r)
|
|
|
|
{
|
|
|
|
case CompactionReason::kUnknown: return "Unknown";
|
|
|
|
case CompactionReason::kLevelL0FilesNum: return "LevelL0FilesNum";
|
|
|
|
case CompactionReason::kLevelMaxLevelSize: return "LevelMaxLevelSize";
|
|
|
|
case CompactionReason::kUniversalSizeAmplification: return "UniversalSizeAmplification";
|
|
|
|
case CompactionReason::kUniversalSizeRatio: return "UniversalSizeRatio";
|
|
|
|
case CompactionReason::kUniversalSortedRunNum: return "UniversalSortedRunNum";
|
|
|
|
case CompactionReason::kFIFOMaxSize: return "FIFOMaxSize";
|
|
|
|
case CompactionReason::kFIFOReduceNumFiles: return "FIFOReduceNumFiles";
|
|
|
|
case CompactionReason::kFIFOTtl: return "FIFOTtl";
|
|
|
|
case CompactionReason::kManualCompaction: return "ManualCompaction";
|
|
|
|
case CompactionReason::kFilesMarkedForCompaction: return "FilesMarkedForCompaction";
|
|
|
|
case CompactionReason::kBottommostFiles: return "BottommostFiles";
|
|
|
|
case CompactionReason::kTtl: return "Ttl";
|
|
|
|
case CompactionReason::kFlush: return "Flush";
|
|
|
|
case CompactionReason::kExternalSstIngestion: return "ExternalSstIngestion";
|
2020-05-05 05:54:12 +02:00
|
|
|
|
2020-06-07 14:30:17 +02:00
|
|
|
#ifdef IRCD_DB_HAS_PERIODIC_COMPACTIONS
|
2020-05-05 05:54:12 +02:00
|
|
|
case CompactionReason::kPeriodicCompaction: return "kPeriodicCompaction";
|
|
|
|
#endif
|
|
|
|
|
2018-12-19 22:39:06 +01:00
|
|
|
case CompactionReason::kNumOfReasons:
|
|
|
|
break;
|
2018-10-31 22:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::BackgroundErrorReason &r)
|
|
|
|
{
|
|
|
|
using rocksdb::BackgroundErrorReason;
|
|
|
|
|
|
|
|
switch(r)
|
|
|
|
{
|
|
|
|
case BackgroundErrorReason::kFlush: return "FLUSH";
|
|
|
|
case BackgroundErrorReason::kCompaction: return "COMPACTION";
|
|
|
|
case BackgroundErrorReason::kWriteCallback: return "WRITE";
|
|
|
|
case BackgroundErrorReason::kMemTable: return "MEMTABLE";
|
2020-07-25 18:10:49 +02:00
|
|
|
#if 0 // unreleased
|
|
|
|
case BackgroundErrorReason::kManifestWrite: return "MANIFESTWRITE";
|
|
|
|
#endif
|
2018-10-31 22:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|
|
|
|
|
2018-12-19 22:39:06 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::WriteStallCondition &c)
|
|
|
|
{
|
|
|
|
using rocksdb::WriteStallCondition;
|
|
|
|
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case WriteStallCondition::kNormal: return "NORMAL";
|
|
|
|
case WriteStallCondition::kDelayed: return "DELAYED";
|
|
|
|
case WriteStallCondition::kStopped: return "STOPPED";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::Env::Priority &p)
|
|
|
|
{
|
|
|
|
switch(p)
|
|
|
|
{
|
2018-04-09 21:55:22 +02:00
|
|
|
case rocksdb::Env::Priority::BOTTOM: return "BOTTOM"_sv;
|
2018-01-18 04:22:35 +01:00
|
|
|
case rocksdb::Env::Priority::LOW: return "LOW"_sv;
|
|
|
|
case rocksdb::Env::Priority::HIGH: return "HIGH"_sv;
|
2020-05-05 05:54:46 +02:00
|
|
|
#ifdef IRCD_DB_HAS_ENV_PRIO_USER
|
|
|
|
case rocksdb::Env::Priority::USER: return "USER"_sv;
|
|
|
|
#endif
|
2018-08-16 11:04:16 +02:00
|
|
|
case rocksdb::Env::Priority::TOTAL: assert(0); break;
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "????"_sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::Env::IOPriority &p)
|
|
|
|
{
|
|
|
|
switch(p)
|
|
|
|
{
|
|
|
|
case rocksdb::Env::IOPriority::IO_LOW: return "IO_LOW"_sv;
|
|
|
|
case rocksdb::Env::IOPriority::IO_HIGH: return "IO_HIGH"_sv;
|
2020-09-15 03:59:55 +02:00
|
|
|
case rocksdb::Env::IOPriority::IO_TOTAL: break;
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "IO_????"_sv;
|
|
|
|
}
|
|
|
|
|
2018-11-02 09:07:09 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::Env::WriteLifeTimeHint &h)
|
|
|
|
{
|
|
|
|
using WriteLifeTimeHint = rocksdb::Env::WriteLifeTimeHint;
|
|
|
|
|
|
|
|
switch(h)
|
|
|
|
{
|
|
|
|
case WriteLifeTimeHint::WLTH_NOT_SET: return "NOT_SET";
|
|
|
|
case WriteLifeTimeHint::WLTH_NONE: return "NONE";
|
|
|
|
case WriteLifeTimeHint::WLTH_SHORT: return "SHORT";
|
|
|
|
case WriteLifeTimeHint::WLTH_MEDIUM: return "MEDIUM";
|
|
|
|
case WriteLifeTimeHint::WLTH_LONG: return "LONG";
|
|
|
|
case WriteLifeTimeHint::WLTH_EXTREME: return "EXTREME";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "WLTH_????"_sv;
|
|
|
|
}
|
|
|
|
|
2018-10-31 22:48:14 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::Status::Severity &s)
|
|
|
|
{
|
|
|
|
using Severity = rocksdb::Status::Severity;
|
|
|
|
|
|
|
|
switch(s)
|
|
|
|
{
|
|
|
|
case Severity::kNoError: return "NONE";
|
|
|
|
case Severity::kSoftError: return "SOFT";
|
|
|
|
case Severity::kHardError: return "HARD";
|
|
|
|
case Severity::kFatalError: return "FATAL";
|
|
|
|
case Severity::kUnrecoverableError: return "UNRECOVERABLE";
|
|
|
|
case Severity::kMaxSeverity: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "?????";
|
|
|
|
}
|
|
|
|
|
2020-02-27 23:46:28 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::Status::Code &s)
|
|
|
|
{
|
|
|
|
using Code = rocksdb::Status::Code;
|
|
|
|
|
|
|
|
switch(s)
|
|
|
|
{
|
|
|
|
case Code::kOk: return "Ok";
|
|
|
|
case Code::kNotFound: return "NotFound";
|
|
|
|
case Code::kCorruption: return "Corruption";
|
|
|
|
case Code::kNotSupported: return "NotSupported";
|
|
|
|
case Code::kInvalidArgument: return "InvalidArgument";
|
|
|
|
case Code::kIOError: return "IOError";
|
|
|
|
case Code::kMergeInProgress: return "MergeInProgress";
|
|
|
|
case Code::kIncomplete: return "Incomplete";
|
|
|
|
case Code::kShutdownInProgress: return "ShutdownInProgress";
|
|
|
|
case Code::kTimedOut: return "TimedOut";
|
|
|
|
case Code::kAborted: return "Aborted";
|
|
|
|
case Code::kBusy: return "Busy";
|
|
|
|
case Code::kExpired: return "Expired";
|
|
|
|
case Code::kTryAgain: return "TryAgain";
|
|
|
|
case Code::kCompactionTooLarge: return "CompactionTooLarge";
|
2020-05-05 05:59:40 +02:00
|
|
|
|
|
|
|
#if ROCKSDB_MAJOR > 6 \
|
|
|
|
|| (ROCKSDB_MAJOR == 6 && ROCKSDB_MINOR > 3) \
|
|
|
|
|| (ROCKSDB_MAJOR == 6 && ROCKSDB_MINOR == 3 && ROCKSDB_PATCH >= 6)
|
|
|
|
case Code::kColumnFamilyDropped: return "ColumnFamilyDropped";
|
|
|
|
case Code::kMaxCode: break;
|
|
|
|
#endif
|
2020-02-27 23:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "?????";
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:24:32 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::reflect(const rocksdb::RandomAccessFile::AccessPattern &p)
|
|
|
|
{
|
|
|
|
switch(p)
|
|
|
|
{
|
|
|
|
case rocksdb::RandomAccessFile::AccessPattern::NORMAL: return "NORMAL"_sv;
|
|
|
|
case rocksdb::RandomAccessFile::AccessPattern::RANDOM: return "RANDOM"_sv;
|
|
|
|
case rocksdb::RandomAccessFile::AccessPattern::SEQUENTIAL: return "SEQUENTIAL"_sv;
|
|
|
|
case rocksdb::RandomAccessFile::AccessPattern::WILLNEED: return "WILLNEED"_sv;
|
|
|
|
case rocksdb::RandomAccessFile::AccessPattern::DONTNEED: return "DONTNEED"_sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "??????"_sv;
|
|
|
|
}
|