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
|
|
|
|
2017-08-23 23:37:06 +02:00
|
|
|
#include <rocksdb/version.h>
|
2018-08-23 13:19:32 +02:00
|
|
|
#include <rocksdb/status.h>
|
2016-09-24 06:01:57 +02:00
|
|
|
#include <rocksdb/db.h>
|
2016-09-26 06:07:22 +02:00
|
|
|
#include <rocksdb/cache.h>
|
2017-03-31 00:57:08 +02:00
|
|
|
#include <rocksdb/comparator.h>
|
2017-03-23 22:58:24 +01:00
|
|
|
#include <rocksdb/merge_operator.h>
|
|
|
|
#include <rocksdb/perf_level.h>
|
2017-04-03 06:02:32 +02:00
|
|
|
#include <rocksdb/perf_context.h>
|
2018-05-24 02:03:09 +02:00
|
|
|
#include <rocksdb/iostats_context.h>
|
2017-03-23 22:58:24 +01:00
|
|
|
#include <rocksdb/listener.h>
|
|
|
|
#include <rocksdb/statistics.h>
|
2017-03-24 00:10:17 +01:00
|
|
|
#include <rocksdb/convenience.h>
|
|
|
|
#include <rocksdb/env.h>
|
2017-08-31 07:12:58 +02:00
|
|
|
#include <rocksdb/slice_transform.h>
|
2018-03-23 03:56:08 +01:00
|
|
|
#include <rocksdb/utilities/checkpoint.h>
|
2018-04-15 08:00:56 +02:00
|
|
|
#include <rocksdb/filter_policy.h>
|
|
|
|
#include <rocksdb/table.h>
|
2018-04-21 00:45:57 +02:00
|
|
|
#include <rocksdb/sst_file_manager.h>
|
2018-09-22 02:12:50 +02:00
|
|
|
#include <rocksdb/sst_dump_tool.h>
|
2018-09-19 00:07:09 +02:00
|
|
|
#include <rocksdb/compaction_filter.h>
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
// ircd::db interfaces requiring complete RocksDB (frontside).
|
2018-01-18 03:34:20 +01:00
|
|
|
#include <ircd/db/database/comparator.h>
|
|
|
|
#include <ircd/db/database/prefix_transform.h>
|
2018-09-19 00:07:09 +02:00
|
|
|
#include <ircd/db/database/compaction_filter.h>
|
2018-01-18 03:34:20 +01:00
|
|
|
#include <ircd/db/database/mergeop.h>
|
|
|
|
#include <ircd/db/database/events.h>
|
|
|
|
#include <ircd/db/database/stats.h>
|
|
|
|
#include <ircd/db/database/logs.h>
|
|
|
|
#include <ircd/db/database/column.h>
|
2018-03-23 04:47:46 +01:00
|
|
|
#include <ircd/db/database/txn.h>
|
2018-09-03 02:29:44 +02:00
|
|
|
#include <ircd/db/database/cache.h>
|
2018-05-30 09:14:07 +02:00
|
|
|
|
|
|
|
// RocksDB embedding environment callback interfaces (backside).
|
2018-01-19 02:59:22 +01:00
|
|
|
#include <ircd/db/database/env/env.h>
|
|
|
|
#include <ircd/db/database/env/writable_file.h>
|
|
|
|
#include <ircd/db/database/env/sequential_file.h>
|
|
|
|
#include <ircd/db/database/env/random_access_file.h>
|
|
|
|
#include <ircd/db/database/env/random_rw_file.h>
|
|
|
|
#include <ircd/db/database/env/directory.h>
|
|
|
|
#include <ircd/db/database/env/file_lock.h>
|
2018-06-09 22:40:21 +02:00
|
|
|
#include <ircd/db/database/env/state.h>
|
|
|
|
|
2018-09-25 06:34:08 +02:00
|
|
|
// Internal utility interface for this definition file.
|
|
|
|
#include "db.h"
|
2018-01-18 03:34:20 +01:00
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
// RocksDB port linktime-overriding interfaces (experimental).
|
|
|
|
#ifdef IRCD_DB_PORT
|
|
|
|
#include <ircd/db/database/env/port.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Misc / General linkages
|
|
|
|
//
|
|
|
|
|
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
|
|
|
{
|
2018-01-24 00:39:44 +01:00
|
|
|
"rdb", 'R'
|
|
|
|
};
|
2017-09-30 08:07:55 +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" },
|
|
|
|
{ "default", 32L },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
request.set(size_t(request_pool_size));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
"db req",
|
2018-08-22 23:08:27 +02:00
|
|
|
size_t(request_pool_stack_size),
|
|
|
|
0, // don't prespawn because this is static
|
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
|
|
|
|
//
|
|
|
|
|
2017-09-08 11:09:34 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
2018-09-04 11:09:49 +02:00
|
|
|
static std::string direct_io_test_file_path();
|
|
|
|
static void init_test_direct_io();
|
2018-06-12 09:24:59 +02:00
|
|
|
static void init_compressions();
|
2017-09-08 11:09:34 +02:00
|
|
|
static void init_directory();
|
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2018-11-02 04:14:00 +01:00
|
|
|
decltype(ircd::db::version)
|
|
|
|
ircd::db::version
|
2018-09-04 06:43:31 +02:00
|
|
|
{
|
2018-11-02 04:14:00 +01:00
|
|
|
ROCKSDB_MAJOR,
|
|
|
|
ROCKSDB_MINOR,
|
|
|
|
ROCKSDB_PATCH
|
|
|
|
};
|
|
|
|
|
|
|
|
char ircd_db_version_str_buf[64];
|
|
|
|
decltype(ircd::db::version_str)
|
|
|
|
ircd::db::version_str
|
|
|
|
(
|
|
|
|
ircd_db_version_str_buf,
|
|
|
|
::snprintf(ircd_db_version_str_buf, sizeof(ircd_db_version_str_buf),
|
|
|
|
"%u.%u.%u",
|
|
|
|
version[0],
|
|
|
|
version[1],
|
|
|
|
version[2])
|
|
|
|
);
|
2018-09-04 06:43:31 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// init::init
|
|
|
|
//
|
|
|
|
|
2018-06-12 09:24:59 +02:00
|
|
|
ircd::db::init::init()
|
|
|
|
{
|
|
|
|
init_compressions();
|
|
|
|
init_directory();
|
2018-09-04 11:09:49 +02:00
|
|
|
init_test_direct_io();
|
2018-08-22 23:08:27 +02:00
|
|
|
request.add(request_pool_size);
|
2018-06-12 09:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::init::~init()
|
|
|
|
noexcept
|
2017-08-23 23:37:06 +02:00
|
|
|
{
|
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."
|
|
|
|
};
|
2017-08-23 23:37:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 09:24:59 +02:00
|
|
|
void
|
2017-08-23 22:37:47 +02:00
|
|
|
ircd::db::init_directory()
|
|
|
|
try
|
|
|
|
{
|
2018-04-03 02:18:02 +02:00
|
|
|
const auto dbdir
|
|
|
|
{
|
|
|
|
fs::get(fs::DB)
|
|
|
|
};
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
2018-08-16 10:27:43 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Cannot start database system: %s", e.what()
|
|
|
|
};
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
if(ircd::debugmode)
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:09:49 +02:00
|
|
|
void
|
|
|
|
ircd::db::init_test_direct_io()
|
|
|
|
try
|
|
|
|
{
|
2018-09-13 14:43:30 +02:00
|
|
|
const auto test_file_path
|
|
|
|
{
|
|
|
|
direct_io_test_file_path()
|
|
|
|
};
|
|
|
|
|
|
|
|
if(fs::direct_io_support(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.",
|
|
|
|
fs::get(fs::DB)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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",
|
|
|
|
direct_io_test_file_path(),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::direct_io_test_file_path()
|
|
|
|
{
|
|
|
|
const auto dbdir
|
|
|
|
{
|
|
|
|
fs::get(fs::DB)
|
|
|
|
};
|
|
|
|
|
2018-09-13 14:43:30 +02:00
|
|
|
const std::string parts[]
|
|
|
|
{
|
|
|
|
dbdir, "SUPPORTS_DIRECT_IO"s
|
|
|
|
};
|
|
|
|
|
|
|
|
return fs::make_path(parts);
|
2018-09-04 11:09:49 +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
|
|
|
|
ircd::db::init_compressions()
|
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()
|
|
|
|
};
|
|
|
|
|
2018-11-03 02:02:27 +01:00
|
|
|
for(const rocksdb::CompressionType &type : supported)
|
|
|
|
{
|
|
|
|
auto &string(compressions.at(uint(type)));
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetStringFromCompressionType(&string, type)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database
|
|
|
|
//
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
void
|
|
|
|
ircd::db::sync(database &d)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': @%lu SYNC WAL",
|
|
|
|
name(d),
|
|
|
|
sequence(d)
|
|
|
|
};
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->SyncWAL()
|
|
|
|
};
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
|
2018-03-23 03:41:50 +01:00
|
|
|
/// Flushes all columns. Note that if blocking=true, blocking may occur for
|
|
|
|
/// each column individually.
|
|
|
|
void
|
|
|
|
ircd::db::flush(database &d,
|
2018-04-27 02:19:29 +02:00
|
|
|
const bool &sync)
|
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': @%lu FLUSH WAL",
|
|
|
|
name(d),
|
|
|
|
sequence(d)
|
|
|
|
};
|
|
|
|
|
2018-04-27 02:19:29 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->FlushWAL(sync)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Moves memory structures to SST files for all columns. This doesn't
|
|
|
|
/// necessarily sort anything that wasn't previously sorted, but it may create
|
|
|
|
/// new SST files and shouldn't be confused with a typical fflush().
|
|
|
|
/// Note that if blocking=true, blocking may occur for each column individually.
|
|
|
|
void
|
|
|
|
ircd::db::sort(database &d,
|
|
|
|
const bool &blocking)
|
2018-03-23 03:41:50 +01:00
|
|
|
{
|
2018-04-20 23:12:57 +02:00
|
|
|
for(const auto &c : d.columns)
|
|
|
|
{
|
|
|
|
db::column column{*c};
|
2018-04-27 02:19:29 +02:00
|
|
|
db::sort(column, blocking);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-09-20 01:36:01 +02:00
|
|
|
ircd::db::compact(database &d,
|
|
|
|
const compactor &cb)
|
2018-04-27 02:19:29 +02:00
|
|
|
{
|
2018-05-11 01:41:34 +02:00
|
|
|
static const std::pair<string_view, string_view> range
|
|
|
|
{
|
|
|
|
{}, {}
|
|
|
|
};
|
|
|
|
|
2018-04-27 02:19:29 +02:00
|
|
|
for(const auto &c : d.columns)
|
|
|
|
{
|
|
|
|
db::column column{*c};
|
2018-09-21 08:30:00 +02:00
|
|
|
compact(column, range, -1, cb);
|
2018-09-20 01:36:01 +02:00
|
|
|
compact(column, -1, cb);
|
2018-04-20 23:12:57 +02:00
|
|
|
}
|
2018-03-23 03:41:50 +01:00
|
|
|
}
|
|
|
|
|
2018-05-23 01:52:34 +02:00
|
|
|
void
|
|
|
|
ircd::db::check(database &d)
|
|
|
|
{
|
|
|
|
assert(d.d);
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-05-23 01:52:34 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->VerifyChecksum()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-31 23:03:32 +01:00
|
|
|
void
|
|
|
|
ircd::db::resume(database &d)
|
|
|
|
{
|
|
|
|
assert(d.d);
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-10-31 23:29:00 +01:00
|
|
|
const auto errors
|
|
|
|
{
|
|
|
|
db::errors(d)
|
|
|
|
};
|
|
|
|
|
2018-10-31 23:03:32 +01:00
|
|
|
log::debug
|
|
|
|
{
|
2018-10-31 23:29:00 +01:00
|
|
|
log, "'%s': Attempting to resume from %zu errors @%lu",
|
2018-10-31 23:03:32 +01:00
|
|
|
name(d),
|
2018-10-31 23:29:00 +01:00
|
|
|
errors.size(),
|
2018-10-31 23:03:32 +01:00
|
|
|
sequence(d)
|
|
|
|
};
|
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->Resume()
|
|
|
|
};
|
|
|
|
|
2018-10-31 23:29:00 +01:00
|
|
|
d.errors.clear();
|
|
|
|
|
2018-10-31 23:03:32 +01:00
|
|
|
log::info
|
|
|
|
{
|
2018-10-31 23:29:00 +01:00
|
|
|
log, "'%s': Resumed normal operation at sequence number %lu; cleared %zu errors",
|
2018-10-31 23:03:32 +01:00
|
|
|
name(d),
|
2018-10-31 23:29:00 +01:00
|
|
|
sequence(d),
|
|
|
|
errors.size()
|
2018-10-31 23:03:32 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-23 03:56:08 +01:00
|
|
|
/// Writes a snapshot of this database to the directory specified. The
|
|
|
|
/// snapshot consists of hardlinks to the bulk data files of this db, but
|
|
|
|
/// copies the other stuff that usually gets corrupted. The directory can
|
|
|
|
/// then be opened as its own database either read-only or read-write.
|
|
|
|
/// Incremental backups and rollbacks can begin from this interface. Note
|
|
|
|
/// this may be an expensive blocking operation.
|
2018-05-25 05:01:52 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::checkpoint(database &d)
|
2018-03-23 03:56:08 +01:00
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
if(!d.checkpointer)
|
2018-03-23 03:56:08 +01:00
|
|
|
throw error
|
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
"Checkpointing is not available for db(%p) '%s",
|
|
|
|
&d,
|
|
|
|
name(d)
|
2018-03-23 03:56:08 +01:00
|
|
|
};
|
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-05-25 05:01:52 +02:00
|
|
|
const auto seqnum
|
|
|
|
{
|
|
|
|
sequence(d)
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string dir
|
|
|
|
{
|
|
|
|
db::path(name(d), seqnum)
|
|
|
|
};
|
|
|
|
|
2018-03-23 03:56:08 +01:00
|
|
|
throw_on_error
|
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
d.checkpointer->CreateCheckpoint(dir, 0)
|
2018-03-23 03:56:08 +01:00
|
|
|
};
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': Checkpoint at sequence %lu in `%s' complete",
|
|
|
|
name(d),
|
|
|
|
seqnum,
|
|
|
|
dir
|
|
|
|
};
|
|
|
|
|
|
|
|
return seqnum;
|
2018-03-23 03:56:08 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 20:26:56 +02:00
|
|
|
/// This wraps RocksDB's "File Deletions" which means after RocksDB
|
|
|
|
/// compresses some file it then destroys the uncompressed version;
|
|
|
|
/// setting this to false will disable that and retain both versions.
|
|
|
|
/// This is useful when a direct reference is being manually held by
|
|
|
|
/// us into the uncompressed version which must remain valid.
|
|
|
|
void
|
|
|
|
ircd::db::fdeletions(database &d,
|
2018-04-20 22:38:49 +02:00
|
|
|
const bool &enable,
|
|
|
|
const bool &force)
|
2018-04-03 20:26:56 +02:00
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-04-03 20:26:56 +02:00
|
|
|
if(enable) throw_on_error
|
|
|
|
{
|
2018-04-20 22:38:49 +02:00
|
|
|
d.d->EnableFileDeletions(force)
|
2018-04-03 20:26:56 +02:00
|
|
|
};
|
|
|
|
else throw_on_error
|
|
|
|
{
|
|
|
|
d.d->DisableFileDeletions()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-20 23:10:59 +02:00
|
|
|
void
|
|
|
|
ircd::db::setopt(database &d,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &val)
|
|
|
|
{
|
|
|
|
const std::unordered_map<std::string, std::string> options
|
|
|
|
{
|
|
|
|
{ std::string{key}, std::string{val} }
|
|
|
|
};
|
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-04-20 23:10:59 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->SetDBOptions(options)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-17 23:13:36 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::bytes(const database &d)
|
|
|
|
{
|
|
|
|
return std::accumulate(begin(d.columns), end(d.columns), size_t(0), []
|
|
|
|
(auto ret, const auto &colptr)
|
|
|
|
{
|
|
|
|
db::column c{*colptr};
|
|
|
|
return ret += db::bytes(c);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::file_count(const database &d)
|
|
|
|
{
|
|
|
|
return std::accumulate(begin(d.columns), end(d.columns), size_t(0), []
|
|
|
|
(auto ret, const auto &colptr)
|
|
|
|
{
|
|
|
|
db::column c{*colptr};
|
|
|
|
return ret += db::file_count(c);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-03 20:44:57 +02:00
|
|
|
/// Get the live file list for db; see overlord documentation.
|
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::files(const database &d)
|
|
|
|
{
|
|
|
|
uint64_t ignored;
|
|
|
|
return files(d, ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the live file list for database relative to the database's directory.
|
|
|
|
/// One of the files is a manifest file which is over-allocated and its used
|
|
|
|
/// size is returned in the integer passed to the `msz` argument.
|
|
|
|
///
|
|
|
|
/// This list may not be completely up to date. The reliable way to get the
|
|
|
|
/// most current list is to flush all columns first and ensure no database
|
|
|
|
/// activity took place between the flushing and this query.
|
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::files(const database &cd,
|
|
|
|
uint64_t &msz)
|
|
|
|
{
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
auto &d(const_cast<database &>(cd));
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-04-03 20:44:57 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->GetLiveFiles(ret, &msz, false)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-31 23:29:00 +01:00
|
|
|
const std::vector<std::string> &
|
|
|
|
ircd::db::errors(const database &d)
|
|
|
|
{
|
|
|
|
return d.errors;
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
uint64_t
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::sequence(const database &cd)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-03-23 03:35:50 +01:00
|
|
|
database &d(const_cast<database &>(cd));
|
2017-03-31 00:57:08 +02:00
|
|
|
return d.d->GetLatestSequenceNumber();
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:17:43 +02:00
|
|
|
rocksdb::Cache *
|
|
|
|
ircd::db::cache(database &d)
|
|
|
|
{
|
2018-09-03 02:29:44 +02:00
|
|
|
return d.row_cache.get();
|
2018-05-15 01:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const rocksdb::Cache *
|
|
|
|
ircd::db::cache(const database &d)
|
|
|
|
{
|
2018-09-03 02:29:44 +02:00
|
|
|
return d.row_cache.get();
|
2018-05-15 01:17:43 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
template<>
|
2018-04-03 19:58:16 +02:00
|
|
|
ircd::db::prop_int
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::property(const database &cd,
|
2017-03-31 00:57:08 +02:00
|
|
|
const string_view &name)
|
|
|
|
{
|
2018-09-26 00:07:56 +02:00
|
|
|
uint64_t ret(0);
|
2018-03-23 03:35:50 +01:00
|
|
|
database &d(const_cast<database &>(cd));
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2017-03-31 00:57:08 +02:00
|
|
|
if(!d.d->GetAggregatedIntProperty(slice(name), &ret))
|
2018-04-13 03:57:03 +02:00
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"property '%s' for all columns in '%s' not found or not an integer.",
|
|
|
|
name,
|
|
|
|
db::name(d)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
return ret;
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
std::shared_ptr<ircd::db::database::column>
|
|
|
|
ircd::db::shared_from(database::column &column)
|
|
|
|
{
|
|
|
|
return column.shared_from_this();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<const ircd::db::database::column>
|
|
|
|
ircd::db::shared_from(const database::column &column)
|
|
|
|
{
|
|
|
|
return column.shared_from_this();
|
|
|
|
}
|
|
|
|
|
2018-05-23 02:01:01 +02:00
|
|
|
const std::string &
|
|
|
|
ircd::db::uuid(const database &d)
|
|
|
|
{
|
|
|
|
return d.uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const database &d)
|
|
|
|
{
|
|
|
|
return d.name;
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
//
|
2017-03-31 00:57:08 +02:00
|
|
|
// database
|
2017-03-24 02:36:49 +01:00
|
|
|
//
|
2018-05-25 05:01:52 +02:00
|
|
|
|
2017-08-31 07:13:50 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const description default_description;
|
2017-08-31 07:13:50 +02:00
|
|
|
}
|
2016-11-29 16:23:38 +01:00
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
// Instance list linkage
|
|
|
|
template<>
|
|
|
|
decltype(ircd::util::instance_list<ircd::db::database>::list)
|
|
|
|
ircd::util::instance_list<ircd::db::database>::list
|
|
|
|
{};
|
|
|
|
|
2018-04-27 01:22:16 +02:00
|
|
|
decltype(ircd::db::default_description)
|
|
|
|
ircd::db::default_description
|
|
|
|
{
|
|
|
|
/// Requirement of RocksDB going back to LevelDB. This column must
|
|
|
|
/// always exist in all descriptions and probably should be at idx[0].
|
|
|
|
{ "default" }
|
|
|
|
};
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
ircd::db::database &
|
|
|
|
ircd::db::database::get(column &column)
|
|
|
|
{
|
|
|
|
assert(column.d);
|
|
|
|
return *column.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::database &
|
|
|
|
ircd::db::database::get(const column &column)
|
|
|
|
{
|
|
|
|
assert(column.d);
|
|
|
|
return *column.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database &
|
|
|
|
ircd::db::database::get(const string_view &name)
|
|
|
|
{
|
|
|
|
const auto pair
|
|
|
|
{
|
|
|
|
namepoint(name)
|
|
|
|
};
|
|
|
|
|
|
|
|
return get(pair.first, pair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database &
|
|
|
|
ircd::db::database::get(const string_view &name,
|
|
|
|
const uint64_t &checkpoint)
|
|
|
|
{
|
|
|
|
auto *const &d
|
|
|
|
{
|
|
|
|
get(std::nothrow, name, checkpoint)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(likely(d))
|
|
|
|
return *d;
|
|
|
|
|
|
|
|
throw checkpoint == uint64_t(-1)?
|
|
|
|
std::out_of_range{"No database with that name exists"}:
|
|
|
|
std::out_of_range{"No database with that name at that checkpoint exists"};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database *
|
|
|
|
ircd::db::database::get(std::nothrow_t,
|
|
|
|
const string_view &name)
|
|
|
|
{
|
|
|
|
const auto pair
|
|
|
|
{
|
|
|
|
namepoint(name)
|
|
|
|
};
|
|
|
|
|
|
|
|
return get(std::nothrow, pair.first, pair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database *
|
|
|
|
ircd::db::database::get(std::nothrow_t,
|
|
|
|
const string_view &name,
|
|
|
|
const uint64_t &checkpoint)
|
|
|
|
{
|
|
|
|
for(auto *const &d : list)
|
|
|
|
if(name == d->name)
|
|
|
|
if(checkpoint == uint64_t(-1) || checkpoint == d->checkpoint)
|
|
|
|
return d;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// database::database
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::database(const string_view &name,
|
2017-08-23 22:37:47 +02:00
|
|
|
std::string optstr)
|
2017-08-23 23:37:06 +02:00
|
|
|
:database
|
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
name, std::move(optstr), default_description
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::database(const string_view &name,
|
|
|
|
std::string optstr,
|
|
|
|
description description)
|
|
|
|
:database
|
|
|
|
{
|
|
|
|
namepoint(name).first, namepoint(name).second, std::move(optstr), std::move(description)
|
2017-08-23 23:37:06 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
ircd::db::database::database(const string_view &name,
|
|
|
|
const uint64_t &checkpoint,
|
2017-08-23 22:37:47 +02:00
|
|
|
std::string optstr,
|
2017-09-19 05:53:45 +02:00
|
|
|
description description)
|
2016-09-24 06:01:57 +02:00
|
|
|
try
|
2017-03-31 00:57:08 +02:00
|
|
|
:name
|
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
namepoint(name).first
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2018-05-25 05:01:52 +02:00
|
|
|
,checkpoint
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
// a -1 may have been generated by the db::namepoint() util when the user
|
|
|
|
// supplied just a name without a checkpoint. In the context of database
|
|
|
|
// opening/creation -1 just defaults to 0.
|
|
|
|
checkpoint == uint64_t(-1)? 0 : checkpoint
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2017-09-19 04:17:36 +02:00
|
|
|
,optstr
|
|
|
|
{
|
|
|
|
std::move(optstr)
|
|
|
|
}
|
2018-05-25 05:01:52 +02:00
|
|
|
,path
|
|
|
|
{
|
|
|
|
db::path(this->name, this->checkpoint)
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
,env
|
|
|
|
{
|
|
|
|
std::make_shared<struct env>(this)
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
,logs
|
|
|
|
{
|
|
|
|
std::make_shared<struct logs>(this)
|
|
|
|
}
|
|
|
|
,stats
|
|
|
|
{
|
|
|
|
std::make_shared<struct stats>(this)
|
|
|
|
}
|
|
|
|
,events
|
|
|
|
{
|
|
|
|
std::make_shared<struct events>(this)
|
|
|
|
}
|
|
|
|
,mergeop
|
|
|
|
{
|
|
|
|
std::make_shared<struct mergeop>(this)
|
|
|
|
}
|
2018-04-21 00:45:57 +02:00
|
|
|
,ssts
|
|
|
|
{
|
2018-08-21 09:20:54 +02:00
|
|
|
// note: the sst file manager cannot be used for now because it will spawn
|
|
|
|
// note: a pthread internally in rocksdb which does not use our callbacks
|
|
|
|
// note: we gave in the supplied env. we really don't want that.
|
|
|
|
|
2018-07-05 01:47:11 +02:00
|
|
|
//rocksdb::NewSstFileManager(env.get(), logs, {}, 0, true, nullptr, 0.05)
|
2018-04-21 00:45:57 +02:00
|
|
|
}
|
2018-09-03 02:29:44 +02:00
|
|
|
,row_cache
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-10-21 08:30:27 +02:00
|
|
|
std::make_shared<database::cache>(this, this->stats, 16_MiB)
|
2018-09-03 02:29:44 +02:00
|
|
|
}
|
2017-11-16 02:29:54 +01:00
|
|
|
,descriptors
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-11-16 02:29:54 +01:00
|
|
|
std::move(description)
|
|
|
|
}
|
|
|
|
,column_names{[this]
|
|
|
|
{
|
|
|
|
// Existing columns at path. If any are left the descriptor set did not
|
|
|
|
// describe all of the columns found in the database at path.
|
2018-04-03 02:18:02 +02:00
|
|
|
const auto opts
|
|
|
|
{
|
2018-04-09 20:51:36 +02:00
|
|
|
make_dbopts(this->optstr)
|
2018-04-03 02:18:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto required
|
|
|
|
{
|
|
|
|
db::column_names(path, opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
std::set<string_view> existing
|
|
|
|
{
|
|
|
|
begin(required), end(required)
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2017-11-16 02:29:54 +01:00
|
|
|
// The names of the columns extracted from the descriptor set
|
2018-10-22 16:09:55 +02:00
|
|
|
decltype(this->column_names) ret;
|
|
|
|
for(auto &descriptor : descriptors)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
ret.emplace(descriptor.name, std::make_shared<column>(*this, descriptor));
|
2017-09-19 04:17:36 +02:00
|
|
|
existing.erase(descriptor.name);
|
2018-10-22 16:09:55 +02:00
|
|
|
}
|
2017-09-19 04:17:36 +02:00
|
|
|
|
|
|
|
for(const auto &remain : existing)
|
2018-04-03 02:18:02 +02:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Failed to describe existing column '%s' (and %zd others...)",
|
|
|
|
remain,
|
|
|
|
existing.size() - 1
|
|
|
|
};
|
|
|
|
|
2017-11-16 02:29:54 +01:00
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,d{[this]
|
2017-09-19 04:17:36 +02:00
|
|
|
{
|
|
|
|
bool fsck{false};
|
|
|
|
bool read_only{false};
|
2018-04-03 02:18:02 +02:00
|
|
|
auto opts
|
|
|
|
{
|
2018-04-09 20:51:36 +02:00
|
|
|
make_dbopts(this->optstr, &this->optstr, &read_only, &fsck)
|
2018-04-03 02:18:02 +02:00
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Setup sundry
|
2017-03-31 00:57:08 +02:00
|
|
|
opts.create_if_missing = true;
|
|
|
|
opts.create_missing_column_families = true;
|
2017-04-03 06:02:32 +02:00
|
|
|
opts.max_file_opening_threads = 0;
|
2018-04-13 07:46:33 +02:00
|
|
|
opts.stats_dump_period_sec = 0;
|
|
|
|
opts.enable_thread_tracking = true;
|
2018-07-05 01:47:11 +02:00
|
|
|
opts.avoid_flush_during_recovery = true;
|
2018-04-21 00:48:29 +02:00
|
|
|
opts.delete_obsolete_files_period_micros = 0;
|
|
|
|
opts.max_background_jobs = 2;
|
|
|
|
opts.max_background_flushes = 1;
|
|
|
|
opts.max_background_compactions = 1;
|
|
|
|
opts.max_subcompactions = 1;
|
2018-08-22 22:13:03 +02:00
|
|
|
opts.max_open_files = -1; //ircd::info::rlimit_nofile / 4;
|
2018-08-24 10:14:21 +02:00
|
|
|
opts.allow_concurrent_memtable_write = false;
|
|
|
|
opts.enable_write_thread_adaptive_yield = false;
|
|
|
|
opts.enable_pipelined_write = false;
|
|
|
|
opts.write_thread_max_yield_usec = 0;
|
|
|
|
opts.write_thread_slow_yield_usec = 0;
|
2018-09-23 00:16:45 +02:00
|
|
|
//opts.max_total_wal_size = 8_MiB;
|
2018-11-10 03:24:51 +01:00
|
|
|
opts.allow_fallocate = true;
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2018-09-04 11:09:49 +02:00
|
|
|
// Detect if O_DIRECT is possible if db::init left a file in the
|
|
|
|
// database directory claiming such. User can force no direct io
|
|
|
|
// with program option at startup (i.e -nodirect).
|
|
|
|
opts.use_direct_reads = ircd::nodirect? false:
|
|
|
|
fs::exists(direct_io_test_file_path());
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
opts.use_direct_io_for_flush_and_compaction = false;
|
2018-11-10 03:24:51 +01:00
|
|
|
//opts.use_direct_io_for_flush_and_compaction = opts.use_direct_reads;
|
2018-11-02 09:07:42 +01:00
|
|
|
|
2018-04-13 07:46:33 +02:00
|
|
|
#ifdef RB_DEBUG
|
|
|
|
opts.dump_malloc_stats = true;
|
|
|
|
#endif
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
// Setup env
|
|
|
|
opts.env = env.get();
|
|
|
|
|
2018-04-21 00:45:57 +02:00
|
|
|
// Setup SST file mgmt
|
|
|
|
opts.sst_file_manager = this->ssts;
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
// Setup logging
|
|
|
|
logs->SetInfoLogLevel(ircd::debugmode? rocksdb::DEBUG_LEVEL : rocksdb::WARN_LEVEL);
|
2017-03-31 00:57:08 +02:00
|
|
|
opts.info_log_level = logs->GetInfoLogLevel();
|
|
|
|
opts.info_log = logs;
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2017-03-23 22:58:24 +01:00
|
|
|
// Setup event and statistics callbacks
|
2017-03-31 00:57:08 +02:00
|
|
|
opts.listeners.emplace_back(this->events);
|
2018-04-15 09:24:38 +02:00
|
|
|
|
|
|
|
// Setup histogram collecting
|
|
|
|
//this->stats->stats_level_ = rocksdb::kAll;
|
|
|
|
this->stats->stats_level_ = rocksdb::kExceptTimeForMutex;
|
|
|
|
opts.statistics = this->stats;
|
2017-03-23 22:58:24 +01:00
|
|
|
|
|
|
|
// Setup performance metric options
|
|
|
|
//rocksdb::SetPerfLevel(rocksdb::PerfLevel::kDisable);
|
|
|
|
|
2018-07-07 01:53:10 +02:00
|
|
|
// Default corruption tolerance is zero-tolerance; db fails to open with
|
|
|
|
// error by default to inform the user. The rest of the options are
|
|
|
|
// various relaxations for how to proceed.
|
2017-11-30 20:04:25 +01:00
|
|
|
opts.wal_recovery_mode = rocksdb::WALRecoveryMode::kAbsoluteConsistency;
|
2018-07-07 01:53:10 +02:00
|
|
|
|
|
|
|
// When corrupted after crash, the DB is rolled back before the first
|
|
|
|
// corruption and erases everything after it, giving a consistent
|
|
|
|
// state up at that point, though losing some recent data.
|
|
|
|
if(ircd::pitrecdb) //TODO: no global?
|
|
|
|
opts.wal_recovery_mode = rocksdb::WALRecoveryMode::kPointInTimeRecovery;
|
|
|
|
|
|
|
|
// Skipping corrupted records will create gaps in the DB timeline where the
|
|
|
|
// application (like a matrix timeline) cannot tolerate the unexpected gap.
|
2018-04-09 21:01:58 +02:00
|
|
|
//opts.wal_recovery_mode = rocksdb::WALRecoveryMode::kSkipAnyCorruptedRecords;
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2018-07-07 01:53:10 +02:00
|
|
|
// Tolerating corrupted records is very last-ditch for getting the database to
|
|
|
|
// open in a catastrophe. We have no use for this option but should use it for
|
|
|
|
//TODO: emergency salvage-mode.
|
|
|
|
//opts.wal_recovery_mode = rocksdb::WALRecoveryMode::kTolerateCorruptedTailRecords;
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Setup cache
|
2018-09-03 02:29:44 +02:00
|
|
|
opts.row_cache = this->row_cache;
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2018-10-22 16:09:55 +02:00
|
|
|
std::vector<rocksdb::ColumnFamilyHandle *> handles; // filled by DB::Open()
|
|
|
|
std::vector<rocksdb::ColumnFamilyDescriptor> columns(this->column_names.size());
|
|
|
|
std::transform(begin(this->column_names), end(this->column_names), begin(columns), []
|
|
|
|
(const auto &pair)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
const auto &column(*pair.second);
|
|
|
|
return static_cast<const rocksdb::ColumnFamilyDescriptor &>(column);
|
2017-03-31 00:57:08 +02:00
|
|
|
});
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2018-04-09 21:01:58 +02:00
|
|
|
// NOTE: rocksdb sez RepairDB is broken; can't use now
|
2017-08-23 22:37:47 +02:00
|
|
|
if(fsck && fs::is_dir(path))
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
2018-05-29 10:09:15 +02:00
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
log, "Checking database @ `%s' columns[%zu]", path, columns.size()
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::RepairDB(path, opts, columns)
|
|
|
|
};
|
|
|
|
|
2018-05-29 10:09:15 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "Database @ `%s' check complete", path
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2018-04-03 02:19:01 +02:00
|
|
|
// If the directory does not exist, though rocksdb will create it, we can
|
|
|
|
// avoid scaring the user with an error log message if we just do that..
|
|
|
|
if(opts.create_if_missing && !fs::is_dir(path))
|
|
|
|
fs::mkdir(path);
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Announce attempt before usual point where exceptions are thrown
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2018-05-29 10:09:15 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "Opening database \"%s\" @ `%s' with %zu columns...",
|
|
|
|
this->name,
|
|
|
|
path,
|
|
|
|
columns.size()
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2017-09-20 06:40:53 +02:00
|
|
|
// Open DB into ptr
|
|
|
|
rocksdb::DB *ptr;
|
2017-08-23 22:37:47 +02:00
|
|
|
if(read_only)
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::DB::OpenForReadOnly(opts, path, columns, &handles, &ptr)
|
|
|
|
};
|
|
|
|
else
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::DB::Open(opts, path, columns, &handles, &ptr)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2018-04-27 01:39:59 +02:00
|
|
|
std::unique_ptr<rocksdb::DB> ret
|
2017-09-19 04:17:36 +02:00
|
|
|
{
|
2018-04-27 01:39:59 +02:00
|
|
|
ptr
|
|
|
|
};
|
|
|
|
|
2018-10-22 16:09:55 +02:00
|
|
|
// Set the handles. We can't throw here so we just log an error.
|
|
|
|
for(const auto &handle : handles) try
|
2017-11-16 02:29:54 +01:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
this->column_names.at(handle->GetName())->handle.reset(handle);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': Error finding described handle '%s' which RocksDB opened :%s",
|
|
|
|
this->name,
|
|
|
|
handle->GetName(),
|
|
|
|
e.what()
|
|
|
|
};
|
2017-11-16 02:29:54 +01:00
|
|
|
}
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2018-04-27 01:39:59 +02:00
|
|
|
return ret;
|
2017-03-24 02:36:49 +01:00
|
|
|
}()}
|
2018-10-22 16:09:55 +02:00
|
|
|
,column_index{[this]
|
|
|
|
{
|
|
|
|
size_t size{0};
|
|
|
|
for(const auto &p : column_names)
|
|
|
|
{
|
|
|
|
const auto &column(*p.second);
|
|
|
|
if(db::id(column) + 1 > size)
|
|
|
|
size = db::id(column) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This may have some gaps containing nullptrs where a CFID is unused.
|
|
|
|
decltype(this->column_index) ret(size);
|
|
|
|
for(const auto &p : column_names)
|
|
|
|
{
|
|
|
|
const auto &colptr(p.second);
|
|
|
|
ret.at(db::id(*colptr)) = colptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,columns{[this]
|
|
|
|
{
|
|
|
|
// Skip the gaps in the column_index vector to make the columns list
|
|
|
|
// only contain active column instances.
|
|
|
|
decltype(this->columns) ret;
|
|
|
|
for(const auto &ptr : this->column_index)
|
|
|
|
if(ptr)
|
|
|
|
ret.emplace_back(ptr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}()}
|
2018-05-23 02:01:01 +02:00
|
|
|
,uuid{[this]
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2018-05-23 02:01:01 +02:00
|
|
|
std::string ret;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d->GetDbIdentity(ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}()}
|
2018-05-25 05:01:52 +02:00
|
|
|
,checkpointer{[this]
|
2018-03-23 03:56:08 +01:00
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2018-03-23 03:56:08 +01:00
|
|
|
rocksdb::Checkpoint *checkpointer{nullptr};
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::Checkpoint::Create(this->d.get(), &checkpointer)
|
|
|
|
};
|
|
|
|
|
|
|
|
return checkpointer;
|
|
|
|
}()}
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-05-31 21:47:37 +02:00
|
|
|
if(ircd::checkdb)
|
2018-04-27 01:48:35 +02:00
|
|
|
{
|
2018-05-31 21:47:37 +02:00
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
log, "'%s': Verifying database integrity. This may take several minutes...",
|
|
|
|
this->name
|
|
|
|
};
|
|
|
|
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2018-05-31 21:47:37 +02:00
|
|
|
check(*this);
|
|
|
|
}
|
2018-04-27 01:48:35 +02:00
|
|
|
|
2018-05-29 10:09:15 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "'%s': Opened database @ `%s' with %zu columns at sequence number %lu.",
|
|
|
|
this->name,
|
|
|
|
path,
|
|
|
|
columns.size(),
|
|
|
|
d->GetLatestSequenceNumber()
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2018-07-07 01:53:10 +02:00
|
|
|
catch(const corruption &e)
|
|
|
|
{
|
|
|
|
throw corruption
|
|
|
|
{
|
|
|
|
"Corruption for '%s' (%s). Try restarting with the -pitrecdb command line option",
|
|
|
|
this->name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2018-04-03 02:18:02 +02:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Failed to open db '%s': %s",
|
|
|
|
this->name,
|
|
|
|
e.what()
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::~database()
|
2018-04-21 01:22:01 +02:00
|
|
|
noexcept try
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:09:15 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "'%s': closing database @ `%s'...",
|
|
|
|
name,
|
|
|
|
path
|
|
|
|
};
|
2018-04-13 07:43:42 +02:00
|
|
|
|
2018-02-06 03:52:31 +01:00
|
|
|
rocksdb::CancelAllBackgroundWork(d.get(), true); // true = blocking
|
2018-05-29 10:09:15 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': background_errors: %lu; flushing...",
|
|
|
|
name,
|
|
|
|
property<uint64_t>(*this, rocksdb::DB::Properties::kBackgroundErrors)
|
|
|
|
};
|
2018-01-18 06:44:56 +01:00
|
|
|
|
2018-04-27 02:19:29 +02:00
|
|
|
flush(*this);
|
2018-10-22 16:09:55 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': flushed; closing columns...",
|
|
|
|
name
|
|
|
|
};
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
this->checkpointer.reset(nullptr);
|
2018-10-22 16:09:55 +02:00
|
|
|
this->column_names.clear();
|
|
|
|
this->column_index.clear();
|
2018-04-27 02:19:29 +02:00
|
|
|
this->columns.clear();
|
2018-05-29 10:09:15 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': closed columns; synchronizing...",
|
|
|
|
name
|
|
|
|
};
|
2018-04-27 02:19:29 +02:00
|
|
|
|
2018-02-06 03:52:31 +01:00
|
|
|
sync(*this);
|
2018-05-29 10:09:15 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': synchronized with hardware.",
|
|
|
|
name
|
|
|
|
};
|
2018-04-21 01:22:01 +02:00
|
|
|
|
|
|
|
const auto sequence
|
|
|
|
{
|
|
|
|
d->GetLatestSequenceNumber()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d->Close()
|
|
|
|
};
|
|
|
|
|
2018-05-29 10:09:15 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "'%s': closed database @ `%s' at sequence number %lu.",
|
|
|
|
name,
|
|
|
|
path,
|
|
|
|
sequence
|
|
|
|
};
|
2018-04-21 01:22:01 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': Error closing database(%p) :%s",
|
2018-04-21 01:22:01 +02:00
|
|
|
name,
|
2018-08-24 06:32:28 +02:00
|
|
|
this,
|
2018-04-21 01:22:01 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2018-08-28 23:04:43 +02:00
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': Unknown error closing database(%p)",
|
|
|
|
name,
|
|
|
|
this
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-08-30 23:07:36 +02:00
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const delta &delta)
|
|
|
|
{
|
|
|
|
operator()(sopts{}, delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const std::initializer_list<delta> &deltas)
|
|
|
|
{
|
|
|
|
operator()(sopts{}, deltas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const delta *const &begin,
|
|
|
|
const delta *const &end)
|
|
|
|
{
|
|
|
|
operator()(sopts{}, begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const sopts &sopts,
|
|
|
|
const delta &delta)
|
|
|
|
{
|
|
|
|
operator()(sopts, &delta, &delta + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const sopts &sopts,
|
|
|
|
const std::initializer_list<delta> &deltas)
|
|
|
|
{
|
|
|
|
operator()(sopts, std::begin(deltas), std::end(deltas));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::operator()(const sopts &sopts,
|
|
|
|
const delta *const &begin,
|
|
|
|
const delta *const &end)
|
|
|
|
{
|
|
|
|
rocksdb::WriteBatch batch;
|
|
|
|
std::for_each(begin, end, [this, &batch]
|
|
|
|
(const delta &delta)
|
|
|
|
{
|
|
|
|
const auto &op(std::get<op>(delta));
|
|
|
|
const auto &col(std::get<1>(delta));
|
|
|
|
const auto &key(std::get<2>(delta));
|
|
|
|
const auto &val(std::get<3>(delta));
|
|
|
|
db::column column(operator[](col));
|
|
|
|
append(batch, column, db::column::delta
|
|
|
|
{
|
|
|
|
op,
|
|
|
|
key,
|
|
|
|
val
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
commit(*this, batch, sopts);
|
2017-08-30 23:07:36 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::column &
|
|
|
|
ircd::db::database::operator[](const string_view &name)
|
2017-09-19 04:17:36 +02:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
const auto it{column_names.find(name)};
|
|
|
|
if(unlikely(it == std::end(column_names)))
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"'%s': column '%s' is not available or specified in schema",
|
|
|
|
this->name,
|
|
|
|
name
|
|
|
|
};
|
2017-09-19 04:17:36 +02:00
|
|
|
|
2018-10-22 16:09:55 +02:00
|
|
|
return operator[](db::id(*it->second));
|
2017-09-19 04:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::column &
|
|
|
|
ircd::db::database::operator[](const uint32_t &id)
|
2017-04-03 06:02:32 +02:00
|
|
|
try
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
auto &ret(*column_index.at(id));
|
|
|
|
assert(db::id(ret) == id);
|
|
|
|
return ret;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
catch(const std::out_of_range &e)
|
|
|
|
{
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"'%s': column id[%u] is not available or specified in schema",
|
|
|
|
this->name,
|
|
|
|
id
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
const ircd::db::database::column &
|
|
|
|
ircd::db::database::operator[](const string_view &name)
|
2017-09-19 04:17:36 +02:00
|
|
|
const
|
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
const auto it{column_names.find(name)};
|
|
|
|
if(unlikely(it == std::end(column_names)))
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"'%s': column '%s' is not available or specified in schema",
|
|
|
|
this->name,
|
|
|
|
name
|
|
|
|
};
|
2017-09-19 04:17:36 +02:00
|
|
|
|
2018-10-22 16:09:55 +02:00
|
|
|
return operator[](db::id(*it->second));
|
2017-09-19 04:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::database::column &
|
|
|
|
ircd::db::database::operator[](const uint32_t &id)
|
2017-04-03 06:02:32 +02:00
|
|
|
const try
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
auto &ret(*column_index.at(id));
|
|
|
|
assert(db::id(ret) == id);
|
|
|
|
return ret;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
catch(const std::out_of_range &e)
|
|
|
|
{
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"'%s': column id[%u] is not available or specified in schema",
|
|
|
|
this->name,
|
|
|
|
id
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::comparator
|
|
|
|
//
|
|
|
|
|
2018-10-31 19:23:30 +01:00
|
|
|
ircd::db::database::comparator::comparator(database *const &d,
|
|
|
|
db::comparator user)
|
|
|
|
:d{d}
|
|
|
|
,user
|
|
|
|
{
|
|
|
|
std::move(user)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
const char *
|
|
|
|
ircd::db::database::comparator::Name()
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
assert(!user.name.empty());
|
2017-09-23 03:48:35 +02:00
|
|
|
return user.name.data();
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::comparator::Equal(const Slice &a,
|
|
|
|
const Slice &b)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-04-10 01:46:13 +02:00
|
|
|
return user.equal?
|
|
|
|
user.equal(slice(a), slice(b)):
|
|
|
|
Compare(a, b) == 0;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ircd::db::database::comparator::Compare(const Slice &a,
|
|
|
|
const Slice &b)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
assert(bool(user.less));
|
2017-09-23 03:48:35 +02:00
|
|
|
const auto sa{slice(a)};
|
|
|
|
const auto sb{slice(b)};
|
|
|
|
return user.less(sa, sb)? -1: // less[Y], equal[?], greater[?]
|
|
|
|
user.equal && user.equal(sa, sb)? 0: // less[N], equal[Y], greater[?]
|
|
|
|
user.equal? 1: // less[N], equal[N], greater[Y]
|
|
|
|
user.less(sb, sa)? 1: // less[N], equal[?], greater[Y]
|
|
|
|
0; // less[N], equal[Y], greater[N]
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-05-22 04:52:18 +02:00
|
|
|
ircd::db::database::comparator::FindShortestSeparator(std::string *const key,
|
|
|
|
const Slice &limit)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-05-22 04:52:18 +02:00
|
|
|
assert(key != nullptr);
|
|
|
|
if(user.separator)
|
|
|
|
user.separator(*key, slice(limit));
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
void
|
2018-05-22 04:52:18 +02:00
|
|
|
ircd::db::database::comparator::FindShortSuccessor(std::string *const key)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2018-05-22 04:52:18 +02:00
|
|
|
assert(key != nullptr);
|
|
|
|
if(user.successor)
|
|
|
|
user.successor(*key);
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2018-10-31 19:23:55 +01:00
|
|
|
bool
|
|
|
|
ircd::db::database::comparator::IsSameLengthImmediateSuccessor(const Slice &s,
|
|
|
|
const Slice &t)
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
return rocksdb::Comparator::IsSameLengthImmediateSuccessor(s, t);
|
|
|
|
}
|
|
|
|
|
2018-10-31 19:25:07 +01:00
|
|
|
bool
|
|
|
|
ircd::db::database::comparator::CanKeysWithDifferentByteContentsBeEqual()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
// When keys with different byte contents can be equal the keys are
|
|
|
|
// not hashable.
|
|
|
|
return !user.hashable;
|
|
|
|
}
|
|
|
|
|
2017-08-31 07:12:58 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::prefix_transform
|
|
|
|
//
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ircd::db::database::prefix_transform::Name()
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-08-31 07:12:58 +02:00
|
|
|
{
|
|
|
|
assert(!user.name.empty());
|
|
|
|
return user.name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Slice
|
|
|
|
ircd::db::database::prefix_transform::Transform(const Slice &key)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-08-31 07:12:58 +02:00
|
|
|
{
|
|
|
|
assert(bool(user.get));
|
2017-09-23 09:28:34 +02:00
|
|
|
return slice(user.get(slice(key)));
|
2017-08-31 07:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::prefix_transform::InRange(const Slice &key)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-08-31 07:12:58 +02:00
|
|
|
{
|
|
|
|
return InDomain(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::prefix_transform::InDomain(const Slice &key)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-08-31 07:12:58 +02:00
|
|
|
{
|
|
|
|
assert(bool(user.has));
|
2017-09-23 09:28:34 +02:00
|
|
|
return user.has(slice(key));
|
2017-08-31 07:12:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::column
|
|
|
|
//
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
void
|
|
|
|
ircd::db::drop(database::column &c)
|
|
|
|
{
|
|
|
|
if(!c.handle)
|
|
|
|
return;
|
|
|
|
|
2018-10-22 13:30:13 +02:00
|
|
|
database &d(c);
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s':'%s' @%lu DROPPING COLUMN",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d)
|
|
|
|
};
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
c.d->d->DropColumnFamily(c.handle.get())
|
|
|
|
};
|
2018-10-22 13:30:13 +02:00
|
|
|
|
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
log, "'%s':'%s' @%lu DROPPED COLUMN",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d)
|
|
|
|
};
|
2017-09-19 04:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ircd::db::id(const database::column &c)
|
|
|
|
{
|
|
|
|
if(!c.handle)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return c.handle->GetID();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const database::column &c)
|
|
|
|
{
|
|
|
|
return c.name;
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor &
|
2017-09-21 05:38:39 +02:00
|
|
|
ircd::db::describe(const database::column &c)
|
|
|
|
{
|
2018-10-22 16:09:16 +02:00
|
|
|
assert(c.descriptor);
|
|
|
|
return *c.descriptor;
|
2017-09-21 05:38:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
//
|
|
|
|
// database::column
|
|
|
|
//
|
|
|
|
|
2018-10-22 16:09:16 +02:00
|
|
|
ircd::db::database::column::column(database &d,
|
|
|
|
db::descriptor &descriptor)
|
2017-09-19 04:17:36 +02:00
|
|
|
:rocksdb::ColumnFamilyDescriptor
|
|
|
|
(
|
|
|
|
descriptor.name, database::options{descriptor.options}
|
|
|
|
)
|
2018-10-22 16:09:16 +02:00
|
|
|
,d{&d}
|
|
|
|
,descriptor{&descriptor}
|
|
|
|
,key_type{this->descriptor->type.first}
|
|
|
|
,mapped_type{this->descriptor->type.second}
|
|
|
|
,cmp{this->d, this->descriptor->cmp}
|
|
|
|
,prefix{this->d, this->descriptor->prefix}
|
|
|
|
,cfilter{this, this->descriptor->compactor}
|
|
|
|
,stats{std::make_shared<struct database::stats>(this->d)}
|
2017-04-03 06:02:32 +02:00
|
|
|
,handle
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-10-22 16:09:16 +02:00
|
|
|
nullptr, [&d](rocksdb::ColumnFamilyHandle *const handle)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2018-10-22 16:09:16 +02:00
|
|
|
assert(d.d);
|
|
|
|
if(handle && d.d)
|
|
|
|
d.d->DestroyColumnFamilyHandle(handle);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2018-04-18 00:28:08 +02:00
|
|
|
// If possible, deduce comparator based on type given in descriptor
|
2018-10-22 16:09:16 +02:00
|
|
|
if(!this->descriptor->cmp.less)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
if(key_type == typeid(string_view))
|
2017-09-23 03:48:35 +02:00
|
|
|
this->cmp.user = cmp_string_view{};
|
2017-03-31 00:57:08 +02:00
|
|
|
else if(key_type == typeid(int64_t))
|
2017-09-23 03:48:35 +02:00
|
|
|
this->cmp.user = cmp_int64_t{};
|
2018-04-18 00:28:08 +02:00
|
|
|
else if(key_type == typeid(uint64_t))
|
|
|
|
this->cmp.user = cmp_uint64_t{};
|
2017-03-31 00:57:08 +02:00
|
|
|
else
|
2018-04-18 00:28:08 +02:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"column '%s' key type[%s] requires user supplied comparator",
|
|
|
|
this->name,
|
|
|
|
key_type.name()
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 10:33:41 +02:00
|
|
|
// Set the key comparator
|
2017-03-31 00:57:08 +02:00
|
|
|
this->options.comparator = &this->cmp;
|
|
|
|
|
2017-08-31 07:12:58 +02:00
|
|
|
// Set the prefix extractor
|
|
|
|
if(this->prefix.user.get && this->prefix.user.has)
|
|
|
|
this->options.prefix_extractor = std::shared_ptr<const rocksdb::SliceTransform>
|
|
|
|
{
|
|
|
|
&this->prefix, [](const rocksdb::SliceTransform *) {}
|
|
|
|
};
|
2017-08-23 22:37:47 +02:00
|
|
|
|
2018-09-25 11:37:29 +02:00
|
|
|
// Set the insert hint prefix extractor
|
|
|
|
if(this->options.prefix_extractor)
|
|
|
|
this->options.memtable_insert_with_hint_prefix_extractor = this->options.prefix_extractor;
|
|
|
|
|
2018-09-19 00:07:09 +02:00
|
|
|
// Set the compaction filter
|
|
|
|
this->options.compaction_filter = &this->cfilter;
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
//
|
|
|
|
// Table options
|
|
|
|
//
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2018-10-14 17:53:46 +02:00
|
|
|
// Block based table index type.
|
2018-10-18 07:11:28 +02:00
|
|
|
table_opts.format_version = 3; // RocksDB >= 5.15 compat only; otherwise use 2.
|
2018-10-14 17:53:46 +02:00
|
|
|
table_opts.index_type = rocksdb::BlockBasedTableOptions::kTwoLevelIndexSearch;
|
|
|
|
table_opts.partition_filters = true;
|
2018-10-18 07:11:28 +02:00
|
|
|
table_opts.use_delta_encoding = true;
|
|
|
|
table_opts.enable_index_compression = false;
|
2018-10-22 22:53:02 +02:00
|
|
|
table_opts.read_amp_bytes_per_bit = 8;
|
2018-10-14 17:53:46 +02:00
|
|
|
|
2018-10-16 10:25:02 +02:00
|
|
|
// Specify that index blocks should use the cache. If not, they will be
|
|
|
|
// pre-read into RAM by rocksdb internally. Because of the above
|
|
|
|
// TwoLevelIndex + partition_filters configuration on RocksDB v5.15 it's
|
2018-11-09 07:19:26 +01:00
|
|
|
// better to use pre-read except in the case of a massive database.
|
2018-11-03 02:31:20 +01:00
|
|
|
table_opts.cache_index_and_filter_blocks = true;
|
2018-10-16 10:25:02 +02:00
|
|
|
table_opts.cache_index_and_filter_blocks_with_high_priority = false;
|
|
|
|
table_opts.pin_top_level_index_and_filter = false;
|
|
|
|
table_opts.pin_l0_filter_and_index_blocks_in_cache = false;
|
|
|
|
|
2018-09-18 06:26:55 +02:00
|
|
|
// Setup the block size
|
2018-10-22 16:09:16 +02:00
|
|
|
table_opts.block_size = this->descriptor->block_size;
|
|
|
|
table_opts.metadata_block_size = this->descriptor->meta_block_size;
|
2018-10-22 22:53:02 +02:00
|
|
|
table_opts.block_size_deviation = 50;
|
2018-11-02 09:07:42 +01:00
|
|
|
table_opts.block_align = false; // Doesn't work w/ compression.
|
2018-09-18 06:26:55 +02:00
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
// Setup the cache for assets.
|
2018-10-22 16:09:16 +02:00
|
|
|
const auto &cache_size(this->descriptor->cache_size);
|
2018-09-03 02:31:09 +02:00
|
|
|
if(cache_size != 0)
|
2018-10-22 16:09:16 +02:00
|
|
|
table_opts.block_cache = std::make_shared<database::cache>(this->d, this->stats, cache_size);
|
2018-04-15 08:00:56 +02:00
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
// Setup the cache for compressed assets.
|
2018-10-22 16:09:16 +02:00
|
|
|
const auto &cache_size_comp(this->descriptor->cache_size_comp);
|
2018-09-03 02:31:09 +02:00
|
|
|
if(cache_size_comp != 0)
|
2018-10-22 16:09:16 +02:00
|
|
|
table_opts.block_cache_compressed = std::make_shared<database::cache>(this->d, this->stats, cache_size_comp);
|
2018-04-15 08:00:56 +02:00
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
// Setup the bloom filter.
|
2018-10-22 16:09:16 +02:00
|
|
|
const auto &bloom_bits(this->descriptor->bloom_bits);
|
2018-04-15 08:00:56 +02:00
|
|
|
if(bloom_bits)
|
|
|
|
table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(bloom_bits, false));
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
// Tickers::READ_AMP_TOTAL_READ_BYTES / Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES
|
|
|
|
//table_opts.read_amp_bytes_per_bit = 8;
|
|
|
|
|
2018-10-14 17:53:46 +02:00
|
|
|
// Finally set the table options in the column options.
|
2018-04-15 08:00:56 +02:00
|
|
|
this->options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_opts));
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
//
|
|
|
|
// Misc options
|
|
|
|
//
|
|
|
|
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.paranoid_file_checks = true;
|
|
|
|
|
2018-09-19 00:07:09 +02:00
|
|
|
// More stats reported by the rocksdb.stats property.
|
|
|
|
this->options.report_bg_io_stats = true;
|
|
|
|
|
2018-04-18 00:28:08 +02:00
|
|
|
// Set the compaction style; we don't override this in the descriptor yet.
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.compaction_style = rocksdb::kCompactionStyleNone;
|
2018-04-18 00:28:08 +02:00
|
|
|
this->options.compaction_style = rocksdb::kCompactionStyleLevel;
|
|
|
|
|
|
|
|
// Set the compaction priority; this should probably be in the descriptor
|
|
|
|
// but this is currently selected for the general matrix workload.
|
2018-10-19 01:34:11 +02:00
|
|
|
this->options.compaction_pri = rocksdb::CompactionPri::kOldestLargestSeqFirst;
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
// Set filter reductions for this column. This means we expect a key to exist.
|
2018-10-22 16:09:16 +02:00
|
|
|
this->options.optimize_filters_for_hits = this->descriptor->expect_queries_hit;
|
2018-04-18 00:28:08 +02:00
|
|
|
|
|
|
|
// Compression
|
2018-11-03 02:08:40 +01:00
|
|
|
this->options.compression = find_supported_compression(this->descriptor->compression);
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.compression = rocksdb::kNoCompression;
|
2017-09-23 03:48:35 +02:00
|
|
|
|
2018-04-20 22:38:49 +02:00
|
|
|
//TODO: descriptor / conf
|
2018-09-26 01:38:19 +02:00
|
|
|
this->options.num_levels = 7;
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.level0_file_num_compaction_trigger = 1;
|
2018-09-26 01:38:19 +02:00
|
|
|
this->options.target_file_size_base = 32_MiB;
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.max_bytes_for_level_base = 192_MiB;
|
2018-09-26 01:38:19 +02:00
|
|
|
this->options.target_file_size_multiplier = 2; // size at level
|
2018-09-23 00:16:45 +02:00
|
|
|
//this->options.max_bytes_for_level_multiplier = 3; // size at level
|
|
|
|
//this->options.write_buffer_size = 2_MiB;
|
|
|
|
//this->options.disable_auto_compactions = true;
|
2018-09-26 01:38:19 +02:00
|
|
|
//this->options.level_compaction_dynamic_level_bytes = true;
|
2018-04-20 22:38:49 +02:00
|
|
|
|
2018-08-21 09:20:54 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-09-03 05:42:33 +02:00
|
|
|
log, "schema '%s' column [%s => %s] cmp[%s] pfx[%s] lru:%s:%s bloom:%zu %s",
|
2018-10-22 16:09:16 +02:00
|
|
|
db::name(d),
|
2018-08-21 09:20:54 +02:00
|
|
|
demangle(key_type.name()),
|
|
|
|
demangle(mapped_type.name()),
|
|
|
|
this->cmp.Name(),
|
|
|
|
this->options.prefix_extractor? this->prefix.Name() : "none",
|
2018-09-03 05:42:33 +02:00
|
|
|
cache_size? "YES": "NO",
|
|
|
|
cache_size_comp? "YES": "NO",
|
2018-08-21 09:20:54 +02:00
|
|
|
bloom_bits,
|
2018-10-22 16:09:16 +02:00
|
|
|
this->descriptor->name
|
2018-08-21 09:20:54 +02:00
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::column::~column()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::column::operator
|
|
|
|
database &()
|
|
|
|
{
|
|
|
|
return *d;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::column::operator
|
|
|
|
rocksdb::ColumnFamilyHandle *()
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return handle.get();
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::column::operator
|
|
|
|
const database &()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return *d;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::column::operator
|
|
|
|
const rocksdb::ColumnFamilyHandle *()
|
|
|
|
const
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return handle.get();
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::snapshot
|
|
|
|
//
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::sequence(const database::snapshot &s)
|
|
|
|
{
|
|
|
|
const rocksdb::Snapshot *const rs(s);
|
2017-09-23 11:52:33 +02:00
|
|
|
return sequence(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::sequence(const rocksdb::Snapshot *const &rs)
|
|
|
|
{
|
|
|
|
return likely(rs)? rs->GetSequenceNumber() : 0ULL;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::snapshot::snapshot(database &d)
|
2017-08-23 22:37:47 +02:00
|
|
|
:s
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-08-23 22:37:47 +02:00
|
|
|
d.d->GetSnapshot(),
|
|
|
|
[dp(weak_from(d))](const rocksdb::Snapshot *const s)
|
|
|
|
{
|
|
|
|
if(!s)
|
|
|
|
return;
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
const auto d(dp.lock());
|
|
|
|
d->d->ReleaseSnapshot(s);
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::snapshot::~snapshot()
|
2017-03-24 02:36:49 +01:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::logs
|
|
|
|
//
|
|
|
|
|
2018-08-29 00:44:03 +02:00
|
|
|
ircd::db::database::logs::logs(database *const &d)
|
|
|
|
:rocksdb::Logger{}
|
|
|
|
,d{d}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::logs::~logs()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::logs::Close()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return rocksdb::Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
static
|
|
|
|
ircd::log::facility
|
|
|
|
translate(const rocksdb::InfoLogLevel &level)
|
|
|
|
{
|
|
|
|
switch(level)
|
|
|
|
{
|
|
|
|
// Treat all infomational messages from rocksdb as debug here for now.
|
|
|
|
// We can clean them up and make better reports for our users eventually.
|
|
|
|
default:
|
|
|
|
case rocksdb::InfoLogLevel::DEBUG_LEVEL: return ircd::log::facility::DEBUG;
|
|
|
|
case rocksdb::InfoLogLevel::INFO_LEVEL: return ircd::log::facility::DEBUG;
|
|
|
|
|
|
|
|
case rocksdb::InfoLogLevel::WARN_LEVEL: return ircd::log::facility::WARNING;
|
|
|
|
case rocksdb::InfoLogLevel::ERROR_LEVEL: return ircd::log::facility::ERROR;
|
|
|
|
case rocksdb::InfoLogLevel::FATAL_LEVEL: return ircd::log::facility::CRITICAL;
|
|
|
|
case rocksdb::InfoLogLevel::HEADER_LEVEL: return ircd::log::facility::NOTICE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::logs::Logv(const char *const fmt,
|
|
|
|
va_list ap)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
Logv(rocksdb::InfoLogLevel::DEBUG_LEVEL, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::logs::LogHeader(const char *const fmt,
|
|
|
|
va_list ap)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
Logv(rocksdb::InfoLogLevel::DEBUG_LEVEL, fmt, ap);
|
|
|
|
}
|
|
|
|
|
2017-10-01 12:06:48 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
|
2017-03-24 02:36:49 +01:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::logs::Logv(const rocksdb::InfoLogLevel level,
|
|
|
|
const char *const fmt,
|
|
|
|
va_list ap)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
if(level < GetInfoLogLevel())
|
|
|
|
return;
|
|
|
|
|
2018-01-12 07:21:51 +01:00
|
|
|
thread_local char buf[1024]; const auto len
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-08-23 23:37:06 +02:00
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap)
|
2017-03-24 02:36:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto str
|
|
|
|
{
|
|
|
|
// RocksDB adds annoying leading whitespace to attempt to right-justify things and idc
|
2017-12-26 12:00:52 +01:00
|
|
|
lstrip(string_view{buf, size_t(len)}, ' ')
|
2017-03-24 02:36:49 +01:00
|
|
|
};
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
// Skip the options for now
|
|
|
|
if(startswith(str, "Options"))
|
|
|
|
return;
|
|
|
|
|
2017-09-30 08:07:55 +02:00
|
|
|
rog(translate(level), "'%s': %s", d->name, str);
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
2017-10-01 12:06:48 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::mergeop
|
|
|
|
//
|
|
|
|
|
2018-08-29 00:44:03 +02:00
|
|
|
ircd::db::database::mergeop::mergeop(database *const &d,
|
|
|
|
merge_closure merger)
|
|
|
|
:d{d}
|
|
|
|
,merger
|
|
|
|
{
|
|
|
|
merger?
|
|
|
|
std::move(merger):
|
|
|
|
ircd::db::merge_operator
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::mergeop::~mergeop()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
const char *
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::mergeop::Name()
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
return "<unnamed>";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::mergeop::Merge(const rocksdb::Slice &_key,
|
|
|
|
const rocksdb::Slice *const _exist,
|
|
|
|
const rocksdb::Slice &_update,
|
|
|
|
std::string *const newval,
|
|
|
|
rocksdb::Logger *const)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept try
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
const string_view key
|
|
|
|
{
|
|
|
|
_key.data(), _key.size()
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view exist
|
|
|
|
{
|
|
|
|
_exist? string_view { _exist->data(), _exist->size() } : string_view{}
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view update
|
|
|
|
{
|
|
|
|
_update.data(), _update.size()
|
|
|
|
};
|
|
|
|
|
|
|
|
if(exist.empty())
|
|
|
|
{
|
|
|
|
*newval = std::string(update);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX caching opportunity?
|
|
|
|
*newval = merger(key, {exist, update}); // call the user
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(const std::bad_function_call &e)
|
|
|
|
{
|
|
|
|
log.critical("merge: missing merge operator (%s)", e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log.error("merge: %s", e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-05-24 02:03:09 +02:00
|
|
|
// db/stats.h
|
2017-04-03 06:02:32 +02:00
|
|
|
//
|
|
|
|
|
2018-05-24 01:57:49 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::string(const rocksdb::IOStatsContext &ic,
|
|
|
|
const bool &all)
|
|
|
|
{
|
|
|
|
const bool exclude_zeros(!all);
|
|
|
|
return ic.ToString(exclude_zeros);
|
|
|
|
}
|
|
|
|
|
|
|
|
const rocksdb::IOStatsContext &
|
|
|
|
ircd::db::iostats_current()
|
|
|
|
{
|
|
|
|
const auto *const &ret
|
|
|
|
{
|
|
|
|
rocksdb::get_iostats_context()
|
|
|
|
};
|
|
|
|
|
|
|
|
if(unlikely(!ret))
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"IO counters are not available on this thread."
|
|
|
|
};
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
2018-05-24 01:27:44 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::string(const rocksdb::PerfContext &pc,
|
|
|
|
const bool &all)
|
|
|
|
{
|
|
|
|
const bool exclude_zeros(!all);
|
|
|
|
return pc.ToString(exclude_zeros);
|
|
|
|
}
|
|
|
|
|
|
|
|
const rocksdb::PerfContext &
|
|
|
|
ircd::db::perf_current()
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2018-05-24 01:27:44 +02:00
|
|
|
const auto *const &ret
|
2018-04-09 21:55:22 +02:00
|
|
|
{
|
|
|
|
rocksdb::get_perf_context()
|
|
|
|
};
|
|
|
|
|
2018-05-24 01:27:44 +02:00
|
|
|
if(unlikely(!ret))
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Performance counters are not available on this thread."
|
|
|
|
};
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::perf_level(const uint &level)
|
|
|
|
{
|
|
|
|
if(level >= rocksdb::PerfLevel::kOutOfBounds)
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Perf level of '%u' is invalid; maximum is '%u'",
|
|
|
|
level,
|
|
|
|
uint(rocksdb::PerfLevel::kOutOfBounds)
|
|
|
|
};
|
|
|
|
|
|
|
|
rocksdb::SetPerfLevel(rocksdb::PerfLevel(level));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint
|
|
|
|
ircd::db::perf_level()
|
|
|
|
{
|
|
|
|
return rocksdb::GetPerfLevel();
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 07:05:29 +02:00
|
|
|
//
|
|
|
|
// ticker
|
|
|
|
//
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::ticker(const database &d,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
return ticker(d, ticker_id(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::ticker(const database &d,
|
|
|
|
const uint32_t &id)
|
|
|
|
{
|
|
|
|
return d.stats->getTickerCount(id);
|
|
|
|
}
|
|
|
|
|
2018-04-15 13:45:31 +02:00
|
|
|
uint32_t
|
|
|
|
ircd::db::ticker_id(const string_view &key)
|
|
|
|
{
|
|
|
|
for(const auto &pair : rocksdb::TickersNameMap)
|
|
|
|
if(key == pair.second)
|
|
|
|
return pair.first;
|
|
|
|
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"No ticker with that key"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::ticker_id(const uint32_t &id)
|
|
|
|
{
|
|
|
|
for(const auto &pair : rocksdb::TickersNameMap)
|
|
|
|
if(id == pair.first)
|
|
|
|
return pair.second;
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::db::ticker_max)
|
|
|
|
ircd::db::ticker_max
|
|
|
|
{
|
|
|
|
rocksdb::TICKER_ENUM_MAX
|
|
|
|
};
|
|
|
|
|
2018-09-26 07:05:29 +02:00
|
|
|
//
|
|
|
|
// histogram
|
|
|
|
//
|
|
|
|
|
|
|
|
const struct ircd::db::histogram &
|
|
|
|
ircd::db::histogram(const database &d,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
return histogram(d, histogram_id(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct ircd::db::histogram &
|
|
|
|
ircd::db::histogram(const database &d,
|
|
|
|
const uint32_t &id)
|
|
|
|
{
|
|
|
|
return d.stats->histogram.at(id);
|
|
|
|
}
|
|
|
|
|
2018-04-15 13:45:31 +02:00
|
|
|
uint32_t
|
|
|
|
ircd::db::histogram_id(const string_view &key)
|
|
|
|
{
|
|
|
|
for(const auto &pair : rocksdb::HistogramsNameMap)
|
|
|
|
if(key == pair.second)
|
|
|
|
return pair.first;
|
|
|
|
|
|
|
|
throw std::out_of_range
|
|
|
|
{
|
|
|
|
"No histogram with that key"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::histogram_id(const uint32_t &id)
|
|
|
|
{
|
|
|
|
for(const auto &pair : rocksdb::HistogramsNameMap)
|
|
|
|
if(id == pair.first)
|
|
|
|
return pair.second;
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::db::histogram_max)
|
|
|
|
ircd::db::histogram_max
|
|
|
|
{
|
|
|
|
rocksdb::HISTOGRAM_ENUM_MAX
|
|
|
|
};
|
|
|
|
|
2018-05-24 02:03:09 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::stats (db/database/stats.h) internal
|
|
|
|
//
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
//
|
|
|
|
// stats::stats
|
|
|
|
//
|
|
|
|
|
2018-09-26 06:20:02 +02:00
|
|
|
ircd::db::database::stats::stats(database *const &d)
|
|
|
|
:d{d}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
ircd::db::database::stats::~stats()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-26 06:20:02 +02:00
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::stats::Reset()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
ticker.fill(0);
|
|
|
|
histogram.fill({0.0});
|
|
|
|
return rocksdb::Status::OK();
|
|
|
|
}
|
|
|
|
|
2017-07-18 19:11:00 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::database::stats::getAndResetTickerCount(const uint32_t type)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-07-18 19:11:00 +02:00
|
|
|
{
|
|
|
|
const auto ret(getTickerCount(type));
|
|
|
|
setTickerCount(type, 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
bool
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::HistEnabledForType(const uint32_t type)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
return type < histogram.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::measureTime(const uint32_t type,
|
|
|
|
const uint64_t time)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-26 07:05:29 +02:00
|
|
|
auto &data(histogram.at(type));
|
|
|
|
|
|
|
|
data.time += time;
|
|
|
|
data.hits++;
|
|
|
|
|
|
|
|
data.max = std::max(data.max, double(time));
|
|
|
|
data.avg = data.time / static_cast<long double>(data.hits);
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::histogramData(const uint32_t type,
|
|
|
|
rocksdb::HistogramData *const data)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
assert(data);
|
2018-09-26 07:05:29 +02:00
|
|
|
const auto &h
|
|
|
|
{
|
|
|
|
histogram.at(type)
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2018-09-26 07:05:29 +02:00
|
|
|
data->median = h.median;
|
|
|
|
data->percentile95 = h.pct95;
|
|
|
|
data->percentile99 = h.pct99;
|
|
|
|
data->average = h.avg;
|
|
|
|
data->standard_deviation = h.stddev;
|
|
|
|
data->max = h.max;
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::recordTick(const uint32_t type,
|
|
|
|
const uint64_t count)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
ticker.at(type) += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::setTickerCount(const uint32_t type,
|
|
|
|
const uint64_t count)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
ticker.at(type) = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::stats::getTickerCount(const uint32_t type)
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
|
|
|
return ticker.at(type);
|
|
|
|
}
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
//
|
|
|
|
// database::stats::passthru
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::stats::passthru::passthru(rocksdb::Statistics *const &a,
|
|
|
|
rocksdb::Statistics *const &b)
|
|
|
|
:pass
|
|
|
|
{
|
|
|
|
{ a, b }
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::stats::passthru::~passthru()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::stats::passthru::Reset()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
throw assertive {"Unavailable for passthru"};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::stats::passthru::recordTick(const uint32_t tickerType,
|
|
|
|
const uint64_t count)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
for(auto *const &pass : this->pass)
|
|
|
|
pass->recordTick(tickerType, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::stats::passthru::measureTime(const uint32_t histogramType,
|
|
|
|
const uint64_t time)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
for(auto *const &pass : this->pass)
|
|
|
|
pass->measureTime(histogramType, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::stats::passthru::HistEnabledForType(const uint32_t type)
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
return std::all_of(begin(pass), end(pass), [&type]
|
|
|
|
(const auto *const &pass)
|
|
|
|
{
|
|
|
|
return pass->HistEnabledForType(type);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::stats::passthru::getTickerCount(const uint32_t tickerType)
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
throw assertive {"Unavailable for passthru"};
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
void
|
|
|
|
ircd::db::database::stats::passthru::setTickerCount(const uint32_t tickerType,
|
|
|
|
const uint64_t count)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
throw assertive {"Unavailable for passthru"};
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
void
|
|
|
|
ircd::db::database::stats::passthru::histogramData(const uint32_t type,
|
|
|
|
rocksdb::HistogramData *const data)
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
throw assertive {"Unavailable for passthru"};
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::stats::passthru::getAndResetTickerCount(const uint32_t tickerType)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
throw assertive {"Unavailable for passthru"};
|
|
|
|
}
|
|
|
|
|
2018-01-18 03:34:20 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::events
|
|
|
|
//
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnFlushCompleted(rocksdb::DB *const db,
|
|
|
|
const rocksdb::FlushJobInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
rog, "'%s' flush complete: column[%s] path[%s] ctx[%lu] job[%d] writes[slow:%d stop:%d] seq[%zu -> %zu] reason:%d",
|
|
|
|
d->name,
|
|
|
|
info.cf_name,
|
|
|
|
info.file_path,
|
|
|
|
info.thread_id,
|
|
|
|
info.job_id,
|
|
|
|
info.triggered_writes_slowdown,
|
|
|
|
info.triggered_writes_stop,
|
|
|
|
info.smallest_seqno,
|
|
|
|
info.largest_seqno,
|
|
|
|
int(info.flush_reason)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::events::OnFlushBegin(rocksdb::DB *const db,
|
|
|
|
const rocksdb::FlushJobInfo &info)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
log::info
|
|
|
|
{
|
2018-11-07 09:57:11 +01:00
|
|
|
rog, "'%s' flush begin column[%s] ctx[%lu] job[%d] writes[slow:%d stop:%d] seq[%zu -> %zu] reason:%d",
|
2018-09-19 03:04:41 +02:00
|
|
|
d->name,
|
|
|
|
info.cf_name,
|
|
|
|
info.thread_id,
|
|
|
|
info.job_id,
|
|
|
|
info.triggered_writes_slowdown,
|
|
|
|
info.triggered_writes_stop,
|
|
|
|
info.smallest_seqno,
|
|
|
|
info.largest_seqno,
|
|
|
|
int(info.flush_reason)
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnCompactionCompleted(rocksdb::DB *const db,
|
|
|
|
const rocksdb::CompactionJobInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::info
|
|
|
|
{
|
|
|
|
rog, "'%s' compacted column[%s] ctx[%lu] job[%d] level[in:%d out:%d] files[in:%zu out:%zu] reason:%d :%s",
|
|
|
|
d->name,
|
|
|
|
info.cf_name,
|
|
|
|
info.thread_id,
|
|
|
|
info.job_id,
|
|
|
|
info.base_input_level,
|
|
|
|
info.output_level,
|
|
|
|
info.input_files.size(),
|
|
|
|
info.output_files.size(),
|
|
|
|
int(info.compaction_reason),
|
|
|
|
info.status.ToString()
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
rog, "'%s': table file deleted: db[%s] path[%s] status[%d] job[%d]",
|
|
|
|
d->name,
|
|
|
|
info.db_name,
|
|
|
|
info.file_path,
|
|
|
|
int(info.status.code()),
|
|
|
|
info.job_id
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnTableFileCreated(const rocksdb::TableFileCreationInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
rog, "'%s': table file created: db[%s] path[%s] status[%d] job[%d]",
|
|
|
|
d->name,
|
|
|
|
info.db_name,
|
|
|
|
info.file_path,
|
|
|
|
int(info.status.code()),
|
|
|
|
info.job_id
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnTableFileCreationStarted(const rocksdb::TableFileCreationBriefInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
rog, "'%s': table file creating: db[%s] column[%s] path[%s] job[%d]",
|
|
|
|
d->name,
|
|
|
|
info.db_name,
|
|
|
|
info.cf_name,
|
|
|
|
info.file_path,
|
|
|
|
info.job_id
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnMemTableSealed(const rocksdb::MemTableInfo &info)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
rog, "'%s': memory table sealed: column[%s] entries[%lu] deletes[%lu]",
|
|
|
|
d->name,
|
|
|
|
info.cf_name,
|
|
|
|
info.num_entries,
|
|
|
|
info.num_deletes
|
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::events::OnColumnFamilyHandleDeletionStarted(rocksdb::ColumnFamilyHandle *const h)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2018-09-19 03:04:41 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
rog, "'%s': column[%s] handle closing @ %p",
|
|
|
|
d->name,
|
|
|
|
h->GetName(),
|
|
|
|
h
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::events::OnExternalFileIngested(rocksdb::DB *const d,
|
|
|
|
const rocksdb::ExternalFileIngestionInfo &info)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
rog, "'%s' external file ingested column[%s] external[%s] internal[%s] sequence:%lu",
|
|
|
|
this->d->name,
|
|
|
|
info.cf_name,
|
|
|
|
info.external_file_path,
|
|
|
|
info.internal_file_path,
|
|
|
|
info.global_seqno
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::events::OnBackgroundError(rocksdb::BackgroundErrorReason reason,
|
|
|
|
rocksdb::Status *const status)
|
|
|
|
noexcept
|
|
|
|
{
|
2018-10-31 23:29:00 +01:00
|
|
|
assert(d);
|
2018-09-19 03:04:41 +02:00
|
|
|
assert(status);
|
2018-10-31 23:29:00 +01:00
|
|
|
|
|
|
|
thread_local char buf[1024];
|
|
|
|
const string_view str{fmt::sprintf
|
2018-09-19 03:04:41 +02:00
|
|
|
{
|
2018-10-31 23:29:00 +01:00
|
|
|
buf, "%s error in %s :%s",
|
2018-10-31 22:48:14 +01:00
|
|
|
reflect(status->severity()),
|
2018-10-31 22:40:00 +01:00
|
|
|
reflect(reason),
|
2018-09-19 03:04:41 +02:00
|
|
|
status->ToString()
|
2018-10-31 23:29:00 +01:00
|
|
|
}};
|
2018-10-31 23:03:32 +01:00
|
|
|
|
|
|
|
// This is a legitimate when we want to use it. If the error is not
|
|
|
|
// suppressed the DB will enter read-only mode and will require a
|
|
|
|
// call to db::resume() to clear the error (i.e by admin at console).
|
|
|
|
const bool ignore
|
|
|
|
{
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2018-10-31 23:29:00 +01:00
|
|
|
const log::facility fac
|
|
|
|
{
|
|
|
|
ignore?
|
|
|
|
log::facility::DERROR:
|
|
|
|
log::facility::ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
log::logf
|
|
|
|
{
|
|
|
|
log, fac, "'%s': %s", d->name, str
|
|
|
|
};
|
|
|
|
|
2018-10-31 23:03:32 +01:00
|
|
|
if(ignore)
|
2018-10-31 23:29:00 +01:00
|
|
|
{
|
2018-10-31 23:03:32 +01:00
|
|
|
*status = rocksdb::Status::OK();
|
2018-10-31 23:29:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-02 08:05:21 +01:00
|
|
|
// Downgrade select fatal errors to hard errors. If this downgrade
|
|
|
|
// does not occur then it can never be cleared by a db::resume() and
|
|
|
|
// the daemon must be restarted.
|
|
|
|
|
|
|
|
if(reason == rocksdb::BackgroundErrorReason::kCompaction)
|
|
|
|
if(status->severity() == rocksdb::Status::kFatalError)
|
|
|
|
*status = rocksdb::Status(*status, rocksdb::Status::kHardError);
|
|
|
|
|
|
|
|
// Save the error string to the database instance for later examination.
|
2018-10-31 23:29:00 +01:00
|
|
|
d->errors.emplace_back(str);
|
2018-09-19 03:04:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::events::OnStallConditionsChanged(const rocksdb::WriteStallInfo &info)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
2018-10-31 22:22:31 +01:00
|
|
|
rog, "'%s' stall condition column[%s] %s -> %s",
|
2018-09-19 03:04:41 +02:00
|
|
|
d->name,
|
|
|
|
info.cf_name,
|
2018-10-31 22:40:00 +01:00
|
|
|
reflect(info.condition.prev),
|
|
|
|
reflect(info.condition.cur)
|
2018-09-19 03:04:41 +02:00
|
|
|
};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
|
|
|
|
2018-09-03 02:29:44 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::cache (internal)
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::db::database::cache::DEFAULT_SHARD_BITS)
|
|
|
|
ircd::db::database::cache::DEFAULT_SHARD_BITS
|
2018-09-26 11:03:31 +02:00
|
|
|
(
|
|
|
|
std::min(std::log2(size_t(db::request_pool_size)), 8.0)
|
|
|
|
);
|
2018-09-03 02:29:44 +02:00
|
|
|
|
|
|
|
decltype(ircd::db::database::cache::DEFAULT_STRICT)
|
|
|
|
ircd::db::database::cache::DEFAULT_STRICT
|
|
|
|
{
|
2018-09-03 12:24:37 +02:00
|
|
|
false
|
2018-09-03 02:29:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::db::database::cache::DEFAULT_HI_PRIO)
|
|
|
|
ircd::db::database::cache::DEFAULT_HI_PRIO
|
|
|
|
{
|
2018-10-14 17:53:46 +02:00
|
|
|
0.10
|
2018-09-03 02:29:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// cache::cache
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::cache::cache(database *const &d,
|
2018-10-21 08:30:27 +02:00
|
|
|
std::shared_ptr<struct database::stats> stats,
|
2018-09-03 02:29:44 +02:00
|
|
|
const ssize_t &initial_capacity)
|
|
|
|
:d{d}
|
2018-10-21 08:30:27 +02:00
|
|
|
,stats{std::move(stats)}
|
2018-09-03 02:29:44 +02:00
|
|
|
,c
|
|
|
|
{
|
|
|
|
rocksdb::NewLRUCache
|
|
|
|
(
|
2018-09-27 03:00:18 +02:00
|
|
|
std::max(initial_capacity, ssize_t(0))
|
|
|
|
,DEFAULT_SHARD_BITS
|
|
|
|
,DEFAULT_STRICT
|
|
|
|
,DEFAULT_HI_PRIO
|
2018-09-03 02:29:44 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
{
|
2018-09-27 03:00:18 +02:00
|
|
|
assert(bool(c));
|
2018-09-03 02:29:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::cache::~cache()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ircd::db::database::cache::Name()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->Name();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::cache::Insert(const Slice &key,
|
|
|
|
void *const value,
|
|
|
|
size_t charge,
|
|
|
|
deleter del,
|
|
|
|
Handle **const handle,
|
|
|
|
Priority priority)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
2018-10-21 08:30:27 +02:00
|
|
|
assert(bool(stats));
|
|
|
|
|
2018-09-05 11:56:50 +02:00
|
|
|
const rocksdb::Status &ret
|
|
|
|
{
|
|
|
|
c->Insert(key, value, charge, del, handle, priority)
|
|
|
|
};
|
|
|
|
|
2018-10-21 08:30:27 +02:00
|
|
|
stats->recordTick(rocksdb::Tickers::BLOCK_CACHE_ADD, ret.ok());
|
|
|
|
stats->recordTick(rocksdb::Tickers::BLOCK_CACHE_ADD_FAILURES, !ret.ok());
|
|
|
|
stats->recordTick(rocksdb::Tickers::BLOCK_CACHE_DATA_BYTES_INSERT, ret.ok()? charge : 0UL);
|
2018-09-05 11:56:50 +02:00
|
|
|
return ret;
|
2018-09-03 02:29:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Cache::Handle *
|
|
|
|
ircd::db::database::cache::Lookup(const Slice &key,
|
|
|
|
Statistics *const statistics)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
2018-10-21 08:30:27 +02:00
|
|
|
assert(bool(this->stats));
|
2018-09-27 03:00:18 +02:00
|
|
|
|
|
|
|
database::stats::passthru passthru
|
|
|
|
{
|
2018-10-21 08:30:27 +02:00
|
|
|
this->stats.get(), statistics
|
2018-09-27 03:00:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
rocksdb::Statistics *const s
|
|
|
|
{
|
|
|
|
statistics?
|
|
|
|
dynamic_cast<rocksdb::Statistics *>(&passthru):
|
2018-10-21 08:30:27 +02:00
|
|
|
dynamic_cast<rocksdb::Statistics *>(this->stats.get())
|
2018-09-27 03:00:18 +02:00
|
|
|
};
|
|
|
|
|
2018-09-05 11:56:50 +02:00
|
|
|
auto *const &ret
|
|
|
|
{
|
2018-09-27 03:00:18 +02:00
|
|
|
c->Lookup(key, s)
|
2018-09-05 11:56:50 +02:00
|
|
|
};
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
// Rocksdb's LRUCache stats are broke. The statistics ptr is null and
|
|
|
|
// passing it to Lookup() does nothing internally. We have to do this
|
|
|
|
// here ourselves :/
|
|
|
|
|
2018-10-21 08:30:27 +02:00
|
|
|
this->stats->recordTick(rocksdb::Tickers::BLOCK_CACHE_HIT, bool(ret));
|
|
|
|
this->stats->recordTick(rocksdb::Tickers::BLOCK_CACHE_MISS, !bool(ret));
|
2018-09-05 11:56:50 +02:00
|
|
|
return ret;
|
2018-09-03 02:29:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::cache::Ref(Handle *const handle)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->Ref(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::cache::Release(Handle *const handle,
|
|
|
|
bool force_erase)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->Release(handle, force_erase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
ircd::db::database::cache::Value(Handle *const handle)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->Value(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::Erase(const Slice &key)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->Erase(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::cache::NewId()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->NewId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::SetCapacity(size_t capacity)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->SetCapacity(capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::SetStrictCapacityLimit(bool strict_capacity_limit)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->SetStrictCapacityLimit(strict_capacity_limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::cache::HasStrictCapacityLimit()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->HasStrictCapacityLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::cache::GetCapacity()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->GetCapacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::cache::GetUsage()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->GetUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::cache::GetUsage(Handle *const handle)
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->GetUsage(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::cache::GetPinnedUsage()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->GetPinnedUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::DisownData()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->DisownData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::ApplyToAllCacheEntries(callback cb,
|
|
|
|
bool thread_safe)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->ApplyToAllCacheEntries(cb, thread_safe);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::EraseUnRefEntries()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->EraseUnRefEntries();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::database::cache::GetPrintableOptions()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->GetPrintableOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::cache::TEST_mark_as_data_block(const Slice &key,
|
|
|
|
size_t charge)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(bool(c));
|
|
|
|
return c->TEST_mark_as_data_block(key, charge);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:07:09 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::compaction_filter
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::compaction_filter::compaction_filter(column *const &c,
|
|
|
|
db::compactor user)
|
|
|
|
:c{c}
|
|
|
|
,d{c->d}
|
|
|
|
,user{std::move(user)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::compaction_filter::~compaction_filter()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::CompactionFilter::Decision
|
|
|
|
ircd::db::database::compaction_filter::FilterV2(const int level,
|
|
|
|
const Slice &key,
|
|
|
|
const ValueType type,
|
|
|
|
const Slice &oldval,
|
|
|
|
std::string *const newval,
|
|
|
|
std::string *const skip)
|
2018-09-20 01:55:29 +02:00
|
|
|
const noexcept
|
2018-09-19 00:07:09 +02:00
|
|
|
{
|
2018-09-20 01:55:29 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-09-19 00:07:09 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
const auto typestr
|
|
|
|
{
|
|
|
|
type == kValue?
|
|
|
|
"VALUE"_sv:
|
|
|
|
type == kMergeOperand?
|
|
|
|
"MERGE"_sv:
|
|
|
|
"BLOB"_sv
|
|
|
|
};
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s':'%s': compaction level:%d key:%zu@%p type:%s old:%zu@%p new:%p skip:%p",
|
|
|
|
d->name,
|
|
|
|
c->name,
|
|
|
|
level,
|
|
|
|
size(key),
|
|
|
|
data(key),
|
|
|
|
typestr,
|
|
|
|
size(oldval),
|
|
|
|
data(oldval),
|
|
|
|
(const void *)newval,
|
2018-10-18 17:00:57 +02:00
|
|
|
(const void *)skip
|
2018-09-19 00:07:09 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-09-20 01:35:28 +02:00
|
|
|
const db::compactor::callback &callback
|
2018-09-19 00:07:09 +02:00
|
|
|
{
|
2018-09-20 01:35:28 +02:00
|
|
|
type == ValueType::kValue && user.value?
|
|
|
|
user.value:
|
2018-09-19 00:07:09 +02:00
|
|
|
|
2018-09-20 01:35:28 +02:00
|
|
|
type == ValueType::kMergeOperand && user.merge?
|
|
|
|
user.merge:
|
2018-09-19 00:07:09 +02:00
|
|
|
|
2018-09-20 01:35:28 +02:00
|
|
|
compactor::callback{}
|
|
|
|
};
|
2018-09-19 00:07:09 +02:00
|
|
|
|
2018-09-20 01:35:28 +02:00
|
|
|
if(!callback)
|
|
|
|
return Decision::kKeep;
|
|
|
|
|
|
|
|
const compactor::args args
|
|
|
|
{
|
|
|
|
level, slice(key), slice(oldval), newval, skip
|
|
|
|
};
|
2018-09-19 00:07:09 +02:00
|
|
|
|
2018-09-20 01:35:28 +02:00
|
|
|
switch(callback(args))
|
2018-09-19 00:07:09 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case db::op::GET: return Decision::kKeep;
|
|
|
|
case db::op::SET: return Decision::kChangeValue;
|
|
|
|
case db::op::DELETE: return Decision::kRemove;
|
|
|
|
case db::op::DELETE_RANGE: return Decision::kRemoveAndSkipUntil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::compaction_filter::IgnoreSnapshots()
|
2018-09-20 01:55:29 +02:00
|
|
|
const noexcept
|
2018-09-19 00:07:09 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ircd::db::database::compaction_filter::Name()
|
2018-09-20 01:55:29 +02:00
|
|
|
const noexcept
|
2018-09-19 00:07:09 +02:00
|
|
|
{
|
|
|
|
assert(c);
|
|
|
|
return db::name(*c).c_str();
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:57:15 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-09-22 22:13:05 +02:00
|
|
|
// database::sst
|
2018-09-21 00:57:15 +02:00
|
|
|
//
|
|
|
|
|
2018-09-22 02:12:50 +02:00
|
|
|
void
|
2018-09-22 23:24:15 +02:00
|
|
|
ircd::db::database::sst::tool(const vector_view<const string_view> &args)
|
2018-09-22 02:12:50 +02:00
|
|
|
{
|
2018-09-23 00:26:41 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-09-22 22:13:05 +02:00
|
|
|
static const size_t ARG_MAX {16};
|
|
|
|
static const size_t ARG_MAX_LEN {256};
|
|
|
|
thread_local char arg[ARG_MAX][ARG_MAX_LEN]
|
2018-09-22 02:12:50 +02:00
|
|
|
{
|
|
|
|
"./sst_dump"
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i(0);
|
2018-09-22 22:13:05 +02:00
|
|
|
char *argv[ARG_MAX] { arg[i++] };
|
|
|
|
for(; i < ARG_MAX - 1 && i - 1 < args.size(); ++i)
|
2018-09-22 02:12:50 +02:00
|
|
|
{
|
|
|
|
strlcpy(arg[i], args.at(i - 1));
|
|
|
|
argv[i] = arg[i];
|
|
|
|
}
|
2018-09-22 22:13:05 +02:00
|
|
|
argv[i++] = nullptr;
|
|
|
|
assert(i <= ARG_MAX);
|
2018-09-22 02:12:50 +02:00
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
const int ret
|
|
|
|
{
|
|
|
|
tool.Run(i, argv)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(ret != 0)
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Error from SST dump tool: return value: %d", ret
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-22 23:24:15 +02:00
|
|
|
//
|
|
|
|
// sst::dump::dump
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::sst::dump::dump(db::column column,
|
|
|
|
const key_range &range,
|
|
|
|
const string_view &path_)
|
|
|
|
{
|
2018-09-23 00:26:41 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-09-22 23:24:15 +02:00
|
|
|
database::column &c(column);
|
2018-09-23 00:26:41 +02:00
|
|
|
const database &d(column);
|
|
|
|
|
2018-09-22 23:24:15 +02:00
|
|
|
std::string path{path_};
|
|
|
|
if(path.empty())
|
|
|
|
{
|
|
|
|
const string_view path_parts[]
|
|
|
|
{
|
|
|
|
fs::get(fs::DB), db::name(d), db::name(c)
|
|
|
|
};
|
|
|
|
|
|
|
|
path = fs::make_path(path_parts);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Options opts(d.d->GetOptions(c));
|
|
|
|
rocksdb::EnvOptions eopts(opts);
|
|
|
|
rocksdb::SstFileWriter writer
|
|
|
|
{
|
|
|
|
eopts, opts, c
|
|
|
|
};
|
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
writer.Open(path)
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i(0);
|
|
|
|
for(auto it(column.begin()); it != column.end(); ++it, ++i)
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
writer.Put(slice(it->first), slice(it->second))
|
|
|
|
};
|
|
|
|
|
|
|
|
rocksdb::ExternalSstFileInfo info;
|
|
|
|
if(i)
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
writer.Finish(&info)
|
|
|
|
};
|
|
|
|
|
|
|
|
this->info.column = db::name(column);
|
|
|
|
this->info.path = std::move(info.file_path);
|
|
|
|
this->info.min_key = std::move(info.smallest_key);
|
|
|
|
this->info.max_key = std::move(info.largest_key);
|
|
|
|
this->info.min_seq = info.sequence_number;
|
|
|
|
this->info.max_seq = info.sequence_number;
|
|
|
|
this->info.size = info.file_size;
|
|
|
|
this->info.entries = info.num_entries;
|
|
|
|
this->info.version = info.version;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:57:15 +02:00
|
|
|
//
|
2018-09-22 22:13:05 +02:00
|
|
|
// sst::info::vector
|
2018-09-21 00:57:15 +02:00
|
|
|
//
|
|
|
|
|
2018-09-22 22:13:05 +02:00
|
|
|
ircd::db::database::sst::info::vector::vector(const database &d)
|
2018-09-21 00:57:15 +02:00
|
|
|
{
|
2018-10-21 18:15:44 +02:00
|
|
|
this->reserve(db::file_count(d));
|
|
|
|
for(const auto &c : d.columns)
|
|
|
|
{
|
|
|
|
db::column column{*c};
|
|
|
|
for(auto &&info : vector(column))
|
|
|
|
this->emplace_back(std::move(info));
|
|
|
|
}
|
2018-09-21 00:57:15 +02:00
|
|
|
}
|
|
|
|
|
2018-09-25 07:26:44 +02:00
|
|
|
ircd::db::database::sst::info::vector::vector(const db::column &column)
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
database::column &c(const_cast<db::column &>(column));
|
|
|
|
database &d(*c.d);
|
|
|
|
|
|
|
|
rocksdb::ColumnFamilyMetaData cfmd;
|
|
|
|
d.d->GetColumnFamilyMetaData(c, &cfmd);
|
2018-10-21 17:08:12 +02:00
|
|
|
|
2018-10-21 18:15:44 +02:00
|
|
|
rocksdb::TablePropertiesCollection tpc;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->GetPropertiesOfAllTables(c, &tpc)
|
|
|
|
};
|
|
|
|
|
2018-10-21 17:08:12 +02:00
|
|
|
size_t i(0);
|
2018-10-21 18:15:44 +02:00
|
|
|
this->resize(std::max(cfmd.file_count, tpc.size()));
|
2018-09-25 07:26:44 +02:00
|
|
|
for(rocksdb::LevelMetaData &level : cfmd.levels)
|
|
|
|
for(rocksdb::SstFileMetaData md : level.files)
|
|
|
|
{
|
2018-10-21 17:08:12 +02:00
|
|
|
auto &info(this->at(i++));
|
|
|
|
info.operator=(std::move(md));
|
|
|
|
info.level = level.level;
|
2018-10-21 18:15:44 +02:00
|
|
|
|
|
|
|
const auto path(info.path + info.name);
|
|
|
|
auto tp(*tpc.at(path));
|
|
|
|
info.operator=(std::move(tp));
|
|
|
|
tpc.erase(path);
|
2018-09-25 07:26:44 +02:00
|
|
|
}
|
2018-10-21 18:15:44 +02:00
|
|
|
|
|
|
|
for(auto &&kv : tpc)
|
|
|
|
{
|
|
|
|
auto &info(this->at(i++));
|
|
|
|
auto tp(*kv.second);
|
|
|
|
info.operator=(std::move(tp));
|
|
|
|
info.path = kv.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(i == this->size());
|
2018-09-25 07:26:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:57:15 +02:00
|
|
|
//
|
2018-09-22 23:24:15 +02:00
|
|
|
// sst::info::info
|
2018-09-21 00:57:15 +02:00
|
|
|
//
|
|
|
|
|
2018-10-21 18:15:44 +02:00
|
|
|
ircd::db::database::sst::info::info(const database &d_,
|
2018-09-22 22:13:05 +02:00
|
|
|
const string_view &filename)
|
2018-09-21 00:57:15 +02:00
|
|
|
{
|
2018-10-21 18:15:44 +02:00
|
|
|
auto &d(const_cast<database &>(d_));
|
2018-09-23 00:26:41 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-10-21 18:15:44 +02:00
|
|
|
|
2018-09-21 00:57:15 +02:00
|
|
|
std::vector<rocksdb::LiveFileMetaData> v;
|
|
|
|
d.d->GetLiveFilesMetaData(&v);
|
|
|
|
|
|
|
|
for(auto &md : v)
|
|
|
|
if(md.name == filename)
|
|
|
|
{
|
2018-10-21 18:15:44 +02:00
|
|
|
rocksdb::TablePropertiesCollection tpc;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->GetPropertiesOfAllTables(d[md.column_family_name], &tpc)
|
|
|
|
};
|
|
|
|
|
|
|
|
auto tp(*tpc.at(md.db_path + md.name));
|
2018-10-21 17:08:12 +02:00
|
|
|
this->operator=(std::move(md));
|
2018-10-21 18:15:44 +02:00
|
|
|
this->operator=(std::move(tp));
|
2018-09-21 00:57:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"No file named '%s' is live in database '%s'",
|
|
|
|
filename,
|
|
|
|
d.name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-21 17:08:12 +02:00
|
|
|
ircd::db::database::sst::info &
|
|
|
|
ircd::db::database::sst::info::operator=(rocksdb::LiveFileMetaData &&md)
|
|
|
|
{
|
|
|
|
name = std::move(md.name);
|
|
|
|
path = std::move(md.db_path);
|
|
|
|
column = std::move(md.column_family_name);
|
|
|
|
size = std::move(md.size);
|
|
|
|
min_seq = std::move(md.smallest_seqno);
|
|
|
|
max_seq = std::move(md.largest_seqno);
|
|
|
|
min_key = std::move(md.smallestkey);
|
|
|
|
max_key = std::move(md.largestkey);
|
|
|
|
num_reads = std::move(md.num_reads_sampled);
|
|
|
|
level = std::move(md.level);
|
|
|
|
compacting = std::move(md.being_compacted);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::sst::info &
|
|
|
|
ircd::db::database::sst::info::operator=(rocksdb::SstFileMetaData &&md)
|
|
|
|
{
|
|
|
|
name = std::move(md.name);
|
|
|
|
path = std::move(md.db_path);
|
|
|
|
size = std::move(md.size);
|
|
|
|
min_seq = std::move(md.smallest_seqno);
|
|
|
|
max_seq = std::move(md.largest_seqno);
|
|
|
|
min_key = std::move(md.smallestkey);
|
|
|
|
max_key = std::move(md.largestkey);
|
|
|
|
num_reads = std::move(md.num_reads_sampled);
|
|
|
|
compacting = std::move(md.being_compacted);
|
|
|
|
return *this;
|
2018-09-25 07:26:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 18:15:44 +02:00
|
|
|
ircd::db::database::sst::info &
|
|
|
|
ircd::db::database::sst::info::operator=(rocksdb::TableProperties &&tp)
|
|
|
|
{
|
|
|
|
column = std::move(tp.column_family_name);
|
|
|
|
filter = std::move(tp.filter_policy_name);
|
|
|
|
comparator = std::move(tp.comparator_name);
|
|
|
|
merge_operator = std::move(tp.merge_operator_name);
|
|
|
|
prefix_extractor = std::move(tp.prefix_extractor_name);
|
|
|
|
compression = std::move(tp.compression_name);
|
|
|
|
format = std::move(tp.format_version);
|
|
|
|
cfid = std::move(tp.column_family_id);
|
|
|
|
data_size = std::move(tp.data_size);
|
|
|
|
index_size = std::move(tp.index_size);
|
|
|
|
top_index_size = std::move(tp.top_level_index_size);
|
|
|
|
filter_size = std::move(tp.filter_size);
|
|
|
|
keys_size = std::move(tp.raw_key_size);
|
|
|
|
values_size = std::move(tp.raw_value_size);
|
|
|
|
index_parts = std::move(tp.index_partitions);
|
|
|
|
data_blocks = std::move(tp.num_data_blocks);
|
|
|
|
entries = std::move(tp.num_entries);
|
|
|
|
range_deletes = std::move(tp.num_range_deletions);
|
|
|
|
fixed_key_len = std::move(tp.fixed_key_len);
|
|
|
|
created = std::move(tp.creation_time);
|
|
|
|
oldest_key = std::move(tp.oldest_key_time);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// database::env
|
|
|
|
//
|
|
|
|
|
2018-01-18 05:17:00 +01:00
|
|
|
//
|
2018-08-28 23:04:43 +02:00
|
|
|
// env::state
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::env::state::state(database *const &d)
|
|
|
|
:d{*d}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::state::~state()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
for(auto &p : pool) try
|
|
|
|
{
|
|
|
|
p.terminate();
|
|
|
|
p.join();
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// env::env
|
2018-01-18 05:17:00 +01:00
|
|
|
//
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
ircd::db::database::env::env(database *const &d)
|
2018-06-09 22:40:21 +02:00
|
|
|
:d{*d},
|
|
|
|
st{std::make_unique<state>(d)}
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::~env()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::NewSequentialFile(const std::string &name,
|
2018-08-23 10:10:30 +02:00
|
|
|
std::unique_ptr<SequentialFile> *const r,
|
|
|
|
const EnvOptions &options)
|
2018-08-24 03:57:24 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 10:10:30 +02:00
|
|
|
log::debug
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-23 10:10:30 +02:00
|
|
|
log, "'%s': new sequential file '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
&options
|
2018-01-18 06:24:32 +01:00
|
|
|
};
|
2018-08-23 10:10:30 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-23 10:10:30 +02:00
|
|
|
*r = std::make_unique<sequential_file>(&d, name, options);
|
|
|
|
return Status::OK();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 03:57:24 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::NewRandomAccessFile(const std::string &name,
|
2018-08-23 10:54:58 +02:00
|
|
|
std::unique_ptr<RandomAccessFile> *const r,
|
|
|
|
const EnvOptions &options)
|
2018-08-24 03:57:24 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-20 03:56:50 +02:00
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-16 13:49:23 +02:00
|
|
|
log, "'%s': new random access file '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
&options
|
2018-01-18 06:24:32 +01:00
|
|
|
};
|
2018-08-16 13:49:23 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-16 13:49:23 +02:00
|
|
|
*r = std::make_unique<random_access_file>(&d, name, options);
|
|
|
|
return Status::OK();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 03:57:24 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::NewWritableFile(const std::string &name,
|
|
|
|
std::unique_ptr<WritableFile> *const r,
|
|
|
|
const EnvOptions &options)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': new writable file '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
&options
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
if(options.use_direct_writes)
|
|
|
|
*r = std::make_unique<writable_file_direct>(&d, name, options, true);
|
|
|
|
else
|
|
|
|
*r = std::make_unique<writable_file>(&d, name, options, true);
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-08-24 06:31:46 +02:00
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::ReopenWritableFile(const std::string &name,
|
2018-08-24 06:32:28 +02:00
|
|
|
std::unique_ptr<WritableFile> *const r,
|
2018-08-24 06:31:46 +02:00
|
|
|
const EnvOptions &options)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
log, "'%s': reopen writable file '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
&options
|
2018-01-18 05:17:00 +01:00
|
|
|
};
|
2018-08-24 06:31:46 +02:00
|
|
|
#endif
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
if(options.use_direct_writes)
|
|
|
|
*r = std::make_unique<writable_file_direct>(&d, name, options, false);
|
|
|
|
else
|
|
|
|
*r = std::make_unique<writable_file>(&d, name, options, false);
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::ReuseWritableFile(const std::string &name,
|
|
|
|
const std::string &old_name,
|
|
|
|
std::unique_ptr<WritableFile> *const r,
|
|
|
|
const EnvOptions &options)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': reuse writable file '%s' old '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
old_name,
|
|
|
|
&options
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
assert(0);
|
|
|
|
return Status::OK();
|
|
|
|
//return defaults.ReuseWritableFile(name, old_name, r, options);
|
2018-08-24 06:31:46 +02:00
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::NewRandomRWFile(const std::string &name,
|
|
|
|
std::unique_ptr<RandomRWFile> *const result,
|
|
|
|
const EnvOptions &options)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
log, "'%s': new random read/write file '%s' options:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
&options
|
2018-01-18 06:24:32 +01:00
|
|
|
};
|
2018-08-24 06:31:46 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
*result = std::make_unique<random_rw_file>(&d, name, options);
|
|
|
|
return Status::OK();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::NewDirectory(const std::string &name,
|
|
|
|
std::unique_ptr<Directory> *const result)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': new directory '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-01-18 06:24:32 +01:00
|
|
|
std::unique_ptr<Directory> defaults;
|
|
|
|
const auto ret
|
|
|
|
{
|
|
|
|
this->defaults.NewDirectory(name, &defaults)
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = std::make_unique<directory>(&d, name, std::move(defaults));
|
|
|
|
return ret;
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::FileExists(const std::string &f)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': file exists '%s'",
|
|
|
|
d.name,
|
|
|
|
f
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.FileExists(f);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetChildren(const std::string &dir,
|
|
|
|
std::vector<std::string> *const r)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get children of directory '%s'",
|
|
|
|
d.name,
|
|
|
|
dir
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.GetChildren(dir, r);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetChildrenFileAttributes(const std::string &dir,
|
|
|
|
std::vector<FileAttributes> *const result)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get children file attributes of directory '%s'",
|
|
|
|
d.name,
|
|
|
|
dir
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.GetChildrenFileAttributes(dir, result);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::DeleteFile(const std::string &name)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': delete file '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.DeleteFile(name);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::CreateDir(const std::string &name)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': create directory '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.CreateDir(name);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::CreateDirIfMissing(const std::string &name)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': create directory if missing '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.CreateDirIfMissing(name);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::DeleteDir(const std::string &name)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': delete directory '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.DeleteDir(name);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-23 13:20:42 +02:00
|
|
|
ircd::db::database::env::GetFileSize(const std::string &name,
|
|
|
|
uint64_t *const s)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 13:20:42 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get file size '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-23 13:20:42 +02:00
|
|
|
assert(s);
|
|
|
|
*s = fs::size(name);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetFileModificationTime(const std::string &name,
|
|
|
|
uint64_t *const file_mtime)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get file mtime '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.GetFileModificationTime(name, file_mtime);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::RenameFile(const std::string &s,
|
|
|
|
const std::string &t)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rename file '%s' to '%s'",
|
|
|
|
d.name,
|
|
|
|
s,
|
|
|
|
t
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.RenameFile(s, t);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::LinkFile(const std::string &s,
|
|
|
|
const std::string &t)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': link file '%s' to '%s'",
|
|
|
|
d.name,
|
|
|
|
s,
|
|
|
|
t
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.LinkFile(s, t);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::LockFile(const std::string &name,
|
2018-01-18 04:22:35 +01:00
|
|
|
FileLock** l)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': lock file '%s'",
|
|
|
|
d.name,
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.LockFile(name, l);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::UnlockFile(FileLock *const l)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': unlock file lock:%p",
|
|
|
|
d.name,
|
|
|
|
l
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
return defaults.UnlockFile(l);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetTestDirectory(std::string *const path)
|
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
return defaults.GetTestDirectory(path);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetAbsolutePath(const std::string &db_path,
|
|
|
|
std::string *const output_path)
|
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get absolute path from '%s' ret:%p",
|
|
|
|
d.name,
|
|
|
|
db_path,
|
|
|
|
output_path
|
|
|
|
};
|
2018-06-01 15:23:39 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return defaults.GetAbsolutePath(db_path, output_path);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::NewLogger(const std::string &name,
|
|
|
|
std::shared_ptr<Logger> *const result)
|
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-08-16 10:27:43 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': new logger '%s' result:%p",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
(const void *)result
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
return defaults.NewLogger(name, result);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetHostName(char *const name,
|
2018-06-01 15:23:39 +02:00
|
|
|
uint64_t len)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get host name name:%p len:%lu",
|
|
|
|
d.name,
|
|
|
|
name,
|
|
|
|
len
|
|
|
|
};
|
2018-06-01 15:23:39 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return defaults.GetHostName(name, len);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::env::NowMicros()
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
|
|
|
return defaults.NowMicros();
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"'%s': now micros :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetCurrentTime(int64_t *const unix_time)
|
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
|
|
|
return defaults.GetCurrentTime(unix_time);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::database::env::TimeToString(uint64_t time)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
|
|
|
return defaults.TimeToString(time);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"'%s': time to string :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::SleepForMicroseconds(int micros)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-06-01 15:23:39 +02:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-01 15:23:39 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 11:14:50 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
"'%s': sleep for %d microseconds",
|
|
|
|
d.name,
|
|
|
|
micros
|
|
|
|
};
|
2018-06-01 15:23:39 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-23 11:14:50 +02:00
|
|
|
ctx::sleep(microseconds(micros));
|
2018-06-01 15:23:39 +02:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': sleep micros:%d :%s",
|
|
|
|
d.name,
|
|
|
|
micros,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-06-01 15:23:39 +02:00
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
void
|
|
|
|
ircd::db::database::env::Schedule(void (*f)(void* arg),
|
2018-08-24 06:31:46 +02:00
|
|
|
void *const a,
|
2018-01-18 04:22:35 +01:00
|
|
|
Priority prio,
|
2018-08-24 06:31:46 +02:00
|
|
|
void *const tag,
|
2018-01-18 04:22:35 +01:00
|
|
|
void (*u)(void* arg))
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': schedule func:%p a:%p tag:%p u:%p prio:%s",
|
|
|
|
d.name,
|
|
|
|
f,
|
|
|
|
a,
|
|
|
|
tag,
|
|
|
|
u,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
auto &pool
|
|
|
|
{
|
|
|
|
st->pool.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
auto &tasks
|
|
|
|
{
|
|
|
|
st->tasks.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
tasks.emplace_back(state::task
|
|
|
|
{
|
|
|
|
f, u, a
|
|
|
|
});
|
|
|
|
|
|
|
|
pool([this, &tasks]
|
|
|
|
{
|
2018-08-17 23:00:21 +02:00
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(this->st);
|
|
|
|
if(tasks.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto task
|
|
|
|
{
|
|
|
|
std::move(tasks.front())
|
|
|
|
};
|
|
|
|
|
|
|
|
tasks.pop_front();
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': func:%p arg:%p",
|
|
|
|
this->d.name,
|
|
|
|
task.func,
|
|
|
|
task.arg,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Execute the task
|
|
|
|
task.func(task.arg);
|
|
|
|
});
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': schedule func:%p a:%p tag:%p u:%p prio:%s",
|
|
|
|
d.name,
|
|
|
|
f,
|
|
|
|
a,
|
|
|
|
tag,
|
|
|
|
u,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
int
|
2018-08-16 13:48:21 +02:00
|
|
|
ircd::db::database::env::UnSchedule(void *const tag,
|
|
|
|
const Priority prio)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-17 23:00:21 +02:00
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': unschedule tag:%p prio:%s",
|
|
|
|
d.name,
|
|
|
|
tag,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
auto &tasks
|
|
|
|
{
|
|
|
|
st->tasks.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i(0);
|
|
|
|
for(auto it(begin(tasks)); it != end(tasks); it = tasks.erase(it), ++i)
|
|
|
|
it->cancel(it->arg);
|
|
|
|
|
|
|
|
return i;
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': unschedule tag:%p prio:%s :%s",
|
|
|
|
d.name,
|
|
|
|
tag,
|
|
|
|
reflect(prio),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::StartThread(void (*f)(void*),
|
2018-08-24 06:31:46 +02:00
|
|
|
void *const a)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': start thread func:%p a:%p",
|
|
|
|
d.name,
|
|
|
|
f,
|
|
|
|
a
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-23 11:19:28 +02:00
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"Independent (non-pool) context spawning not yet implemented"
|
|
|
|
};
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::WaitForJoin()
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-01 21:26:05 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wait for all ctx to join",
|
|
|
|
d.name
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-23 11:16:44 +02:00
|
|
|
assert(st);
|
|
|
|
for(auto &pool : st->pool)
|
|
|
|
pool.join();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wait for join :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
unsigned int
|
2018-08-16 13:48:21 +02:00
|
|
|
ircd::db::database::env::GetThreadPoolQueueLen(Priority prio)
|
2018-08-24 06:31:46 +02:00
|
|
|
const noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get thread pool queue len prio:%s",
|
|
|
|
d.name,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
const auto &pool
|
|
|
|
{
|
|
|
|
st->pool.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
return pool.queued();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"'%s': set background threads :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::SetBackgroundThreads(int num,
|
2018-08-16 13:48:21 +02:00
|
|
|
Priority prio)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-20 03:56:50 +02:00
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': set background threads num:%d prio:%s",
|
|
|
|
d.name,
|
|
|
|
num,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
auto &pool
|
|
|
|
{
|
|
|
|
st->pool.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &size
|
|
|
|
{
|
|
|
|
ssize_t(pool.size())
|
|
|
|
};
|
|
|
|
|
|
|
|
if(size > num)
|
|
|
|
pool.del(size - num);
|
|
|
|
else if(size < num)
|
|
|
|
pool.add(num - size);
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': set background threads :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::IncBackgroundThreadsIfNeeded(int num,
|
2018-08-16 13:48:21 +02:00
|
|
|
Priority prio)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-20 03:56:50 +02:00
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:48:21 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': increase background threads num:%d prio:%s",
|
|
|
|
d.name,
|
|
|
|
num,
|
|
|
|
reflect(prio)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
auto &pool
|
|
|
|
{
|
|
|
|
st->pool.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
pool.add(num);
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': inc background threads num:%d prio:%s :%s",
|
|
|
|
d.name,
|
|
|
|
num,
|
|
|
|
reflect(prio),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::LowerThreadPoolIOPriority(Priority pool)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': lower thread pool priority prio:%s",
|
|
|
|
d.name,
|
|
|
|
reflect(pool)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
defaults.LowerThreadPoolIOPriority(pool);
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': lower thread pool IO priority pool:%s :%s",
|
|
|
|
d.name,
|
|
|
|
reflect(pool),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:31:46 +02:00
|
|
|
ircd::db::database::env::GetThreadList(std::vector<ThreadStatus> *const list)
|
|
|
|
noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-02 18:18:01 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get thread list %p (%zu)",
|
|
|
|
d.name,
|
2018-08-24 06:31:46 +02:00
|
|
|
list,
|
|
|
|
list? list->size() : 0UL
|
2018-06-02 18:18:01 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 06:31:46 +02:00
|
|
|
assert(0);
|
|
|
|
return defaults.GetThreadList(list);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': get thread list:%p :%s",
|
|
|
|
d.name,
|
|
|
|
list,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:31:46 +02:00
|
|
|
rocksdb::ThreadStatusUpdater *
|
2018-01-18 04:22:35 +01:00
|
|
|
ircd::db::database::env::GetThreadStatusUpdater()
|
2018-08-24 06:31:46 +02:00
|
|
|
const noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-08-24 06:31:46 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-06-02 18:18:01 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get thread status updater",
|
|
|
|
d.name,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
return defaults.GetThreadStatusUpdater();
|
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': get thread status updater :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:22:35 +01:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::env::GetThreadID()
|
2018-08-24 06:31:46 +02:00
|
|
|
const noexcept try
|
2018-01-18 04:22:35 +01:00
|
|
|
{
|
2018-06-02 18:18:01 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get thread ID",
|
|
|
|
d.name,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
return ctx::this_ctx::id();
|
2018-01-18 04:22:35 +01:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"'%s': get thread id :%s",
|
|
|
|
d.name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-01-18 04:22:35 +01:00
|
|
|
|
2018-04-09 21:55:22 +02:00
|
|
|
int
|
2018-08-16 13:48:21 +02:00
|
|
|
ircd::db::database::env::GetBackgroundThreads(Priority prio)
|
2018-08-24 06:31:46 +02:00
|
|
|
noexcept try
|
2018-04-09 21:55:22 +02:00
|
|
|
{
|
2018-06-02 18:18:01 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': get background threads prio:%s",
|
|
|
|
d.name,
|
2018-08-16 13:48:21 +02:00
|
|
|
reflect(prio)
|
2018-06-02 18:18:01 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-16 13:48:21 +02:00
|
|
|
assert(st);
|
|
|
|
const auto &pool
|
|
|
|
{
|
|
|
|
st->pool.at(prio)
|
|
|
|
};
|
|
|
|
|
|
|
|
return pool.size();
|
2018-04-09 21:55:22 +02:00
|
|
|
}
|
2018-08-24 06:31:46 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': get background threads prio:%s :%s",
|
|
|
|
d.name,
|
|
|
|
reflect(prio),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-04-09 21:55:22 +02:00
|
|
|
|
2018-01-18 05:17:00 +01:00
|
|
|
//
|
|
|
|
// writable_file
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::env::writable_file::writable_file(database *const &d,
|
|
|
|
const std::string &name,
|
2018-08-24 06:32:28 +02:00
|
|
|
const EnvOptions &env_opts,
|
|
|
|
const bool &trunc)
|
|
|
|
try
|
|
|
|
:d
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
*d
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
,env_opts
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
env_opts
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
,opts{[this, &trunc]
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
fs::fd::opts ret
|
|
|
|
{
|
2018-09-13 12:01:06 +02:00
|
|
|
std::ios::out |
|
|
|
|
(trunc? std::ios::trunc : std::ios::openmode(0))
|
2018-08-24 06:32:28 +02:00
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
ret.direct = this->env_opts.use_direct_writes;
|
|
|
|
ret.cloexec = this->env_opts.set_fd_cloexec;
|
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,fd
|
|
|
|
{
|
|
|
|
name, this->opts
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-11-02 09:07:42 +01:00
|
|
|
,preallocation_block_size
|
|
|
|
{
|
2018-11-10 03:24:51 +01:00
|
|
|
ircd::info::page_size
|
2018-10-31 22:09:10 +01:00
|
|
|
}
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-10 03:24:51 +01:00
|
|
|
log, "'%s': opened wfile:%p fd:%d '%s'",
|
2018-08-24 06:32:28 +02:00
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': opening wfile:%p `%s' :%s",
|
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::writable_file::~writable_file()
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-11-10 03:24:51 +01:00
|
|
|
Close();
|
2018-11-02 09:07:42 +01:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': closed wfile:%p fd:%d",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::Close()
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-11-02 09:07:42 +01:00
|
|
|
std::unique_lock<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
if(!fd)
|
|
|
|
return Status::OK();
|
2018-08-24 06:32:28 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d close",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
fd = fs::fd{};
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::writable_file::Flush()
|
|
|
|
noexcept try
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d flush",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fdsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d flush :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d flush :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::Sync()
|
|
|
|
noexcept try
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p sync",
|
|
|
|
d.name,
|
|
|
|
this
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fdsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p sync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p sync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::Fsync()
|
|
|
|
noexcept try
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fsync",
|
|
|
|
d.name,
|
|
|
|
this
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fsync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 05:17:00 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fsync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 05:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::RangeSync(uint64_t offset,
|
|
|
|
uint64_t length)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
2018-08-23 10:10:30 +02:00
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
"'%s': wfile:%p fd:%d range sync offset:%lu length:%lu",
|
|
|
|
d.name,
|
2018-08-23 10:10:30 +02:00
|
|
|
this,
|
|
|
|
int(fd),
|
2018-08-24 06:32:28 +02:00
|
|
|
offset,
|
|
|
|
length
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
|
|
|
#endif
|
2018-08-24 06:32:28 +02:00
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return Status::NotSupported();
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d range sync offset:%zu length:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::critical
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': wfile:%p fd:%d range sync offset:%zu length:%zu :%s",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
e.what()
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
2018-08-24 06:32:28 +02:00
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::Truncate(uint64_t size)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
"'%s': wfile:%p fd:%d truncate to %lu bytes",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
fs::truncate(fd, size, wopts);
|
2018-11-02 09:07:42 +01:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d truncate to %lu bytes :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d truncate to %lu bytes :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file::InvalidateCache(size_t offset,
|
|
|
|
size_t length)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d invalidate cache offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:30:15 +01:00
|
|
|
if(opts.direct)
|
|
|
|
return Status::OK();
|
|
|
|
|
|
|
|
#if defined(HAVE_POSIX_FADVISE) && defined(FADV_DONTNEED)
|
|
|
|
syscall(::posix_fadvise, fd, offset, length, FADV_DONTNEED);
|
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d invalidate cache offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p fd:%d invalidate cache offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:24:32 +01:00
|
|
|
rocksdb::Status
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::writable_file::Append(const Slice &s)
|
2018-08-23 10:10:30 +02:00
|
|
|
noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-11-28 02:30:59 +01:00
|
|
|
assert(!opts.direct);
|
2018-08-23 10:10:30 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-08-24 06:32:28 +02:00
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
2018-08-23 10:10:30 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 10:10:30 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-10 03:24:51 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d append:%p bytes:%zu",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
2018-11-02 09:07:42 +01:00
|
|
|
size(s),
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
2018-08-24 06:32:28 +02:00
|
|
|
const const_buffer buf
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
data(s), size(s)
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
fs::append(fd, buf, wopts);
|
2018-08-23 10:10:30 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
2018-08-23 13:20:16 +02:00
|
|
|
catch(const fs::error &e)
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': wfile:%p fd:%d append:%p size:%zu :%s",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
2018-08-23 10:10:30 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
2018-08-23 13:20:16 +02:00
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': wfile:%p fd:%d append:%p size:%zu :%s",
|
2018-08-23 13:20:16 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
2018-08-23 13:20:16 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::writable_file::PositionedAppend(const Slice &s,
|
|
|
|
uint64_t offset)
|
2018-08-23 10:10:30 +02:00
|
|
|
noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-11-28 02:30:59 +01:00
|
|
|
assert(!opts.direct);
|
2018-08-23 10:10:30 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-08-24 06:32:28 +02:00
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
2018-08-23 10:10:30 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 10:10:30 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
"'%s': wfile:%p fd:%d append:%p bytes:%zu offset:%lu",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
|
|
|
offset
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
wopts.offset = offset;
|
|
|
|
const const_buffer buf
|
|
|
|
{
|
|
|
|
data(s), size(s)
|
|
|
|
};
|
|
|
|
|
|
|
|
fs::append(fd, buf, wopts);
|
|
|
|
return Status::OK();
|
2018-08-23 10:10:30 +02:00
|
|
|
}
|
2018-08-23 13:20:16 +02:00
|
|
|
catch(const fs::error &e)
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': wfile:%p fd:%d append:%p size:%zu offset:%zu :%s",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
2018-08-23 10:10:30 +02:00
|
|
|
offset,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
2018-08-23 13:20:16 +02:00
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log, "'%s': wfile:%p fd:%d append:%p size:%zu offset:%lu :%s",
|
2018-08-23 13:20:16 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
2018-08-23 13:20:16 +02:00
|
|
|
offset,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-11-02 09:07:42 +01:00
|
|
|
ircd::db::database::env::writable_file::Allocate(uint64_t offset,
|
|
|
|
uint64_t length)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-23 10:10:30 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d allocate offset:%lu length:%lu%s%s",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
2018-11-02 09:07:42 +01:00
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
env_opts.fallocate_with_keep_size? " KEEP_SIZE" : "",
|
|
|
|
env_opts.allow_fallocate? "" : " (DISABLED)"
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
_allocate(offset, length);
|
2018-08-23 10:10:30 +02:00
|
|
|
return Status::OK();
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const fs::error &e)
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::error
|
2018-08-23 10:10:30 +02:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d allocate offset:%zu length:%zu :%s",
|
2018-08-23 10:10:30 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
2018-11-02 09:07:42 +01:00
|
|
|
offset,
|
|
|
|
length,
|
2018-08-24 06:32:28 +02:00
|
|
|
e.what()
|
2018-08-23 10:10:30 +02:00
|
|
|
};
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
catch(const std::exception &e)
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::critical
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d allocate offset:%zu length:%zu :%s",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
2018-11-02 09:07:42 +01:00
|
|
|
offset,
|
|
|
|
length,
|
2018-08-24 06:32:28 +02:00
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
void
|
2018-11-02 09:07:42 +01:00
|
|
|
ircd::db::database::env::writable_file::PrepareWrite(size_t offset,
|
|
|
|
size_t length)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-08-22 21:56:17 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p prepare write offset:%zu length:%zu",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
2018-08-22 21:56:17 +02:00
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
offset,
|
|
|
|
length
|
2018-08-22 21:56:17 +02:00
|
|
|
};
|
|
|
|
#endif
|
2018-08-24 06:32:28 +02:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
if(!env_opts.allow_fallocate)
|
|
|
|
return;
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
_allocate(offset, length);
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
void
|
|
|
|
ircd::db::database::env::writable_file::_allocate(const size_t &offset,
|
|
|
|
const size_t &length)
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
const size_t first_block
|
|
|
|
{
|
|
|
|
offset / preallocation_block_size
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t last_block
|
|
|
|
{
|
|
|
|
(offset + length) / preallocation_block_size
|
|
|
|
};
|
|
|
|
|
|
|
|
const ssize_t missing_blocks
|
|
|
|
{
|
|
|
|
ssize_t(last_block) - preallocation_last_block
|
|
|
|
};
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
// Fast bail when the offset and length are behind the last block already
|
|
|
|
// allocated. We don't support windowing here. If this branch is not taken
|
|
|
|
// we'll fallocate() contiguously from the last fallocate() (or offset 0).
|
2018-11-02 09:07:42 +01:00
|
|
|
if(missing_blocks <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const ssize_t start_block
|
|
|
|
{
|
|
|
|
preallocation_last_block + 1
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t allocate_offset
|
|
|
|
{
|
|
|
|
start_block * preallocation_block_size
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t allocate_length
|
|
|
|
{
|
|
|
|
missing_blocks * preallocation_block_size
|
|
|
|
};
|
|
|
|
|
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.offset = allocate_offset;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
wopts.keep_size = env_opts.fallocate_with_keep_size;
|
2018-08-20 03:56:50 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d allocating %zd blocks after block:%zu offset:%lu length:%lu%s",
|
2018-08-16 13:49:23 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
int(fd),
|
|
|
|
missing_blocks,
|
|
|
|
start_block,
|
|
|
|
allocate_offset,
|
|
|
|
allocate_length,
|
|
|
|
wopts.keep_size? " KEEP_SIZE" : ""
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
fs::allocate(fd, allocate_length, wopts);
|
|
|
|
this->preallocation_last_block = last_block;
|
2018-08-23 13:20:16 +02:00
|
|
|
}
|
2018-08-19 10:14:54 +02:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
void
|
|
|
|
ircd::db::database::env::writable_file::GetPreallocationStatus(size_t *const block_size,
|
|
|
|
size_t *const last_allocated_block)
|
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-20 03:56:50 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-11-02 09:07:42 +01:00
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
*block_size = this->preallocation_block_size;
|
|
|
|
*last_allocated_block = this->preallocation_last_block;
|
2018-08-20 03:56:50 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p get preallocation block_size(%p):%zu last_block(%p):%zu",
|
2018-08-16 13:49:23 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
block_size,
|
|
|
|
*block_size,
|
|
|
|
last_allocated_block,
|
|
|
|
*last_allocated_block
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
2018-11-02 09:07:42 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::writable_file::SetPreallocationBlockSize(size_t size)
|
|
|
|
noexcept
|
2018-08-24 06:32:28 +02:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
2018-08-16 13:49:23 +02:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p set preallocation block size:%zu",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
size
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-11-02 09:07:42 +01:00
|
|
|
#endif
|
2018-08-16 13:49:23 +02:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
this->preallocation_block_size = size;
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
uint64_t
|
|
|
|
ircd::db::database::env::writable_file::GetFileSize()
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d get file size",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
int(fd)
|
2018-08-24 06:32:28 +02:00
|
|
|
};
|
|
|
|
#endif
|
2018-08-16 13:49:23 +02:00
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
return fs::size(fd);
|
2018-08-23 13:20:16 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p fd:%d get file size :%s",
|
2018-08-23 13:20:16 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-08-24 06:32:28 +02:00
|
|
|
int(fd),
|
2018-11-02 09:07:42 +01:00
|
|
|
e.what()
|
2018-08-23 13:20:16 +02:00
|
|
|
};
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
return 0;
|
2018-08-19 10:14:54 +02:00
|
|
|
}
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
void
|
2018-11-02 09:07:42 +01:00
|
|
|
ircd::db::database::env::writable_file::SetIOPriority(Env::IOPriority prio)
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p IO priority %s",
|
2018-08-16 13:49:23 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
reflect(prio)
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
this->prio = prio;
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Env::IOPriority
|
|
|
|
ircd::db::database::env::writable_file::GetIOPriority()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return prio;
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
void
|
2018-11-02 09:07:42 +01:00
|
|
|
ircd::db::database::env::writable_file::SetWriteLifeTimeHint(WriteLifeTimeHint hint)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p hint %s",
|
2018-08-16 13:49:23 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
reflect(hint)
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
this->hint = hint;
|
2018-11-02 09:30:15 +01:00
|
|
|
//TODO: fcntl F_SET_FILE_RW_HINT
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
rocksdb::Env::WriteLifeTimeHint
|
|
|
|
ircd::db::database::env::writable_file::GetWriteLifeTimeHint()
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept
|
2018-08-23 13:20:16 +02:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
return hint;
|
2018-08-23 13:20:16 +02:00
|
|
|
}
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file::GetUniqueId(char *const id,
|
|
|
|
size_t max_size)
|
|
|
|
const noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-20 03:56:50 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-16 13:49:23 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
"'%s': wfile:%p get unique id:%p max_size:%zu",
|
2018-08-16 13:49:23 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
2018-11-02 09:07:42 +01:00
|
|
|
id,
|
|
|
|
max_size
|
2018-08-16 13:49:23 +02:00
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
const mutable_buffer buf
|
2018-08-24 06:32:28 +02:00
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
id, max_size
|
2018-08-24 06:32:28 +02:00
|
|
|
};
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
//return size(fs::uuid(fd, buf));
|
|
|
|
return 0;
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
log::critical
|
|
|
|
{
|
2018-11-02 09:07:42 +01:00
|
|
|
log, "'%s': wfile:%p get unique id :%s",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
2018-11-02 09:07:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::writable_file::IsSyncThreadSafe()
|
|
|
|
const noexcept try
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
return false;
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
//
|
|
|
|
// writable_file_direct
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::env::writable_file_direct::writable_file_direct(database *const &d,
|
|
|
|
const std::string &name,
|
|
|
|
const EnvOptions &env_opts,
|
|
|
|
const bool &trunc)
|
|
|
|
:writable_file
|
|
|
|
{
|
|
|
|
d, name, env_opts, trunc
|
|
|
|
}
|
|
|
|
,alignment
|
|
|
|
{
|
|
|
|
fs::block_size(fd)
|
|
|
|
}
|
|
|
|
,logical_offset
|
|
|
|
{
|
|
|
|
!trunc?
|
|
|
|
fs::size(fd):
|
|
|
|
size_t(0)
|
|
|
|
}
|
|
|
|
,buffer
|
|
|
|
{
|
|
|
|
alignment, alignment
|
|
|
|
}
|
|
|
|
{
|
|
|
|
zero(buffer);
|
|
|
|
if(!aligned(logical_offset))
|
|
|
|
throw assertive
|
|
|
|
{
|
|
|
|
"direct writable file requires read into buffer."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file_direct::Close()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
std::unique_lock<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
if(!fd)
|
|
|
|
return Status::OK();
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d close",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(logical_offset > 0 && fs::size(fd) != logical_offset)
|
|
|
|
{
|
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
fs::truncate(fd, logical_offset, wopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fs::fd{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file_direct::Truncate(uint64_t size)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
"'%s': wfile:%p DIRECT fd:%d truncate to %lu bytes",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
fs::truncate(fd, size, wopts);
|
|
|
|
logical_offset = size;
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d truncate to %lu bytes :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d truncate to %lu bytes :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
size,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file_direct::Append(const Slice &s)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d append:%p%s bytes:%zu%s logical_offset:%zu%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
aligned(data(s))? "" : "#AC",
|
|
|
|
size(s),
|
|
|
|
aligned(size(s))? "" : "#AC",
|
|
|
|
logical_offset,
|
|
|
|
aligned(logical_offset)? "" : "#AC"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-28 02:30:59 +01:00
|
|
|
const auto logical_check
|
2018-11-10 03:24:51 +01:00
|
|
|
{
|
2018-11-28 02:30:59 +01:00
|
|
|
logical_offset
|
2018-11-10 03:24:51 +01:00
|
|
|
};
|
|
|
|
|
2018-11-28 02:30:59 +01:00
|
|
|
const_buffer buf
|
2018-11-10 03:24:51 +01:00
|
|
|
{
|
2018-11-28 02:30:59 +01:00
|
|
|
slice(s)
|
2018-11-10 03:24:51 +01:00
|
|
|
};
|
|
|
|
|
2018-11-28 02:30:59 +01:00
|
|
|
while(!empty(buf))
|
|
|
|
buf = write(buf);
|
2018-11-10 03:24:51 +01:00
|
|
|
|
2018-11-28 02:30:59 +01:00
|
|
|
assert(logical_check + size(slice(s)) == logical_offset);
|
2018-11-10 03:24:51 +01:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d append:%p size:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d append:%p size:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
size(s),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::writable_file_direct::PositionedAppend(const Slice &s,
|
|
|
|
uint64_t offset)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d append:%p%s bytes:%zu%s offset:%zu%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(s),
|
|
|
|
aligned(data(s))? "" : "#AC",
|
|
|
|
size(s),
|
|
|
|
aligned(size(s))? "" : "#AC",
|
|
|
|
offset,
|
|
|
|
aligned(offset)? "" : "#AC"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rocksdb::Status::NotSupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
ircd::db::database::env::writable_file_direct::GetFileSize()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d get file size",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const auto &ret
|
|
|
|
{
|
|
|
|
logical_offset
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(ret <= fs::size(fd));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d get file size :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-28 02:30:59 +01:00
|
|
|
/// (Internal) Append buffer. This function is the internal entry interface
|
|
|
|
/// for appending a buffer of any size and alignment to the file. It is
|
|
|
|
/// internal because it does no locking or error handling back to rocksdb,
|
|
|
|
/// because it's expected to be called from some virtual override which does
|
|
|
|
/// those things. This function will branch off as required to other internal
|
|
|
|
/// write_* functions to properly align and rebuffer the supplied buffer
|
|
|
|
/// eventually culminating in an aligned append to the file.
|
|
|
|
///
|
|
|
|
/// Calling this function will always result in some write to the file; even
|
|
|
|
/// if temporary buffering is used to achieve alignment; even if the entire
|
|
|
|
/// supplied buffer is hopelessly unaligned: the supplied data will be written
|
|
|
|
/// out some way or another during this call. This means there is no
|
|
|
|
/// requirement to care about flushing the temporary this->buffer after this
|
|
|
|
/// call is made. Note that the temporary this->buffer has no reason to be
|
|
|
|
/// touched by anything other than this function stack.
|
|
|
|
///
|
|
|
|
/// !!! NOTE !!!
|
|
|
|
/// There is a requirement to truncate the file after this call is made before
|
|
|
|
/// closing the file. If a crash occurs after a write() which was padded out
|
|
|
|
/// to the block alignment: the file size will reflect the padding when it is
|
|
|
|
/// opened at next startup; RocksDB will not detect its terminator character
|
|
|
|
/// sequence and consider this file corrupt.
|
|
|
|
/// !!!
|
|
|
|
///
|
|
|
|
/// - any offset
|
|
|
|
/// - any data
|
|
|
|
/// - any size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::write(const const_buffer &buf_)
|
|
|
|
{
|
|
|
|
const_buffer buf
|
|
|
|
{
|
|
|
|
// If the file's offset is aligned and the buffer's data is aligned
|
|
|
|
// we take an easy branch which writes everything and copies any
|
|
|
|
// unaligned overflow to the temporary this->buffer. Nothing is
|
|
|
|
// returned into buf from this branch so there's nothing else done
|
|
|
|
// as this function will return when empty(buf) is checked below.
|
|
|
|
aligned(logical_offset) && aligned(data(buf_))?
|
|
|
|
write_aligned(buf_):
|
|
|
|
|
|
|
|
// If the file's offset isn't aligned we have to bring it up to
|
|
|
|
// alignment first by using data from the front of buf_. All the
|
|
|
|
// remaining data will be returned to here, which may make a mess
|
|
|
|
// of buf's alignment and size but this frame will deal with that.
|
|
|
|
!aligned(logical_offset)?
|
|
|
|
write_unaligned_off(buf_):
|
|
|
|
|
|
|
|
// The file's offset is aligned but buf is not aligned. We'll deal
|
|
|
|
// with that in this frame.
|
|
|
|
buf_
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(aligned(logical_offset) || empty(buf));
|
|
|
|
|
|
|
|
// buf can be empty here if it was entirely dealt with by the above
|
|
|
|
// branches and there's nothing else to do here.
|
|
|
|
if(empty(buf))
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
// Branch on whether the buffer's address is aligned. If so, considering
|
|
|
|
// the logical_offset is aligned here we are then finished.
|
|
|
|
if(aligned(data(buf)))
|
|
|
|
return write_aligned(buf);
|
|
|
|
|
|
|
|
// Deal with an unaligned buffer by bringing it up to alignment. This
|
|
|
|
// will end up returning an aligned buffer, but may unalign the
|
|
|
|
// logical_offset by doing so. This write() call must be looped until
|
|
|
|
// it empties the buffer. It will be loopy if everything comes very
|
|
|
|
// unaligned out of rocksdb.
|
|
|
|
return write_unaligned_buf(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Called when the logical_offset aligned but the supplied buffer's address
|
|
|
|
/// is not aligned. The supplied buffer's size can be unaligned here. This
|
|
|
|
/// function will fill up the temporary this->buffer with the front of buf
|
|
|
|
/// until an aligned address is achieved.
|
|
|
|
///
|
|
|
|
/// The rest of the buffer which starts at an aligned address is returned and
|
|
|
|
/// not written. It is not written since this function may leave the
|
|
|
|
/// logical_offset at an unaligned address.
|
|
|
|
///
|
|
|
|
/// * aligned offset
|
|
|
|
/// * unaligned data
|
|
|
|
/// - any size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::write_unaligned_buf(const const_buffer &buf)
|
|
|
|
{
|
|
|
|
assert(aligned(logical_offset));
|
|
|
|
assert(!aligned(data(buf)));
|
|
|
|
assert(!aligned(buf));
|
|
|
|
|
|
|
|
// Window on the data between the given buffer's pointer and the next
|
|
|
|
// alignment boundary.
|
|
|
|
const const_buffer under_buf
|
|
|
|
{
|
|
|
|
data(buf), std::min(remain(uintptr_t(data(buf))), size(buf))
|
|
|
|
};
|
|
|
|
|
|
|
|
// Window on the data from the alignment boundary to the end of the
|
|
|
|
// given buffer.
|
|
|
|
const const_buffer remaining_buf
|
|
|
|
{
|
|
|
|
buf + size(under_buf)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(size(under_buf) <= size(buf));
|
|
|
|
assert(size(under_buf) + size(remaining_buf) == size(buf));
|
|
|
|
assert(data(buf) + size(under_buf) == data(remaining_buf));
|
|
|
|
assert(aligned(data(remaining_buf)) || empty(remaining_buf));
|
|
|
|
|
|
|
|
// We have to use the temporary buffer to deal with the unaligned
|
|
|
|
// leading part of the buffer. Since logical_offset is aligned this
|
|
|
|
// buffer isn't being used right now. We copy as much as possible
|
|
|
|
// to fill out a complete block, both the unaligned and aligned inputs
|
|
|
|
// and zero padding if both are not sufficient.
|
|
|
|
mutable_buffer dst(this->buffer);
|
|
|
|
consume(dst, copy(dst, under_buf));
|
|
|
|
consume(dst, copy(dst, remaining_buf));
|
|
|
|
consume(dst, zero(dst));
|
|
|
|
assert(empty(dst));
|
|
|
|
|
|
|
|
// Flush the temporary buffer.
|
|
|
|
_write__aligned(this->buffer, logical_offset);
|
|
|
|
|
|
|
|
// The logical_offset is only advanced by the underflow amount, even if
|
|
|
|
// we padded the temporary buffer with some remaing_buf data. The caller
|
|
|
|
// is lead to believe they must deal with remaining_buf in its entirety
|
|
|
|
// starting at the logical_offset.
|
|
|
|
logical_offset += size(under_buf);
|
|
|
|
|
|
|
|
return remaining_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Called when the logical_offset is not aligned, indicating that something
|
|
|
|
/// was left in the temporary this->buffer which must be completed out to
|
|
|
|
/// alignment by consuming the front of the argument buf. This function appends
|
|
|
|
/// the front of buf to this->buffer and flushes this->buffer.
|
|
|
|
///
|
|
|
|
/// logical_offset is incremented, either to the next block alignment or less
|
|
|
|
/// if size(buf) can't get it there.
|
|
|
|
///
|
|
|
|
/// The rest of buf which isn't used to fill out this->buffer is returned and
|
|
|
|
/// not written. It is not written since the returned data(buf) might not
|
|
|
|
/// be aligned. In fact, this function does not care about the alignment of buf
|
|
|
|
/// at all.
|
|
|
|
///
|
|
|
|
/// * unaligned offset
|
|
|
|
/// - any data
|
|
|
|
/// - any size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::write_unaligned_off(const const_buffer &buf)
|
|
|
|
{
|
|
|
|
assert(!aligned(logical_offset));
|
|
|
|
|
|
|
|
// Window on the amount of buf we can take to fill up remaining space in
|
|
|
|
// the temporary this->buffer
|
|
|
|
const const_buffer src
|
|
|
|
{
|
|
|
|
data(buf), std::min(size(buf), buffer_remain())
|
|
|
|
};
|
|
|
|
|
|
|
|
// Window on the remaining space in the temporary this->buffer.
|
|
|
|
const mutable_buffer dst
|
|
|
|
{
|
|
|
|
this->buffer + buffer_consumed()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Window on the remaining space in dst after src is copied to dst, if any.
|
|
|
|
const mutable_buffer pad
|
|
|
|
{
|
|
|
|
dst + size(src)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(size(dst) - size(pad) == size(src));
|
|
|
|
assert(size(src) + size(pad) == buffer_remain());
|
|
|
|
assert(size(src) + size(pad) + buffer_consumed() == alignment);
|
|
|
|
assert(size(src) + buffer_consumed() != alignment || empty(pad));
|
|
|
|
|
|
|
|
copy(dst, src);
|
|
|
|
zero(pad);
|
|
|
|
|
|
|
|
// Backtrack the logical_offset to the aligned offset where this->buffer's
|
|
|
|
// data starts.
|
|
|
|
const auto aligned_offset
|
|
|
|
{
|
|
|
|
align(logical_offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write the whole temporary this->buffer at the aligned offset.
|
|
|
|
_write__aligned(this->buffer, aligned_offset);
|
|
|
|
|
|
|
|
// Only increment the logical_offset to indicate the appending of
|
|
|
|
// what this function added to the temporary this->buffer.
|
|
|
|
logical_offset += size(src);
|
|
|
|
|
|
|
|
// The logical_offset should either be aligned now after using buf's
|
|
|
|
// data to eliminate the temporary this->buffer, or buf's data wasn't
|
|
|
|
// enough and we'll have to call this function again later with more.
|
|
|
|
assert(aligned(logical_offset) || size(buf) < alignment);
|
|
|
|
|
|
|
|
// Return the rest of buf which we didn't use to fill out this->buf
|
|
|
|
// Caller will have to deal figuring out how to align the next write.
|
|
|
|
return const_buffer
|
|
|
|
{
|
|
|
|
buf + size(src)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Write function callable when the current logical_offset and the supplied
|
|
|
|
/// buffer's pointer are both aligned, but the size of the buffer need not
|
|
|
|
/// be aligned. This function thus assumes that the temporary this->buffer
|
|
|
|
/// is empty; it will write as much of the input buffer as aligned. The
|
|
|
|
/// unaligned overflow will be copied to the front of the temporary
|
|
|
|
/// this->buffer which will be padded to alignment and flushed and the
|
|
|
|
/// logical_offset will indicate an increment of the size of the input buffer.
|
|
|
|
///
|
|
|
|
/// * aligned offset
|
|
|
|
/// * aligned data
|
|
|
|
/// - any size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::write_aligned(const const_buffer &buf)
|
|
|
|
{
|
|
|
|
assert(aligned(data(buf)));
|
|
|
|
assert(aligned(logical_offset));
|
|
|
|
|
|
|
|
// This portion at the end of buf did not fill out to the alignment.
|
|
|
|
const const_buffer overflow
|
|
|
|
{
|
|
|
|
_write_aligned(buf, logical_offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
// The aligned portion was written so the offset is incremented here.
|
|
|
|
logical_offset += size(buf) - size(overflow);
|
|
|
|
|
|
|
|
assert(aligned(logical_offset));
|
|
|
|
assert(size(overflow) < alignment);
|
|
|
|
assert(aligned(data(overflow)) || empty(overflow));
|
|
|
|
assert(align(size(buf)) + size(overflow) == size(buf));
|
|
|
|
assert(blocks(size(buf)) * alignment + size(overflow) == size(buf));
|
|
|
|
|
|
|
|
if(!empty(overflow))
|
|
|
|
{
|
|
|
|
// The overflow is copied to the temporary this->buffer, padded out with
|
|
|
|
// zero and then flushed. The logical offset will be incremented by the
|
|
|
|
// size of that overflow and will no longer be an aligned value,
|
|
|
|
// indicating there is something in the temporary this->buffer.
|
|
|
|
mutable_buffer dst(this->buffer);
|
|
|
|
consume(dst, copy(dst, overflow));
|
|
|
|
consume(dst, zero(dst));
|
|
|
|
assert(empty(dst));
|
|
|
|
|
|
|
|
_write__aligned(this->buffer, logical_offset);
|
|
|
|
logical_offset += size(overflow);
|
|
|
|
assert(!aligned(logical_offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing is ever returned and required by the caller here because the
|
|
|
|
// input is aligned to its address and offset and any unaligned size was
|
|
|
|
// dealt with using the temporary this->buffer.
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lower level write to an aligned offset. The pointer of the buffer and the
|
|
|
|
/// offset both have to be aligned to alignment. The size of the buffer does
|
|
|
|
/// not have to be aligned to alignment. The unaligned portion of the input
|
|
|
|
/// buffer (the last partial block), if any, will be returned to the caller.
|
|
|
|
///
|
|
|
|
/// No modifications to the logical_offset or the temporary this->buffer take
|
|
|
|
/// place here so the caller must manipulate those accordingly.
|
|
|
|
///
|
|
|
|
/// * aligned data
|
|
|
|
/// * aligned offset
|
|
|
|
/// - any size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::_write_aligned(const const_buffer &buf,
|
|
|
|
const uint64_t &offset)
|
|
|
|
{
|
|
|
|
assert(aligned(data(buf)));
|
|
|
|
assert(aligned(offset));
|
|
|
|
|
|
|
|
// This portion will be written
|
|
|
|
const const_buffer aligned_buf
|
|
|
|
{
|
|
|
|
data(buf), blocks(size(buf)) * alignment
|
|
|
|
};
|
|
|
|
|
|
|
|
// This trailing portion will be returned to caller
|
|
|
|
const const_buffer ret
|
|
|
|
{
|
|
|
|
data(buf) + size(aligned_buf), size(buf) - size(aligned_buf)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!empty(aligned_buf) || size(buf) < alignment);
|
|
|
|
assert(size(aligned_buf) + size(ret) == size(buf));
|
|
|
|
assert(size(ret) < alignment);
|
|
|
|
|
|
|
|
// aligned_buf will be empty if buf itself is smaller than the alignment.
|
|
|
|
if(empty(aligned_buf))
|
|
|
|
{
|
|
|
|
assert(size(ret) == size(buf));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_write__aligned(aligned_buf, offset);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lowest level write of a fully aligned buffer to an aligned offset. The
|
|
|
|
/// pointer of the buffer, the size of the buffer, and the offset ALL have
|
|
|
|
/// to be aligned to alignment for this function. This function is the only
|
|
|
|
/// in the stack which actually writes to the filesystem.
|
|
|
|
///
|
|
|
|
/// No modifications to the logical_offset take place here so the caller must
|
|
|
|
/// increment that accordingly. The return value is a const_buffer to conform
|
|
|
|
/// with the rest of the stack but it is unconditionally empty here because
|
|
|
|
/// there is no possible overflowing.
|
|
|
|
///
|
|
|
|
/// * aligned offset
|
|
|
|
/// * aligned data
|
|
|
|
/// * aligned size
|
|
|
|
ircd::const_buffer
|
|
|
|
ircd::db::database::env::writable_file_direct::_write__aligned(const const_buffer &buf,
|
|
|
|
const uint64_t &offset)
|
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': wfile:%p DIRECT fd:%d write:%p%s bytes:%zu%s offset:%zu%s (logical:%zu)",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(buf),
|
|
|
|
aligned(data(buf))? "" : "#AC",
|
|
|
|
size(buf),
|
|
|
|
aligned(size(buf))? "" : "#AC",
|
|
|
|
offset,
|
|
|
|
aligned(offset)? "" : "#AC",
|
|
|
|
logical_offset
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(aligned(buf));
|
|
|
|
assert(aligned(offset));
|
|
|
|
|
|
|
|
fs::write_opts wopts;
|
|
|
|
wopts.priority = this->prio;
|
|
|
|
wopts.offset = offset;
|
|
|
|
fs::write(fd, buf, wopts);
|
|
|
|
|
|
|
|
// Nothing is ever returned to the caller here because the input buffer
|
|
|
|
// and the offset must be fully aligned at this stage.
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file_direct::buffer_consumed()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return likely(alignment != 0)?
|
|
|
|
logical_offset % alignment:
|
|
|
|
0UL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file_direct::buffer_remain()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return remain(logical_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file_direct::blocks(const size_t &value)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return likely(alignment != 0)?
|
|
|
|
value / alignment:
|
|
|
|
0UL;
|
|
|
|
}
|
|
|
|
|
2018-11-10 03:24:51 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file_direct::remain(const size_t &value)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return likely(alignment != 0)?
|
|
|
|
alignment - (value - align(value)):
|
2018-11-28 02:30:59 +01:00
|
|
|
0UL;
|
2018-11-10 03:24:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::writable_file_direct::align(const size_t &value)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return likely(alignment != 0)?
|
|
|
|
value - (value % alignment):
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::writable_file_direct::aligned(const const_buffer &buf)
|
|
|
|
const
|
|
|
|
{
|
2018-11-28 02:30:59 +01:00
|
|
|
return buffer::aligned(buf, alignment);
|
2018-11-10 03:24:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::writable_file_direct::aligned(const void *const &value)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return aligned(size_t(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::writable_file_direct::aligned(const size_t &value)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return (alignment == 0) || (value % alignment == 0UL);
|
|
|
|
}
|
|
|
|
|
2018-01-18 06:24:32 +01:00
|
|
|
//
|
2018-08-24 06:32:28 +02:00
|
|
|
// sequential_file
|
2018-01-18 06:24:32 +01:00
|
|
|
//
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
decltype(ircd::db::database::env::sequential_file::default_opts)
|
|
|
|
ircd::db::database::env::sequential_file::default_opts{[]
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::fs::fd::opts ret{std::ios_base::in};
|
|
|
|
return ret;
|
|
|
|
}()};
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::sequential_file::sequential_file(database *const &d,
|
|
|
|
const std::string &name,
|
|
|
|
const EnvOptions &env_opts)
|
|
|
|
try
|
|
|
|
:d
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
*d
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
,opts{[&env_opts]
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
fs::fd::opts ret{default_opts};
|
|
|
|
ret.direct = env_opts.use_direct_reads;
|
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,fd
|
|
|
|
{
|
|
|
|
name, this->opts
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
2018-10-31 22:09:10 +01:00
|
|
|
,_buffer_align
|
|
|
|
{
|
|
|
|
fs::block_size(fd)
|
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
,offset
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
0
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
log, "'%s': opened seqfile:%p fd:%d bs:%zu '%s'",
|
2018-08-24 06:32:28 +02:00
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
2018-10-31 22:09:10 +01:00
|
|
|
_buffer_align,
|
2018-08-24 06:32:28 +02:00
|
|
|
name
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': opening seqfile:%p `%s' :%s",
|
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
e.what()
|
|
|
|
};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::sequential_file::~sequential_file()
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': close seqfile:%p fd:%d",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-08-24 06:32:28 +02:00
|
|
|
ircd::db::database::env::sequential_file::Read(size_t length,
|
2018-08-24 14:33:18 +02:00
|
|
|
Slice *const result,
|
|
|
|
char *const scratch)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
assert(result);
|
2018-08-24 14:33:18 +02:00
|
|
|
assert(scratch);
|
2018-08-24 06:32:28 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p read:%p offset:%zu length:%zu scratch:%p",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
scratch, length
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto read
|
|
|
|
{
|
|
|
|
fs::read(fd, buf, offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = slice(read);
|
|
|
|
offset += length;
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::sequential_file::PositionedRead(uint64_t offset,
|
|
|
|
size_t length,
|
2018-08-24 14:33:18 +02:00
|
|
|
Slice *const result,
|
|
|
|
char *const scratch)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
assert(result);
|
2018-08-24 14:33:18 +02:00
|
|
|
assert(scratch);
|
2018-08-24 06:32:28 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
scratch, length
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto read
|
|
|
|
{
|
|
|
|
fs::read(fd, buf, offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = slice(read);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::sequential_file::Skip(uint64_t size)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
"'%s': seqfile:%p offset:zu skip:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
size
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::sequential_file::InvalidateCache(size_t offset,
|
|
|
|
size_t length)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
"'%s': seqfile:%p invalidate cache offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:30:15 +01:00
|
|
|
if(opts.direct)
|
|
|
|
return Status::OK();
|
|
|
|
|
|
|
|
#if defined(HAVE_POSIX_FADVISE) && defined(FADV_DONTNEED)
|
|
|
|
syscall(::posix_fadvise, fd, offset, length, FADV_DONTNEED);
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
"'%s': seqfile:%p invalidate cache offset:%zu length:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': seqfile:%p invalidate cache offset:%zu length:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::sequential_file::use_direct_io()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
return opts.direct;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::sequential_file::GetRequiredBufferAlignment()
|
|
|
|
const noexcept
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
const auto &ret
|
2018-08-29 04:38:55 +02:00
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
_buffer_align
|
2018-08-29 04:38:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// random_access_file
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::db::database::env::random_access_file::default_opts)
|
|
|
|
ircd::db::database::env::random_access_file::default_opts{[]
|
|
|
|
{
|
|
|
|
ircd::fs::fd::opts ret{std::ios_base::in};
|
|
|
|
return ret;
|
|
|
|
}()};
|
|
|
|
|
|
|
|
ircd::db::database::env::random_access_file::random_access_file(database *const &d,
|
|
|
|
const std::string &name,
|
|
|
|
const EnvOptions &env_opts)
|
|
|
|
try
|
|
|
|
:d
|
|
|
|
{
|
|
|
|
*d
|
|
|
|
}
|
|
|
|
,opts{[&env_opts]
|
|
|
|
{
|
|
|
|
fs::fd::opts ret{default_opts};
|
|
|
|
ret.direct = env_opts.use_direct_reads;
|
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,fd
|
|
|
|
{
|
|
|
|
name, this->opts
|
|
|
|
}
|
2018-10-18 17:27:03 +02:00
|
|
|
,_buffer_align
|
|
|
|
{
|
|
|
|
fs::block_size(fd)
|
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
log, "'%s': opened rfile:%p fd:%d bs:%zu '%s'",
|
2018-08-24 06:32:28 +02:00
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
2018-10-31 22:09:10 +01:00
|
|
|
_buffer_align,
|
2018-08-24 06:32:28 +02:00
|
|
|
name
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': opening rfile:%p `%s' :%s",
|
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::random_access_file::~random_access_file()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': close rfile:%p fd:%d",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_access_file::Prefetch(uint64_t offset,
|
|
|
|
size_t length)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p prefetch offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fs::prefetch(fd, length, offset);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p prefetch offset:%zu length:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_access_file::Read(uint64_t offset,
|
|
|
|
size_t length,
|
2018-08-24 14:33:18 +02:00
|
|
|
Slice *const result,
|
|
|
|
char *const scratch)
|
2018-08-24 06:32:28 +02:00
|
|
|
const noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
assert(result);
|
2018-08-24 14:33:18 +02:00
|
|
|
assert(scratch);
|
2018-08-24 06:32:28 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p read:%p offset:%zu length:%zu scratch:%p",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
scratch, length
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto read
|
|
|
|
{
|
|
|
|
fs::read(fd, buf, offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = slice(read);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_access_file::InvalidateCache(size_t offset,
|
|
|
|
size_t length)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p invalidate cache offset:%zu length:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
offset,
|
|
|
|
length
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-02 09:30:15 +01:00
|
|
|
if(opts.direct)
|
|
|
|
return Status::OK();
|
|
|
|
|
|
|
|
#if defined(HAVE_POSIX_FADVISE) && defined(FADV_DONTNEED)
|
|
|
|
syscall(::posix_fadvise, fd, offset, length, FADV_DONTNEED);
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::random_access_file::GetUniqueId(char *const id,
|
|
|
|
size_t max_size)
|
|
|
|
const noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p get unique id:%p max_size:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
id,
|
|
|
|
max_size
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
id, max_size
|
|
|
|
};
|
|
|
|
|
2018-09-21 07:00:11 +02:00
|
|
|
//return size(fs::uuid(fd, buf));
|
|
|
|
return 0;
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p GetUniqueId id:%p max_size:%zu :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
id,
|
|
|
|
max_size,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::database::env::random_access_file::Hint(AccessPattern pattern)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rfile:%p hint %s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
reflect(pattern)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::random_access_file::use_direct_io()
|
|
|
|
const noexcept
|
|
|
|
{
|
|
|
|
return opts.direct;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::random_access_file::GetRequiredBufferAlignment()
|
|
|
|
const noexcept
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
const auto &ret
|
2018-08-29 04:38:55 +02:00
|
|
|
{
|
2018-10-18 17:27:03 +02:00
|
|
|
_buffer_align
|
2018-08-29 04:38:55 +02:00
|
|
|
};
|
|
|
|
|
2018-10-31 22:09:10 +01:00
|
|
|
return ret;
|
2018-08-24 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// random_rw_file
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::db::database::env::random_rw_file::default_opts)
|
|
|
|
ircd::db::database::env::random_rw_file::default_opts{[]
|
|
|
|
{
|
|
|
|
ircd::fs::fd::opts ret
|
|
|
|
{
|
|
|
|
std::ios_base::in | std::ios_base::out
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}()};
|
|
|
|
|
|
|
|
ircd::db::database::env::random_rw_file::random_rw_file(database *const &d,
|
|
|
|
const std::string &name,
|
|
|
|
const EnvOptions &opts)
|
|
|
|
try
|
|
|
|
:d
|
|
|
|
{
|
|
|
|
*d
|
|
|
|
}
|
|
|
|
,opts{[&opts]
|
|
|
|
{
|
|
|
|
fs::fd::opts ret{default_opts};
|
|
|
|
ret.direct = opts.use_direct_reads && opts.use_direct_writes;
|
|
|
|
return ret;
|
|
|
|
}()}
|
|
|
|
,fd
|
|
|
|
{
|
|
|
|
name, this->opts
|
|
|
|
}
|
2018-10-31 22:09:10 +01:00
|
|
|
,_buffer_align
|
|
|
|
{
|
|
|
|
fs::block_size(fd)
|
|
|
|
}
|
2018-08-24 06:32:28 +02:00
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
log, "'%s': opened rwfile:%p fd:%d bs:%zu '%s'",
|
2018-08-24 06:32:28 +02:00
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
2018-10-31 22:09:10 +01:00
|
|
|
_buffer_align,
|
2018-08-24 06:32:28 +02:00
|
|
|
name
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': opening rwfile:%p `%s' :%s",
|
|
|
|
d->name,
|
|
|
|
this,
|
|
|
|
name,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::random_rw_file::~random_rw_file()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': close rwfile:%p fd:%d '%s'",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Close()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
log, "'%s': close rwfile:%p fd:%d '%s'",
|
2018-08-24 06:32:28 +02:00
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
this->fd = fs::fd{};
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p close :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Fsync()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d fsync",
|
|
|
|
d.name,
|
|
|
|
int(fd),
|
|
|
|
this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d fsync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d fsync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Sync()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d sync",
|
|
|
|
d.name,
|
|
|
|
int(fd),
|
|
|
|
this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fdsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d sync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d sync :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Flush()
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d flush",
|
|
|
|
d.name,
|
|
|
|
int(fd),
|
|
|
|
this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 19:19:45 +01:00
|
|
|
//TODO: AIO fdsync() throwing -EINVAL.
|
|
|
|
fs::fsync_opts opts;
|
|
|
|
opts.use_aio = false;
|
|
|
|
fs::fdsync(fd, opts);
|
2018-08-24 06:32:28 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d flush :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"'%s': rwfile:%p fd:%d flush :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Read(uint64_t offset,
|
|
|
|
size_t length,
|
|
|
|
Slice *const result,
|
|
|
|
char *const scratch)
|
|
|
|
const noexcept try
|
|
|
|
{
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
|
|
|
assert(result);
|
2018-08-24 14:33:18 +02:00
|
|
|
assert(scratch);
|
2018-08-24 06:32:28 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p read:%p offset:%zu length:%zu scratch:%p",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
scratch, length
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto read
|
|
|
|
{
|
|
|
|
fs::read(fd, buf, offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = slice(read);
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
result,
|
|
|
|
offset,
|
|
|
|
length,
|
|
|
|
scratch,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::random_rw_file::Write(uint64_t offset,
|
|
|
|
const Slice &slice)
|
2018-08-24 06:32:28 +02:00
|
|
|
noexcept try
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-08-24 06:32:28 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d write:%p length:%zu offset:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(slice),
|
|
|
|
size(slice),
|
|
|
|
offset
|
|
|
|
};
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
2018-08-24 06:32:28 +02:00
|
|
|
const const_buffer buf
|
|
|
|
{
|
|
|
|
data(slice), size(slice)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto read
|
|
|
|
{
|
|
|
|
fs::write(fd, buf, offset)
|
|
|
|
};
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const fs::error &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d write:%p length:%zu offset:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(slice),
|
|
|
|
size(slice),
|
|
|
|
offset
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "'%s': rwfile:%p fd:%d write:%p length:%zu offset:%zu",
|
|
|
|
d.name,
|
|
|
|
this,
|
|
|
|
int(fd),
|
|
|
|
data(slice),
|
|
|
|
size(slice),
|
|
|
|
offset
|
|
|
|
};
|
|
|
|
|
|
|
|
return error_to_status{e};
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::database::env::random_rw_file::use_direct_io()
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-08-24 06:32:28 +02:00
|
|
|
return opts.direct;
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::database::env::random_rw_file::GetRequiredBufferAlignment()
|
2018-01-18 09:49:23 +01:00
|
|
|
const noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
const auto &ret
|
2018-08-29 04:38:55 +02:00
|
|
|
{
|
2018-10-31 22:09:10 +01:00
|
|
|
_buffer_align
|
2018-08-29 04:38:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2018-01-18 06:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// directory
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::env::directory::directory(database *const &d,
|
|
|
|
const std::string &name,
|
|
|
|
std::unique_ptr<Directory> defaults)
|
|
|
|
:d{*d}
|
|
|
|
,defaults{std::move(defaults)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::directory::~directory()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
|
|
|
ircd::db::database::env::directory::Fsync()
|
2018-01-18 09:49:23 +01:00
|
|
|
noexcept
|
2018-01-18 06:24:32 +01:00
|
|
|
{
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_ENV
|
2018-01-18 06:24:32 +01:00
|
|
|
log.debug("'%s': directory:%p fsync",
|
|
|
|
d.name,
|
|
|
|
this);
|
2018-05-29 10:42:48 +02:00
|
|
|
#endif
|
2018-01-18 06:24:32 +01:00
|
|
|
|
|
|
|
return defaults->Fsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// file_lock
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::database::env::file_lock::file_lock(database *const &d)
|
|
|
|
:d{*d}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::database::env::file_lock::~file_lock()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
2018-01-18 05:17:00 +01:00
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
//
|
|
|
|
// rocksdb::port (EXPERIMENTAL)
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef IRCD_DB_PORT
|
|
|
|
|
|
|
|
//
|
|
|
|
// Mutex
|
|
|
|
//
|
|
|
|
|
2018-08-19 03:20:38 +02:00
|
|
|
static_assert
|
|
|
|
(
|
|
|
|
sizeof(rocksdb::port::Mutex) <= sizeof(pthread_mutex_t) + 1,
|
|
|
|
"link-time punning of our structure won't work if the structure is larger "
|
|
|
|
"than the one rocksdb has assumed space for."
|
|
|
|
);
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
rocksdb::port::Mutex::Mutex()
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
2018-06-01 20:31:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "mutex %lu %p CTOR", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::port::Mutex::Mutex(bool adaptive)
|
2018-06-01 20:31:46 +02:00
|
|
|
:Mutex{}
|
2018-05-30 09:14:07 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
rocksdb::port::Mutex::~Mutex()
|
|
|
|
{
|
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
2018-06-01 20:31:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "mutex %lu %p DTOR", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
void
|
|
|
|
rocksdb::port::Mutex::Lock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
2018-06-01 20:31:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "mutex %lu %p LOCK", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::Mutex::Unlock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
2018-06-01 20:31:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "mutex %lu %p UNLOCK", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(mu.locked());
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::Mutex::AssertHeld()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
2018-06-01 20:31:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
assert(mu.locked());
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// RWMutex
|
|
|
|
//
|
|
|
|
|
2018-08-19 03:20:38 +02:00
|
|
|
static_assert
|
|
|
|
(
|
|
|
|
sizeof(rocksdb::port::RWMutex) <= sizeof(pthread_rwlock_t),
|
|
|
|
"link-time punning of our structure won't work if the structure is larger "
|
|
|
|
"than the one rocksdb has assumed space for."
|
|
|
|
);
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
rocksdb::port::RWMutex::RWMutex()
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p CTOR", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::port::RWMutex::~RWMutex()
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p DTOR", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::RWMutex::ReadLock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p LOCK SHARED", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.lock_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::RWMutex::WriteLock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p LOCK", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::RWMutex::ReadUnlock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p UNLOCK SHARED", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.unlock_shared();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::RWMutex::WriteUnlock()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "shared_mutex %lu %p UNLOCK", ctx::id(), this
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
mu.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CondVar
|
|
|
|
//
|
|
|
|
|
2018-08-19 03:20:38 +02:00
|
|
|
static_assert
|
|
|
|
(
|
|
|
|
sizeof(rocksdb::port::CondVar) <= sizeof(pthread_cond_t) + sizeof(void *),
|
|
|
|
"link-time punning of our structure won't work if the structure is larger "
|
|
|
|
"than the one rocksdb has assumed space for."
|
|
|
|
);
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
rocksdb::port::CondVar::CondVar(Mutex *mu)
|
|
|
|
:mu{mu}
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p CTOR", ctx::id(), this, mu
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::port::CondVar::~CondVar()
|
|
|
|
{
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT_
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p DTOR", ctx::id(), this, mu
|
|
|
|
};
|
|
|
|
#endif
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::CondVar::Wait()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p WAIT", ctx::id(), this, mu
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
assert(mu);
|
2018-06-01 20:31:46 +02:00
|
|
|
assert_main_thread();
|
2018-08-16 13:48:21 +02:00
|
|
|
mu->AssertHeld();
|
2018-08-17 22:38:32 +02:00
|
|
|
cv.wait(mu->mu);
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if timeout occurred
|
|
|
|
bool
|
|
|
|
rocksdb::port::CondVar::TimedWait(uint64_t abs_time_us)
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
assert(ctx::current);
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p WAIT_UNTIL %lu", ctx::id(), this, mu, abs_time_us
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-05-30 09:14:07 +02:00
|
|
|
assert(mu);
|
2018-06-01 20:31:46 +02:00
|
|
|
assert_main_thread();
|
2018-08-16 13:48:21 +02:00
|
|
|
mu->AssertHeld();
|
2018-05-30 09:14:07 +02:00
|
|
|
const std::chrono::microseconds us(abs_time_us);
|
2018-06-01 20:31:46 +02:00
|
|
|
const std::chrono::steady_clock::time_point tp(us);
|
2018-08-17 22:38:32 +02:00
|
|
|
return cv.wait_until(mu->mu, tp) == std::cv_status::timeout;
|
2018-05-30 09:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::CondVar::Signal()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p NOTIFY", ctx::id(), this, mu
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
cv.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rocksdb::port::CondVar::SignalAll()
|
|
|
|
{
|
2018-08-29 00:57:49 +02:00
|
|
|
if(unlikely(!ctx::current))
|
|
|
|
return;
|
|
|
|
|
2018-06-01 20:31:46 +02:00
|
|
|
#ifdef RB_DEBUG_DB_PORT
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
db::log, "cond %lu %p %p BROADCAST", ctx::id(), this, mu
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert_main_thread();
|
2018-05-30 09:14:07 +02:00
|
|
|
cv.notify_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // IRCD_DB_PORT
|
|
|
|
|
2018-06-09 22:40:21 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// db/database/env/state.h
|
|
|
|
//
|
|
|
|
|
2017-09-19 04:19:02 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-01-30 18:58:36 +01:00
|
|
|
// db/txn.h
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
|
|
|
|
2018-03-28 00:21:30 +02:00
|
|
|
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;
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
2018-03-23 04:49:11 +01:00
|
|
|
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;
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->GetUpdatesSince(seq, &tit)
|
|
|
|
};
|
|
|
|
}
|
2018-03-23 04:49:11 +01:00
|
|
|
|
|
|
|
assert(bool(tit));
|
|
|
|
for(; tit->Valid(); tit->Next())
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
2018-03-23 04:49:11 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:19:02 +02:00
|
|
|
std::string
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::debug(const txn &t)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
const rocksdb::WriteBatch &wb(t);
|
|
|
|
return db::debug(wb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::for_each(const txn &t,
|
2017-09-19 04:19:02 +02:00
|
|
|
const std::function<void (const delta &)> &closure)
|
2017-09-19 05:40:13 +02:00
|
|
|
{
|
|
|
|
const auto re{[&closure]
|
|
|
|
(const delta &delta)
|
|
|
|
{
|
|
|
|
closure(delta);
|
|
|
|
return true;
|
|
|
|
}};
|
|
|
|
|
|
|
|
const database &d(t);
|
|
|
|
const rocksdb::WriteBatch &wb{t};
|
2018-01-30 18:58:36 +01:00
|
|
|
txn::handler h{d, re};
|
2017-09-19 05:40:13 +02:00
|
|
|
wb.Iterate(&h);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-04-17 00:16:51 +02:00
|
|
|
ircd::db::for_each(const txn &t,
|
|
|
|
const std::function<bool (const delta &)> &closure)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
const database &d(t);
|
|
|
|
const rocksdb::WriteBatch &wb{t};
|
2018-01-30 18:58:36 +01:00
|
|
|
txn::handler h{d, closure};
|
2017-09-19 05:40:13 +02:00
|
|
|
wb.Iterate(&h);
|
|
|
|
return h._continue;
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2018-03-23 04:47:46 +01:00
|
|
|
/// handler (db/database/txn.h)
|
2017-09-19 04:19:02 +02:00
|
|
|
///
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::PutCF(const uint32_t cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
const Slice &key,
|
|
|
|
const Slice &val)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::SET, key, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::DeleteCF(const uint32_t cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
const Slice &key)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::DELETE, key, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::DeleteRangeCF(const uint32_t cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
const Slice &begin,
|
|
|
|
const Slice &end)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::DELETE_RANGE, begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::SingleDeleteCF(const uint32_t cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
const Slice &key)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::SINGLE_DELETE, key, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::MergeCF(const uint32_t cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
const Slice &key,
|
|
|
|
const Slice &value)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return callback(cfid, op::MERGE, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-10-16 07:11:14 +02:00
|
|
|
ircd::db::txn::handler::MarkBeginPrepare(bool b)
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2018-10-16 07:11:14 +02:00
|
|
|
ircd::assertion("not implemented");
|
2017-09-19 04:19:02 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::MarkEndPrepare(const Slice &xid)
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2018-10-16 07:11:14 +02:00
|
|
|
ircd::assertion("not implemented");
|
2017-09-19 04:19:02 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::MarkCommit(const Slice &xid)
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2018-10-16 07:11:14 +02:00
|
|
|
ircd::assertion("not implemented");
|
2017-09-19 04:19:02 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::MarkRollback(const Slice &xid)
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2018-10-16 07:11:14 +02:00
|
|
|
ircd::assertion("not implemented");
|
2017-09-19 04:19:02 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::callback(const uint32_t &cfid,
|
2017-09-19 04:19:02 +02:00
|
|
|
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;
|
2018-05-29 10:09:15 +02:00
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
"txn::handler: cfid[%u]: %s", cfid, e.what()
|
|
|
|
};
|
|
|
|
|
2017-11-26 01:20:42 +01:00
|
|
|
ircd::terminate();
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::callback(const delta &delta)
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept try
|
|
|
|
{
|
2017-09-19 05:40:13 +02:00
|
|
|
_continue = cb(delta);
|
2017-09-19 04:19:02 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
_continue = false;
|
2017-09-19 05:40:13 +02:00
|
|
|
return Status::OK();
|
2017-09-19 04:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::handler::Continue()
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return _continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-01-30 18:58:36 +01:00
|
|
|
// txn
|
2017-09-19 04:19:02 +02:00
|
|
|
//
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::txn(database &d)
|
2018-03-23 04:48:23 +01:00
|
|
|
:txn{d, opts{}}
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::txn(database &d,
|
2017-09-19 04:19:02 +02:00
|
|
|
const opts &opts)
|
|
|
|
:d{&d}
|
|
|
|
,wb
|
|
|
|
{
|
|
|
|
std::make_unique<rocksdb::WriteBatch>(opts.reserve_bytes, opts.max_bytes)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-23 04:48:23 +01:00
|
|
|
ircd::db::txn::txn(database &d,
|
|
|
|
std::unique_ptr<rocksdb::WriteBatch> &&wb)
|
|
|
|
:d{&d}
|
|
|
|
,wb{std::move(wb)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::~txn()
|
2017-09-19 04:19:02 +02:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator()(const sopts &opts)
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
assert(bool(d));
|
|
|
|
operator()(*d, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::operator()(database &d,
|
2017-09-19 04:19:02 +02:00
|
|
|
const sopts &opts)
|
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
commit(d, *wb, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-30 18:58:36 +01:00
|
|
|
ircd::db::txn::clear()
|
2017-09-19 04:19:02 +02:00
|
|
|
{
|
|
|
|
assert(bool(wb));
|
|
|
|
wb->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-09-28 03:25:39 +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)
|
|
|
|
{
|
2017-09-28 03:25:39 +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)
|
|
|
|
{
|
|
|
|
return 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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2017-09-28 03:25:39 +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
|
|
|
{
|
2018-04-17 00:16:51 +02:00
|
|
|
closure(std::get<delta.VAL>(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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Checkpoint
|
|
|
|
//
|
|
|
|
|
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() };
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
db::column c{d[std::get<1>(delta)]};
|
|
|
|
db::append(*t.wb, c, db::column::delta
|
|
|
|
{
|
|
|
|
std::get<op>(delta),
|
|
|
|
std::get<2>(delta),
|
|
|
|
std::get<3>(delta)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:02:47 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// db/index.h
|
|
|
|
//
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
const ircd::db::gopts
|
|
|
|
ircd::db::index::applied_opts
|
2017-09-08 11:02:47 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
{ get::PREFIX }
|
|
|
|
};
|
2017-09-08 11:02:47 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
template<class pos>
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::seek(index::const_iterator_base &it,
|
2018-05-25 11:34:44 +02:00
|
|
|
const pos &p)
|
2017-09-22 05:08:11 +02:00
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
it.opts |= index::applied_opts;
|
|
|
|
return seek(static_cast<column::const_iterator_base &>(it), p);
|
2017-09-22 05:08:11 +02:00
|
|
|
}
|
2018-05-25 11:34:44 +02:00
|
|
|
template bool ircd::db::seek<ircd::db::pos>(index::const_iterator_base &, const pos &);
|
|
|
|
template bool ircd::db::seek<ircd::string_view>(index::const_iterator_base &, const string_view &);
|
2017-09-08 11:02:47 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
ircd::db::index::const_iterator
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::index::begin(const string_view &key,
|
|
|
|
gopts opts)
|
2017-09-22 05:08:11 +02:00
|
|
|
{
|
|
|
|
const_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(opts)
|
2017-09-22 05:08:11 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
seek(ret, key);
|
2017-09-22 05:08:11 +02:00
|
|
|
return ret;
|
2017-09-08 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::index::const_iterator
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::index::end(const string_view &key,
|
|
|
|
gopts opts)
|
2017-09-08 11:02:47 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
const_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(opts)
|
2017-09-22 05:08:11 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
if(seek(ret, key))
|
|
|
|
seek(ret, pos::END);
|
2017-09-22 12:31:44 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return ret;
|
2017-09-08 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-24 04:47:36 +02:00
|
|
|
/// 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
|
|
|
|
/// iterations of an index shoud only be used for debugging and statistics! The
|
|
|
|
/// index should be ordered the way it will be primarily accessed using the
|
|
|
|
/// comparator. If it will be accessed in different directions, make another
|
|
|
|
/// index column.
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::index::const_reverse_iterator
|
|
|
|
ircd::db::index::rbegin(const string_view &key,
|
|
|
|
gopts opts)
|
2017-09-08 11:02:47 +02:00
|
|
|
{
|
2017-09-22 12:31:44 +02:00
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(opts)
|
2017-09-22 12:31:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
if(seek(ret, key))
|
2017-09-24 04:47:36 +02:00
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
while(seek(ret, pos::NEXT));
|
|
|
|
seek(ret, pos::PREV);
|
2017-09-24 04:47:36 +02:00
|
|
|
}
|
2017-09-22 12:31:44 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::index::const_reverse_iterator
|
|
|
|
ircd::db::index::rend(const string_view &key,
|
|
|
|
gopts opts)
|
|
|
|
{
|
|
|
|
const_reverse_iterator ret
|
|
|
|
{
|
2018-05-25 11:34:44 +02:00
|
|
|
c, {}, std::move(opts)
|
2017-09-22 12:31:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-25 11:34:44 +02:00
|
|
|
if(seek(ret, key))
|
|
|
|
seek(ret, pos::END);
|
2017-09-22 12:31:44 +02:00
|
|
|
|
|
|
|
return ret;
|
2017-09-08 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// const_iterator
|
|
|
|
//
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
ircd::db::index::const_iterator &
|
|
|
|
ircd::db::index::const_iterator::operator--()
|
2017-09-08 11:02:47 +02:00
|
|
|
{
|
2017-09-22 12:31:44 +02:00
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::index::const_iterator &
|
|
|
|
ircd::db::index::const_iterator::operator++()
|
|
|
|
{
|
2017-09-22 12:31:44 +02:00
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return *this;
|
2017-09-08 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::index::const_reverse_iterator &
|
|
|
|
ircd::db::index::const_reverse_iterator::operator--()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::NEXT);
|
|
|
|
else
|
|
|
|
seek(*this, pos::FRONT);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::index::const_reverse_iterator &
|
|
|
|
ircd::db::index::const_reverse_iterator::operator++()
|
|
|
|
{
|
|
|
|
if(likely(bool(*this)))
|
|
|
|
seek(*this, pos::PREV);
|
|
|
|
else
|
|
|
|
seek(*this, pos::BACK);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::index::const_iterator_base::value_type &
|
|
|
|
ircd::db::index::const_iterator_base::operator*()
|
2017-09-08 11:02:47 +02:00
|
|
|
const
|
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
const auto &prefix
|
|
|
|
{
|
|
|
|
describe(*c).prefix
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fetch the full value like a standard column first
|
2017-09-22 12:31:44 +02:00
|
|
|
column::const_iterator_base::operator*();
|
2017-09-22 05:08:11 +02:00
|
|
|
string_view &key{val.first};
|
|
|
|
|
|
|
|
// When there's no prefixing this index column is just
|
|
|
|
// like a normal column. Otherwise, we remove the prefix
|
|
|
|
// from the key the user will end up seeing.
|
2017-09-08 11:02:47 +02:00
|
|
|
if(prefix.has && prefix.has(key))
|
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
const auto &first(prefix.get(key));
|
|
|
|
const auto &second(key.substr(first.size()));
|
2017-09-08 11:02:47 +02:00
|
|
|
key = second;
|
|
|
|
}
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return val;
|
2017-09-08 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
const ircd::db::index::const_iterator_base::value_type *
|
|
|
|
ircd::db::index::const_iterator_base::operator->()
|
2017-09-08 11:02:47 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
return &this->operator*();
|
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-04-03 06:02:32 +02:00
|
|
|
// db/cell.h
|
2017-03-24 02:36:49 +01:00
|
|
|
//
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::sequence(const cell &c)
|
|
|
|
{
|
|
|
|
const database::snapshot &ss(c);
|
|
|
|
return sequence(database::snapshot(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const cell &c)
|
|
|
|
{
|
|
|
|
return name(c.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const cell::delta &delta,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(&delta, &delta + 1, sopts);
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
void
|
|
|
|
ircd::db::write(const sopts &sopts,
|
|
|
|
const std::initializer_list<cell::delta> &deltas)
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
write(deltas, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const std::initializer_list<cell::delta> &deltas,
|
|
|
|
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
|
|
|
|
ircd::db::write(const cell::delta *const &begin,
|
|
|
|
const cell::delta *const &end,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
if(begin == end)
|
2017-04-03 06:02:32 +02:00
|
|
|
return;
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-08-23 22:37:47 +02: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);
|
2017-08-29 03:44:27 +02:00
|
|
|
column &c(std::get<cell *>(front)->c);
|
2017-04-03 06:02:32 +02:00
|
|
|
database &d(c);
|
|
|
|
|
|
|
|
rocksdb::WriteBatch batch;
|
2017-08-23 22:37:47 +02:00
|
|
|
std::for_each(begin, end, [&batch]
|
|
|
|
(const cell::delta &delta)
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
append(batch, delta);
|
2017-08-23 22:37:47 +02:00
|
|
|
});
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
commit(d, batch, sopts);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 23:05:15 +02:00
|
|
|
template<class pos>
|
|
|
|
bool
|
|
|
|
ircd::db::seek(cell &c,
|
2018-02-06 00:15:02 +01:00
|
|
|
const pos &p,
|
|
|
|
gopts opts)
|
2017-08-30 23:05:15 +02:00
|
|
|
{
|
|
|
|
column &cc(c);
|
|
|
|
database::column &dc(cc);
|
|
|
|
|
2018-02-06 00:15:02 +01:00
|
|
|
if(!opts.snapshot)
|
|
|
|
opts.snapshot = c.ss;
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
const auto ropts(make_opts(opts));
|
2017-08-30 23:05:15 +02:00
|
|
|
return seek(dc, p, ropts, c.it);
|
|
|
|
}
|
2018-02-06 00:15:02 +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
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::cell()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-14 21:59:20 +02:00
|
|
|
ircd::db::cell::cell(database &d,
|
|
|
|
const string_view &colname,
|
|
|
|
gopts opts)
|
|
|
|
:cell
|
|
|
|
{
|
|
|
|
column(d[colname]), std::unique_ptr<rocksdb::Iterator>{}, std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::cell::cell(database &d,
|
|
|
|
const string_view &colname,
|
|
|
|
const string_view &index,
|
|
|
|
gopts opts)
|
|
|
|
:cell
|
|
|
|
{
|
|
|
|
column(d[colname]), index, std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
const string_view &index,
|
|
|
|
gopts opts)
|
|
|
|
:c{std::move(column)}
|
|
|
|
,ss{opts.snapshot}
|
2018-08-24 14:33:18 +02:00
|
|
|
,it
|
|
|
|
{
|
|
|
|
!index.empty()?
|
|
|
|
seek(this->c, index, opts):
|
|
|
|
std::unique_ptr<rocksdb::Iterator>{}
|
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2017-09-14 21:59:20 +02:00
|
|
|
if(bool(this->it))
|
2017-09-16 20:48:09 +02:00
|
|
|
if(!valid_eq(*this->it, index))
|
2017-09-14 21:59:20 +02:00
|
|
|
this->it.reset();
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
const string_view &index,
|
2017-08-23 22:37:47 +02:00
|
|
|
std::unique_ptr<rocksdb::Iterator> it,
|
|
|
|
gopts opts)
|
2017-04-03 06:02:32 +02:00
|
|
|
:c{std::move(column)}
|
2017-09-14 21:59:20 +02:00
|
|
|
,ss{opts.snapshot}
|
|
|
|
,it{std::move(it)}
|
|
|
|
{
|
2017-09-23 06:55:31 +02:00
|
|
|
if(index.empty())
|
|
|
|
return;
|
|
|
|
|
2018-02-06 00:15:02 +01:00
|
|
|
seek(*this, index, opts);
|
2017-09-16 20:48:09 +02:00
|
|
|
if(!valid_eq(*this->it, index))
|
2017-09-14 21:59:20 +02:00
|
|
|
this->it.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cell::cell(column column,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> it,
|
|
|
|
gopts opts)
|
|
|
|
:c{std::move(column)}
|
2017-08-23 22:37:47 +02:00
|
|
|
,ss{std::move(opts.snapshot)}
|
2017-04-03 06:02:32 +02:00
|
|
|
,it{std::move(it)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::cell(cell &&o)
|
2017-03-31 00:57:08 +02:00
|
|
|
noexcept
|
2017-04-03 06:02:32 +02:00
|
|
|
:c{std::move(o.c)}
|
|
|
|
,ss{std::move(o.ss)}
|
|
|
|
,it{std::move(o.it)}
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::cell::operator=(cell &&o)
|
2017-03-31 00:57:08 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
c = std::move(o.c);
|
|
|
|
ss = std::move(o.ss);
|
|
|
|
it = std::move(o.it);
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
// Linkage for incomplete rocksdb::Iterator
|
|
|
|
ircd::db::cell::~cell()
|
2017-03-31 00:57:08 +02:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
bool
|
2017-09-14 21:59:20 +02:00
|
|
|
ircd::db::cell::load(const string_view &index,
|
|
|
|
gopts opts)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
database &d(c);
|
2017-09-22 02:01:29 +02:00
|
|
|
if(valid(index) && !opts.snapshot && sequence(ss) == sequence(d))
|
2017-04-03 06:02:32 +02:00
|
|
|
return true;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
if(bool(opts.snapshot))
|
|
|
|
{
|
|
|
|
this->it.reset();
|
|
|
|
this->ss = std::move(opts.snapshot);
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
database::column &c(this->c);
|
2017-08-30 23:05:15 +02:00
|
|
|
return seek(c, index, opts, this->it);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2017-03-24 02:36:49 +01:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::cell::operator=(const string_view &s)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-08-30 23:21:18 +02:00
|
|
|
write(c, key(), s);
|
2017-04-03 06:02:32 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
void
|
|
|
|
ircd::db::cell::operator()(const op &op,
|
|
|
|
const string_view &val,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(cell::delta{op, *this, val}, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cell::operator
|
|
|
|
string_view()
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
return val();
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
ircd::db::cell::operator
|
|
|
|
string_view()
|
2017-04-03 06:02:32 +02:00
|
|
|
const
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return val();
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::val()
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
if(!valid())
|
|
|
|
load();
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
return likely(valid())? db::val(*it) : string_view{};
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::key()
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
if(!valid())
|
|
|
|
load();
|
|
|
|
|
2017-09-14 21:59:20 +02:00
|
|
|
return likely(valid())? db::key(*it) : string_view{};
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::val()
|
|
|
|
const
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return likely(valid())? db::val(*it) : string_view{};
|
2017-03-24 02:36:49 +01:00
|
|
|
}
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::db::cell::key()
|
|
|
|
const
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-09-14 21:59:20 +02:00
|
|
|
return likely(valid())? db::key(*it) : string_view{};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-16 20:48:09 +02:00
|
|
|
ircd::db::cell::valid()
|
2017-09-14 21:59:20 +02:00
|
|
|
const
|
|
|
|
{
|
2017-09-16 20:48:09 +02:00
|
|
|
return bool(it) && db::valid(*it);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-16 20:48:09 +02:00
|
|
|
ircd::db::cell::valid(const string_view &s)
|
2017-04-03 06:02:32 +02:00
|
|
|
const
|
|
|
|
{
|
2017-09-16 20:48:09 +02:00
|
|
|
return bool(it) && db::valid_eq(*it, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::cell::valid_gt(const string_view &s)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return bool(it) && db::valid_gt(*it, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::cell::valid_lte(const string_view &s)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return bool(it) && db::valid_lte(*it, s);
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2017-03-31 00:57:08 +02:00
|
|
|
//
|
2017-04-03 06:02:32 +02:00
|
|
|
// db/row.h
|
2017-03-31 00:57:08 +02:00
|
|
|
//
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
void
|
|
|
|
ircd::db::del(row &row,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(row::delta{op::DELETE, row}, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const row::delta &delta,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(&delta, &delta + 1, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const sopts &sopts,
|
|
|
|
const std::initializer_list<row::delta> &deltas)
|
|
|
|
{
|
|
|
|
write(deltas, sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const std::initializer_list<row::delta> &deltas,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(std::begin(deltas), std::end(deltas), sopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::write(const row::delta *const &begin,
|
|
|
|
const row::delta *const &end,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2017-08-29 03:44:27 +02:00
|
|
|
const auto &row(std::get<row *>(delta));
|
|
|
|
return ret += row->size();
|
2017-08-23 22:37:47 +02:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: allocator?
|
|
|
|
std::vector<cell::delta> deltas;
|
|
|
|
deltas.reserve(cells);
|
|
|
|
|
|
|
|
// Compose all of the cells from all of the rows into a single txn
|
|
|
|
std::for_each(begin, end, [&deltas]
|
|
|
|
(const auto &delta)
|
|
|
|
{
|
|
|
|
const auto &op(std::get<op>(delta));
|
2017-08-29 03:44:27 +02:00
|
|
|
const auto &row(std::get<row *>(delta));
|
|
|
|
std::for_each(std::begin(*row), std::end(*row), [&deltas, &op]
|
2017-08-23 22:37:47 +02:00
|
|
|
(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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Commitment
|
|
|
|
write(&deltas.front(), &deltas.front() + deltas.size(), sopts);
|
|
|
|
}
|
|
|
|
|
2018-08-19 05:59:28 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::seek(row &r,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
2018-08-19 06:02:42 +02:00
|
|
|
// This frame can't be interrupted because it may have requests
|
|
|
|
// pending in the request pool which must synchronize back here.
|
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
2018-08-19 05:59:28 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
const ircd::timer timer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
size_t ret{0};
|
|
|
|
ctx::latch latch{r.size()};
|
|
|
|
const auto closure{[&latch, &ret, &key]
|
|
|
|
(auto &cell)
|
|
|
|
{
|
|
|
|
ret += bool(seek(cell, key));
|
|
|
|
latch.count_down();
|
|
|
|
}};
|
|
|
|
|
|
|
|
for(auto &cell : r)
|
|
|
|
{
|
|
|
|
db::column &column(cell);
|
2018-09-27 04:02:09 +02:00
|
|
|
//TODO: should check a bloom filter on the cache for this branch
|
|
|
|
//TODO: because right now double-querying the cache is gross.
|
2018-08-19 05:59:28 +02:00
|
|
|
if(!exists(cache(column), key))
|
|
|
|
request([&closure, &cell]
|
|
|
|
{
|
|
|
|
closure(cell);
|
|
|
|
});
|
|
|
|
else
|
|
|
|
closure(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
latch.wait();
|
|
|
|
|
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
const column &c(r[0]);
|
|
|
|
const database &d(c);
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s' %lu:%lu '%s' row SEEK KEY %zu of %zu in %ld$us",
|
2018-05-29 10:42:48 +02:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(r[0]),
|
|
|
|
name(c),
|
|
|
|
ret,
|
|
|
|
r.size(),
|
|
|
|
timer.at<microseconds>().count()
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 04:30:25 +02:00
|
|
|
assert(ret <= r.size());
|
2017-09-23 10:26:17 +02:00
|
|
|
return ret;
|
2017-08-30 23:05:15 +02:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:20:13 +02:00
|
|
|
//
|
|
|
|
// row
|
|
|
|
//
|
2017-08-30 23:05:15 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::row::row(database &d,
|
|
|
|
const string_view &key,
|
2018-05-13 03:26:49 +02:00
|
|
|
const vector_view<const string_view> &colnames,
|
2017-09-29 06:19:02 +02:00
|
|
|
const vector_view<cell> &buf,
|
2017-08-23 22:37:47 +02:00
|
|
|
gopts opts)
|
2018-05-20 08:13:54 +02:00
|
|
|
:vector_view<cell>
|
|
|
|
{
|
|
|
|
buf.data(),
|
|
|
|
colnames.empty()?
|
|
|
|
d.columns.size():
|
|
|
|
colnames.size()
|
|
|
|
}
|
2017-03-24 02:36:49 +01:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
using std::end;
|
|
|
|
using std::begin;
|
|
|
|
using rocksdb::Iterator;
|
|
|
|
using rocksdb::ColumnFamilyHandle;
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
if(!opts.snapshot)
|
|
|
|
opts.snapshot = database::snapshot(d);
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
const rocksdb::ReadOptions options
|
|
|
|
{
|
|
|
|
make_opts(opts)
|
|
|
|
};
|
|
|
|
|
2018-05-20 08:13:54 +02:00
|
|
|
const size_t &column_count
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2018-05-20 08:13:54 +02:00
|
|
|
vector_view<cell>::size()
|
2017-04-03 06:02:32 +02:00
|
|
|
};
|
|
|
|
|
2018-05-13 03:26:08 +02:00
|
|
|
database::column *colptr[column_count];
|
2017-04-03 06:02:32 +02:00
|
|
|
if(colnames.empty())
|
2018-10-22 16:09:55 +02:00
|
|
|
std::transform(begin(d.column_names), end(d.column_names), colptr, [&colnames]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const auto &p)
|
|
|
|
{
|
2018-10-22 16:09:55 +02:00
|
|
|
return p.second.get();
|
2017-04-03 06:02:32 +02:00
|
|
|
});
|
|
|
|
else
|
2018-05-13 03:26:08 +02:00
|
|
|
std::transform(begin(colnames), end(colnames), colptr, [&d]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const auto &name)
|
|
|
|
{
|
|
|
|
return &d[name];
|
|
|
|
});
|
|
|
|
|
|
|
|
std::vector<Iterator *> iterators;
|
|
|
|
{
|
2018-11-06 01:37:58 +01:00
|
|
|
// The goal here is to optimize away the heap allocation incurred by
|
|
|
|
// having to pass RocksDB the specific std::vector type which doesn't
|
|
|
|
// have room for an allocator. We use a single thread_local vector
|
|
|
|
// and reserve() it with one worst-case size of all possible columns.
|
|
|
|
// Then we resize it to this specific call's requirements and copy the
|
|
|
|
// column pointers. On sane platforms only one allocation ever occurs.
|
2018-10-16 10:23:01 +02:00
|
|
|
const ctx::critical_assertion ca;
|
2018-11-06 01:37:58 +01:00
|
|
|
thread_local std::vector<ColumnFamilyHandle *> handles;
|
|
|
|
assert(column_count <= d.columns.size());
|
|
|
|
handles.reserve(d.columns.size());
|
|
|
|
handles.resize(column_count);
|
|
|
|
std::transform(colptr, colptr + column_count, begin(handles), []
|
|
|
|
(database::column *const &ptr)
|
|
|
|
{
|
|
|
|
return ptr->handle.get();
|
|
|
|
});
|
|
|
|
|
2018-08-20 04:30:17 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->NewIterators(options, handles, &iterators)
|
|
|
|
};
|
|
|
|
}
|
2017-04-03 06:02:32 +02:00
|
|
|
|
2018-05-13 03:26:08 +02:00
|
|
|
for(size_t i(0); i < this->size() && i < column_count; ++i)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> it(iterators.at(i));
|
2018-08-19 05:59:28 +02:00
|
|
|
(*this)[i] = cell { *colptr[i], std::move(it), opts };
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
2018-08-19 05:59:28 +02:00
|
|
|
|
|
|
|
if(key)
|
|
|
|
seek(*this, key);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::row::operator()(const op &op,
|
|
|
|
const string_view &col,
|
|
|
|
const string_view &val,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
write(cell::delta{op, (*this)[col], val}, sopts);
|
|
|
|
}
|
|
|
|
|
2017-09-22 02:00:48 +02:00
|
|
|
ircd::db::cell &
|
|
|
|
ircd::db::row::operator[](const string_view &column)
|
|
|
|
{
|
|
|
|
const auto it(find(column));
|
|
|
|
if(unlikely(it == end()))
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"column '%s' not specified in the descriptor schema", column
|
|
|
|
};
|
2017-09-22 02:00:48 +02:00
|
|
|
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::cell &
|
|
|
|
ircd::db::row::operator[](const string_view &column)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const auto it(find(column));
|
|
|
|
if(unlikely(it == end()))
|
2018-05-29 10:09:15 +02:00
|
|
|
throw schema_error
|
|
|
|
{
|
|
|
|
"column '%s' not specified in the descriptor schema", column
|
|
|
|
};
|
2017-09-22 02:00:48 +02:00
|
|
|
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::row::iterator
|
|
|
|
ircd::db::row::find(const string_view &col)
|
|
|
|
{
|
2017-09-29 06:19:02 +02:00
|
|
|
return std::find_if(std::begin(*this), std::end(*this), [&col]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return name(cell.c) == col;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::row::const_iterator
|
|
|
|
ircd::db::row::find(const string_view &col)
|
|
|
|
const
|
|
|
|
{
|
2017-09-29 06:19:02 +02:00
|
|
|
return std::find_if(std::begin(*this), std::end(*this), [&col]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return name(cell.c) == col;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-30 23:22:19 +02:00
|
|
|
bool
|
|
|
|
ircd::db::row::valid()
|
|
|
|
const
|
|
|
|
{
|
2017-09-29 06:19:02 +02:00
|
|
|
return std::any_of(std::begin(*this), std::end(*this), []
|
2017-08-30 23:22:19 +02:00
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return cell.valid();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-16 20:48:09 +02:00
|
|
|
bool
|
|
|
|
ircd::db::row::valid(const string_view &s)
|
|
|
|
const
|
|
|
|
{
|
2017-09-29 06:19:02 +02:00
|
|
|
return std::any_of(std::begin(*this), std::end(*this), [&s]
|
2017-09-16 20:48:09 +02:00
|
|
|
(const auto &cell)
|
|
|
|
{
|
|
|
|
return cell.valid(s);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// db/column.h
|
|
|
|
//
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
std::string ret;
|
2018-05-05 00:55:21 +02:00
|
|
|
const auto closure([&ret]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const string_view &src)
|
|
|
|
{
|
|
|
|
ret.assign(begin(src), end(src));
|
|
|
|
});
|
|
|
|
|
2018-05-05 00:55:21 +02:00
|
|
|
column(key, closure, gopts);
|
2017-04-03 06:02:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
2018-01-26 18:58:35 +01:00
|
|
|
const mutable_buffer &buf,
|
2017-04-03 06:02:32 +02:00
|
|
|
const gopts &gopts)
|
|
|
|
{
|
2018-05-05 00:55:21 +02:00
|
|
|
string_view ret;
|
|
|
|
const auto closure([&ret, &buf]
|
2017-04-03 06:02:32 +02:00
|
|
|
(const string_view &src)
|
|
|
|
{
|
2018-05-05 00:55:21 +02:00
|
|
|
ret = { data(buf), copy(buf, src) };
|
2017-04-03 06:02:32 +02:00
|
|
|
});
|
|
|
|
|
2018-05-05 00:55:21 +02:00
|
|
|
column(key, closure, gopts);
|
|
|
|
return ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2018-05-05 00:57:50 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::read(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
bool &found,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
const auto closure([&ret]
|
|
|
|
(const string_view &src)
|
|
|
|
{
|
|
|
|
ret.assign(begin(src), end(src));
|
|
|
|
});
|
|
|
|
|
|
|
|
found = column(key, std::nothrow, closure, gopts);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) };
|
|
|
|
});
|
|
|
|
|
|
|
|
found = column(key, std::nothrow, closure, gopts);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:17:43 +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();
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
template<>
|
2018-04-03 19:58:16 +02:00
|
|
|
ircd::db::prop_str
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::property(const column &column,
|
2017-04-03 06:02:32 +02:00
|
|
|
const string_view &name)
|
|
|
|
{
|
|
|
|
std::string ret;
|
2018-03-23 03:35:50 +01:00
|
|
|
database::column &c(const_cast<db::column &>(column));
|
|
|
|
database &d(const_cast<db::column &>(column));
|
2018-04-13 03:57:03 +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)
|
|
|
|
};
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2018-04-03 19:58:16 +02:00
|
|
|
ircd::db::prop_int
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::property(const column &column,
|
2017-04-03 06:02:32 +02:00
|
|
|
const string_view &name)
|
|
|
|
{
|
2018-09-26 00:07:56 +02:00
|
|
|
uint64_t ret(0);
|
2018-03-23 03:35:50 +01:00
|
|
|
database::column &c(const_cast<db::column &>(column));
|
|
|
|
database &d(const_cast<db::column &>(column));
|
2017-04-03 06:02:32 +02:00
|
|
|
if(!d.d->GetIntProperty(c, slice(name), &ret))
|
2018-04-13 03:57:03 +02:00
|
|
|
throw not_found
|
|
|
|
{
|
|
|
|
"property '%s' for column '%s' in '%s' not found or not an integer.",
|
|
|
|
name,
|
|
|
|
db::name(column),
|
|
|
|
db::name(d)
|
|
|
|
};
|
2017-04-03 06:02:32 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-03 20:05:03 +02:00
|
|
|
template<>
|
|
|
|
ircd::db::prop_map
|
|
|
|
ircd::db::property(const column &column,
|
|
|
|
const string_view &name)
|
|
|
|
{
|
2018-04-09 21:55:22 +02:00
|
|
|
std::map<std::string, std::string> ret;
|
2018-04-03 20:05:03 +02:00
|
|
|
database::column &c(const_cast<db::column &>(column));
|
|
|
|
database &d(const_cast<db::column &>(column));
|
2018-04-13 03:57:03 +02:00
|
|
|
if(!d.d->GetMapProperty(c, slice(name), &ret))
|
|
|
|
ret.emplace(std::string{name}, property<std::string>(column, name));
|
|
|
|
|
2018-04-03 20:05:03 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
size_t
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::bytes(const column &column)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyMetaData cfm;
|
2018-03-23 03:35:50 +01:00
|
|
|
database &d(const_cast<db::column &>(column));
|
|
|
|
database::column &c(const_cast<db::column &>(column));
|
2017-04-03 06:02:32 +02:00
|
|
|
assert(bool(c.handle));
|
|
|
|
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
|
|
|
return cfm.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2018-03-23 03:35:50 +01:00
|
|
|
ircd::db::file_count(const column &column)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyMetaData cfm;
|
2018-03-23 03:35:50 +01:00
|
|
|
database &d(const_cast<db::column &>(column));
|
|
|
|
database::column &c(const_cast<db::column &>(column));
|
2017-04-03 06:02:32 +02:00
|
|
|
assert(bool(c.handle));
|
|
|
|
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
|
|
|
|
return cfm.file_count;
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
uint32_t
|
|
|
|
ircd::db::id(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return id(c);
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
const std::string &
|
|
|
|
ircd::db::name(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return name(c);
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor &
|
2017-09-21 05:38:39 +02:00
|
|
|
ircd::db::describe(const column &column)
|
|
|
|
{
|
|
|
|
const database::column &c(column);
|
|
|
|
return describe(c);
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:56:46 +02:00
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::files(const column &column)
|
|
|
|
{
|
|
|
|
database::column &c(const_cast<db::column &>(column));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:13 +02:00
|
|
|
void
|
|
|
|
ircd::db::drop(column &column)
|
|
|
|
{
|
|
|
|
database::column &c(column);
|
|
|
|
drop(c);
|
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
void
|
2018-04-27 02:19:29 +02:00
|
|
|
ircd::db::sort(column &column,
|
|
|
|
const bool &blocking)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
database::column &c(column);
|
2018-04-20 23:12:57 +02:00
|
|
|
database &d(*c.d);
|
2018-08-20 03:35:42 +02:00
|
|
|
|
2018-04-20 23:12:57 +02:00
|
|
|
rocksdb::FlushOptions opts;
|
|
|
|
opts.wait = blocking;
|
2018-08-20 04:30:17 +02:00
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-08-20 03:35:42 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
log, "'%s':'%s' @%lu FLUSH (sort) %s",
|
2018-08-20 03:35:42 +02:00
|
|
|
name(d),
|
|
|
|
name(c),
|
2018-08-29 06:53:17 +02:00
|
|
|
sequence(d),
|
|
|
|
blocking? "blocking"_sv: "non-blocking"_sv
|
2018-08-20 03:35:42 +02:00
|
|
|
};
|
2018-04-20 23:12:57 +02:00
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->Flush(opts, c)
|
|
|
|
};
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 11:42:57 +02:00
|
|
|
void
|
|
|
|
ircd::db::compact(column &column,
|
2018-09-20 01:36:01 +02:00
|
|
|
const int &level_,
|
|
|
|
const compactor &cb)
|
2018-04-15 11:42:57 +02:00
|
|
|
{
|
|
|
|
database::column &c(column);
|
2018-04-20 23:12:57 +02:00
|
|
|
database &d(*c.d);
|
|
|
|
|
2018-04-21 01:48:07 +02:00
|
|
|
rocksdb::ColumnFamilyMetaData cfmd;
|
|
|
|
d.d->GetColumnFamilyMetaData(c, &cfmd);
|
|
|
|
for(const auto &level : cfmd.levels)
|
|
|
|
{
|
2018-05-11 01:41:34 +02:00
|
|
|
if(level_ != -1 && level.level != level_)
|
|
|
|
continue;
|
|
|
|
|
2018-04-21 01:48:07 +02:00
|
|
|
if(level.files.empty())
|
|
|
|
continue;
|
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
rocksdb::CompactionOptions opts;
|
2018-04-21 01:48:07 +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);
|
|
|
|
});
|
|
|
|
|
2018-08-27 05:24:38 +02:00
|
|
|
// Locking the write_mutex here prevents writes during a column's
|
|
|
|
// compaction. This is needed because if contention occurs inside
|
|
|
|
// rocksdb we will hit some std::mutex's which do not use the
|
|
|
|
// rocksdb::port wrapper and deadlock the process. (It is an error
|
|
|
|
// on the part of rocksdb to directly use std::mutex rather than their
|
|
|
|
// port wrapper).
|
|
|
|
ctx::interruption_point();
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-08-29 06:53:17 +02:00
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-09-20 01:36:01 +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);
|
|
|
|
}};
|
|
|
|
|
|
|
|
c.cfilter.user = cb;
|
|
|
|
|
2018-05-11 01:41:34 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s':'%s' COMPACT level:%d files:%zu size:%zu",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
level.level,
|
|
|
|
level.files.size(),
|
|
|
|
level.size
|
|
|
|
};
|
2018-04-21 01:48:07 +02:00
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->CompactFiles(opts, c, files, level.level)
|
|
|
|
};
|
|
|
|
}
|
2018-04-15 11:42:57 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 01:41:34 +02:00
|
|
|
void
|
|
|
|
ircd::db::compact(column &column,
|
|
|
|
const std::pair<string_view, string_view> &range,
|
2018-09-21 08:30:00 +02:00
|
|
|
const int &to_level,
|
2018-09-20 01:36:01 +02:00
|
|
|
const compactor &cb)
|
2018-05-11 01:41:34 +02:00
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
database &d(column);
|
2018-05-11 01:41:34 +02:00
|
|
|
database::column &c(column);
|
|
|
|
|
|
|
|
const auto begin(slice(range.first));
|
|
|
|
const rocksdb::Slice *const b
|
|
|
|
{
|
|
|
|
empty(range.first)? nullptr : &begin
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto end(slice(range.second));
|
|
|
|
const rocksdb::Slice *const e
|
|
|
|
{
|
|
|
|
empty(range.second)? nullptr : &end
|
|
|
|
};
|
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
rocksdb::CompactRangeOptions opts;
|
|
|
|
opts.change_level = true;
|
2018-09-21 08:30:00 +02:00
|
|
|
opts.target_level = std::max(to_level, -1);
|
2018-08-29 06:53:17 +02:00
|
|
|
opts.allow_write_stall = true;
|
|
|
|
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-09-20 01:36:01 +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);
|
|
|
|
}};
|
|
|
|
|
|
|
|
c.cfilter.user = cb;
|
|
|
|
|
2018-05-11 01:41:34 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s':'%s' @%lu COMPACT [%s, %s] to level %d",
|
|
|
|
name(d),
|
|
|
|
name(c),
|
|
|
|
sequence(d),
|
|
|
|
range.first,
|
|
|
|
range.second,
|
2018-09-20 01:36:01 +02:00
|
|
|
opts.target_level
|
2018-05-11 01:41:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->CompactRange(opts, c, b, e)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-20 23:10:59 +02:00
|
|
|
void
|
|
|
|
ircd::db::setopt(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &val)
|
|
|
|
{
|
2018-08-29 06:53:17 +02:00
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
2018-04-20 23:10:59 +02:00
|
|
|
const std::unordered_map<std::string, std::string> options
|
|
|
|
{
|
|
|
|
{ std::string{key}, std::string{val} }
|
|
|
|
};
|
|
|
|
|
2018-08-29 06:53:17 +02:00
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-04-20 23:10:59 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->SetOptions(c, options)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-22 00:08:57 +02:00
|
|
|
void
|
|
|
|
ircd::db::ingest(column &column,
|
|
|
|
const string_view &path)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
|
|
|
|
rocksdb::IngestExternalFileOptions opts;
|
2018-09-22 23:54:04 +02:00
|
|
|
opts.allow_global_seqno = true;
|
2018-09-23 00:16:45 +02:00
|
|
|
opts.allow_blocking_flush = true;
|
2018-09-22 00:08:57 +02:00
|
|
|
|
2018-09-22 23:54:04 +02:00
|
|
|
// 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;
|
|
|
|
|
2018-09-22 00:08:57 +02:00
|
|
|
const std::vector<std::string> files
|
|
|
|
{
|
|
|
|
{ std::string{path} }
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->IngestExternalFile(c, files, opts)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-24 06:01:57 +02:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::del(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const sopts &sopts)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
database &d(column);
|
2018-08-29 06:53:17 +02:00
|
|
|
database::column &c(column);
|
|
|
|
auto opts(make_opts(sopts));
|
|
|
|
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-08-20 04:30:17 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s' %lu '%s' DELETE key(%zu B)",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
name(c),
|
|
|
|
key.size()
|
|
|
|
};
|
2016-09-24 06:01:57 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->Delete(opts, c, slice(key))
|
|
|
|
};
|
2016-09-25 06:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::write(column &column,
|
|
|
|
const string_view &key,
|
2018-04-30 16:18:06 +02:00
|
|
|
const const_buffer &val,
|
2016-09-25 06:12:43 +02:00
|
|
|
const sopts &sopts)
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
database &d(column);
|
2018-08-29 06:53:17 +02:00
|
|
|
database::column &c(column);
|
|
|
|
auto opts(make_opts(sopts));
|
|
|
|
|
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
|
|
|
const ctx::uninterruptible::nothrow ui;
|
2018-08-20 04:30:17 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s' %lu '%s' PUT key(%zu B) val(%zu B)",
|
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
name(c),
|
|
|
|
size(key),
|
|
|
|
size(val)
|
|
|
|
};
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->Put(opts, c, slice(key), slice(val))
|
|
|
|
};
|
2016-09-25 06:12:43 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 13:38:30 +02:00
|
|
|
void
|
|
|
|
ircd::db::prefetch(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
if(exists(cache(column), key))
|
|
|
|
return;
|
|
|
|
|
|
|
|
request([column(column), key(std::string(key)), gopts]
|
|
|
|
() mutable
|
|
|
|
{
|
|
|
|
has(column, key, gopts);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-19 05:40:23 +02:00
|
|
|
bool
|
|
|
|
ircd::db::cached(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &gopts)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
|
|
|
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
opts.read_tier = NON_BLOCKING;
|
|
|
|
opts.fill_cache = false;
|
|
|
|
|
|
|
|
std::unique_ptr<rocksdb::Iterator> it;
|
|
|
|
if(!seek(c, key, opts, it))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(bool(it));
|
|
|
|
return valid_eq(*it, key);
|
|
|
|
}
|
|
|
|
|
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
|
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.
|
2018-10-21 13:41:21 +02:00
|
|
|
if(0 && c.table_opts.filter_policy)
|
2018-10-16 10:21:42 +02:00
|
|
|
{
|
|
|
|
const auto k(slice(key));
|
|
|
|
auto opts(make_opts(gopts));
|
|
|
|
opts.read_tier = NON_BLOCKING;
|
|
|
|
thread_local std::string discard;
|
|
|
|
if(!d.d->KeyMayExist(opts, c, k, &discard, nullptr))
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-28 01:48:27 +02:00
|
|
|
|
2018-09-01 13:06:13 +02:00
|
|
|
const auto it
|
2017-03-31 01:20:01 +02:00
|
|
|
{
|
2018-09-01 13:06:13 +02:00
|
|
|
seek(column, key, gopts)
|
|
|
|
};
|
2018-04-10 01:57:13 +02:00
|
|
|
|
2018-09-01 13:06:13 +02:00
|
|
|
return valid_eq(*it, key);
|
2017-03-31 01:20:01 +02:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:13:50 +02:00
|
|
|
//
|
|
|
|
// column
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::column::column(database::column &c)
|
|
|
|
:c{&c}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::column::column(database &d,
|
|
|
|
const string_view &column_name)
|
|
|
|
:c{&d[column_name]}
|
|
|
|
{}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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()
|
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)
|
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
|
|
|
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
|
|
|
|
{
|
|
|
|
return &operator*();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::column::const_iterator_base::operator!()
|
2016-09-26 06:07:22 +02:00
|
|
|
const
|
|
|
|
{
|
2017-09-16 20:48:09 +02:00
|
|
|
return !static_cast<bool>(*this);
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:31:44 +02:00
|
|
|
ircd::db::column::const_iterator_base::operator bool()
|
2016-09-26 06:07:22 +02:00
|
|
|
const
|
|
|
|
{
|
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)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
return !(a == b);
|
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)
|
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) == 0;
|
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;
|
|
|
|
|
|
|
|
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)
|
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)
|
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);
|
2018-11-16 05:54:50 +01:00
|
|
|
return seek(c, p, 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
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// comparator.h
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// linkage placements for integer comparators so they all have the same addr
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::cmp_int64_t::cmp_int64_t()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cmp_int64_t::~cmp_int64_t()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cmp_uint64_t::cmp_uint64_t()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::cmp_uint64_t::~cmp_uint64_t()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::reverse_cmp_int64_t::reverse_cmp_int64_t()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::reverse_cmp_int64_t::~reverse_cmp_int64_t()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::reverse_cmp_uint64_t::reverse_cmp_uint64_t()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::reverse_cmp_uint64_t::~reverse_cmp_uint64_t()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// cmp_string_view
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::cmp_string_view::cmp_string_view()
|
|
|
|
:db::comparator{"string_view", &less, &equal}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::cmp_string_view::less(const string_view &a,
|
|
|
|
const string_view &b)
|
|
|
|
{
|
|
|
|
return a < b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::cmp_string_view::equal(const string_view &a,
|
|
|
|
const string_view &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// reverse_cmp_string_view
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::reverse_cmp_string_view::reverse_cmp_string_view()
|
|
|
|
:db::comparator{"reverse_string_view", &less, &equal}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::reverse_cmp_string_view::less(const string_view &a,
|
|
|
|
const string_view &b)
|
|
|
|
{
|
|
|
|
/// 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;
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::reverse_cmp_string_view::equal(const string_view &a,
|
|
|
|
const string_view &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
2017-09-14 20:30:06 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// merge.h
|
|
|
|
//
|
|
|
|
|
|
|
|
std::string
|
|
|
|
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;
|
|
|
|
assert(0);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// writebatch
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::append(rocksdb::WriteBatch &batch,
|
|
|
|
const cell::delta &delta)
|
|
|
|
{
|
|
|
|
auto &column(std::get<cell *>(delta)->c);
|
|
|
|
append(batch, column, column::delta
|
|
|
|
{
|
|
|
|
std::get<op>(delta),
|
2017-09-14 21:59:20 +02:00
|
|
|
std::get<cell *>(delta)->key(),
|
2017-09-08 11:14:17 +02:00
|
|
|
std::get<string_view>(delta)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::append(rocksdb::WriteBatch &batch,
|
|
|
|
column &column,
|
|
|
|
const column::delta &delta)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::commit(database &d,
|
|
|
|
rocksdb::WriteBatch &batch,
|
|
|
|
const sopts &sopts)
|
|
|
|
{
|
|
|
|
const auto opts(make_opts(sopts));
|
|
|
|
commit(d, batch, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::commit(database &d,
|
|
|
|
rocksdb::WriteBatch &batch,
|
|
|
|
const rocksdb::WriteOptions &opts)
|
|
|
|
{
|
2018-08-24 10:14:21 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
2018-03-14 01:32:13 +01:00
|
|
|
ircd::timer timer;
|
|
|
|
#endif
|
2017-09-08 11:14:17 +02:00
|
|
|
|
2018-08-27 05:24:38 +02:00
|
|
|
const std::lock_guard<decltype(write_mutex)> lock{write_mutex};
|
2018-08-24 12:40:37 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2017-09-08 11:14:17 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
d.d->Write(opts, &batch)
|
|
|
|
};
|
2018-03-14 01:32:13 +01:00
|
|
|
|
2018-08-24 10:14:21 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
2018-05-29 10:09:15 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "'%s' %lu COMMIT %s in %ld$us",
|
|
|
|
d.name,
|
|
|
|
sequence(d),
|
|
|
|
debug(batch),
|
|
|
|
timer.at<microseconds>().count()
|
|
|
|
};
|
2018-03-14 01:32:13 +01:00
|
|
|
#endif
|
2017-09-08 11:14:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
std::string
|
|
|
|
ircd::db::debug(const rocksdb::WriteBatch &batch)
|
|
|
|
{
|
2018-05-29 10:09:15 +02:00
|
|
|
return ircd::string(512, [&batch]
|
|
|
|
(const mutable_buffer &ret)
|
|
|
|
{
|
|
|
|
return snprintf(data(ret), size(ret)+1,
|
|
|
|
"%d deltas; size: %zuB :%s%s%s%s%s%s%s%s%s",
|
|
|
|
batch.Count(),
|
|
|
|
batch.GetDataSize(),
|
|
|
|
batch.HasPut()? " PUT" : "",
|
|
|
|
batch.HasDelete()? " DELETE" : "",
|
|
|
|
batch.HasSingleDelete()? " SINGLE_DELETE" : "",
|
|
|
|
batch.HasDeleteRange()? " DELETE_RANGE" : "",
|
|
|
|
batch.HasMerge()? " MERGE" : "",
|
|
|
|
batch.HasBeginPrepare()? " BEGIN_PREPARE" : "",
|
|
|
|
batch.HasEndPrepare()? " END_PREPARE" : "",
|
|
|
|
batch.HasCommit()? " COMMIT" : "",
|
|
|
|
batch.HasRollback()? " ROLLBACK" : "");
|
|
|
|
});
|
2017-09-19 04:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::has(const rocksdb::WriteBatch &wb,
|
|
|
|
const op &op)
|
2017-09-08 11:14:17 +02:00
|
|
|
{
|
2017-09-19 04:17:36 +02:00
|
|
|
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();
|
|
|
|
}
|
2017-09-08 11:14:17 +02:00
|
|
|
|
2017-09-19 04:17:36 +02:00
|
|
|
return false;
|
2017-09-08 11:14:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// seek
|
|
|
|
//
|
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
static rocksdb::Iterator &_seek_(rocksdb::Iterator &, const pos &);
|
2017-09-24 04:47:36 +02:00
|
|
|
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 &);
|
2018-11-16 05:54:50 +01:00
|
|
|
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);
|
2017-09-08 11:14:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
std::unique_ptr<rocksdb::Iterator>
|
|
|
|
ircd::db::seek(column &column,
|
|
|
|
const string_view &key,
|
|
|
|
const gopts &opts)
|
|
|
|
{
|
|
|
|
database &d(column);
|
|
|
|
database::column &c(column);
|
2017-08-23 22:37:47 +02:00
|
|
|
|
|
|
|
std::unique_ptr<rocksdb::Iterator> ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
seek(c, key, opts, ret);
|
|
|
|
return std::move(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class pos>
|
2017-08-30 23:05:15 +02:00
|
|
|
bool
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::seek(database::column &c,
|
|
|
|
const pos &p,
|
|
|
|
const gopts &gopts,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> &it)
|
|
|
|
{
|
2018-11-16 05:54:50 +01:00
|
|
|
const rocksdb::ReadOptions opts
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
|
|
|
make_opts(gopts)
|
|
|
|
};
|
|
|
|
|
2017-08-30 23:05:15 +02:00
|
|
|
return seek(c, p, opts, it);
|
2017-04-03 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 10:13:26 +02:00
|
|
|
template<class pos>
|
|
|
|
bool
|
|
|
|
ircd::db::seek(database::column &c,
|
2018-04-27 02:52:24 +02:00
|
|
|
const pos &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
|
|
|
std::unique_ptr<rocksdb::Iterator> &it)
|
2017-09-23 10:13:26 +02:00
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
|
2017-09-23 10:13:26 +02:00
|
|
|
if(!it)
|
|
|
|
{
|
|
|
|
database &d(*c.d);
|
|
|
|
rocksdb::ColumnFamilyHandle *const &cf(c);
|
|
|
|
it.reset(d.d->NewIterator(opts, cf));
|
|
|
|
}
|
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
return _seek(c, p, opts, *it);
|
2017-09-23 10:13:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 23:05:15 +02:00
|
|
|
bool
|
2017-09-23 10:13:26 +02:00
|
|
|
ircd::db::_seek(database::column &c,
|
|
|
|
const string_view &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
2018-08-19 03:29:00 +02:00
|
|
|
rocksdb::Iterator &it)
|
2017-04-03 06:02:32 +02:00
|
|
|
{
|
2018-08-19 03:29:00 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
2017-04-03 06:02:32 +02:00
|
|
|
database &d(*c.d);
|
2017-09-23 10:13:26 +02:00
|
|
|
const ircd::timer timer;
|
2018-08-19 03:29:00 +02:00
|
|
|
#endif
|
2017-08-19 00:13:15 +02:00
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
_seek_(it, p);
|
2017-08-19 00:13:15 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
|
|
|
{
|
2018-08-16 14:06:26 +02:00
|
|
|
log, "'%s' %lu:%lu SEEK %s in %ld$us '%s'",
|
2018-05-29 10:42:48 +02:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
2018-08-19 03:29:00 +02:00
|
|
|
it.status().ToString(),
|
2018-05-29 10:42:48 +02:00
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
name(c)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
return valid(it);
|
2017-09-23 10:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::_seek(database::column &c,
|
|
|
|
const pos &p,
|
|
|
|
const rocksdb::ReadOptions &opts,
|
2018-08-19 03:29:00 +02:00
|
|
|
rocksdb::Iterator &it)
|
2017-09-23 10:13:26 +02:00
|
|
|
{
|
2018-08-19 03:29:00 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
2017-09-23 10:13:26 +02:00
|
|
|
database &d(*c.d);
|
|
|
|
const ircd::timer timer;
|
|
|
|
const bool valid_it
|
|
|
|
{
|
2018-08-19 03:29:00 +02:00
|
|
|
valid(it)
|
2017-09-23 10:13:26 +02:00
|
|
|
};
|
2018-08-19 03:29:00 +02:00
|
|
|
#endif
|
2017-09-23 10:13:26 +02:00
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
_seek_(it, p);
|
2017-09-23 10:13:26 +02:00
|
|
|
|
2018-05-29 10:42:48 +02:00
|
|
|
#ifdef RB_DEBUG_DB_SEEK
|
|
|
|
log::debug
|
|
|
|
{
|
2018-08-16 14:06:26 +02:00
|
|
|
log, "'%s' %lu:%lu SEEK[%s] %s -> %s in %ld$us '%s'",
|
2018-05-29 10:42:48 +02:00
|
|
|
name(d),
|
|
|
|
sequence(d),
|
|
|
|
sequence(opts.snapshot),
|
|
|
|
reflect(p),
|
|
|
|
valid_it? "VALID" : "INVALID",
|
2018-08-19 03:29:00 +02:00
|
|
|
it.status().ToString(),
|
2018-05-29 10:42:48 +02:00
|
|
|
timer.at<microseconds>().count(),
|
|
|
|
name(c)
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 03:29:00 +02:00
|
|
|
return valid(it);
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2017-09-24 04:47:36 +02: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)
|
|
|
|
{
|
|
|
|
it.SeekForPrev(slice(sv));
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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)
|
|
|
|
{
|
|
|
|
it.Seek(slice(sv));
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Defaults to _seek_upper_ because it has better support from RocksDB.
|
|
|
|
rocksdb::Iterator &
|
|
|
|
ircd::db::_seek_(rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
|
|
|
{
|
|
|
|
return _seek_upper_(it, sv);
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:14:17 +02:00
|
|
|
rocksdb::Iterator &
|
2017-04-03 06:02:32 +02:00
|
|
|
ircd::db::_seek_(rocksdb::Iterator &it,
|
|
|
|
const pos &p)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
switch(p)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
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();
|
2016-09-26 06:07:22 +02:00
|
|
|
|
2017-04-03 06:02:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 11:14:17 +02:00
|
|
|
|
|
|
|
return it;
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:17:43 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// cache.h
|
|
|
|
//
|
|
|
|
|
2018-08-19 02:59:31 +02:00
|
|
|
void
|
|
|
|
ircd::db::clear(rocksdb::Cache *const &cache)
|
|
|
|
{
|
|
|
|
if(cache)
|
|
|
|
return clear(*cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::clear(rocksdb::Cache &cache)
|
|
|
|
{
|
|
|
|
cache.EraseUnRefEntries();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::remove(rocksdb::Cache *const &cache,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
2018-08-19 05:59:42 +02:00
|
|
|
return cache? remove(*cache, key) : false;
|
2018-08-19 02:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::remove(rocksdb::Cache &cache,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
cache.Erase(slice(key));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::insert(rocksdb::Cache *const &cache,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &value)
|
|
|
|
{
|
2018-08-19 05:59:42 +02:00
|
|
|
return cache? insert(*cache, key, value) : false;
|
2018-08-19 02:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::insert(rocksdb::Cache &cache,
|
|
|
|
const string_view &key,
|
|
|
|
const string_view &value)
|
|
|
|
{
|
|
|
|
unique_buffer<const_buffer> buf
|
|
|
|
{
|
|
|
|
const_buffer{value}
|
|
|
|
};
|
|
|
|
|
|
|
|
return insert(cache, key, std::move(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::insert(rocksdb::Cache *const &cache,
|
|
|
|
const string_view &key,
|
|
|
|
unique_buffer<const_buffer> value)
|
|
|
|
{
|
2018-08-19 05:59:42 +02:00
|
|
|
return cache? insert(*cache, key, std::move(value)) : false;
|
2018-08-19 02:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::insert(rocksdb::Cache &cache,
|
|
|
|
const string_view &key,
|
|
|
|
unique_buffer<const_buffer> value)
|
|
|
|
{
|
2018-08-21 09:47:05 +02:00
|
|
|
const ctx::uninterruptible ui;
|
|
|
|
const size_t value_size
|
|
|
|
{
|
|
|
|
size(value)
|
|
|
|
};
|
|
|
|
|
2018-08-19 02:59:31 +02:00
|
|
|
static const auto deleter{[]
|
|
|
|
(const rocksdb::Slice &key, void *const value)
|
|
|
|
{
|
2018-08-21 09:47:05 +02:00
|
|
|
delete[] reinterpret_cast<const char *>(value);
|
2018-08-19 02:59:31 +02:00
|
|
|
}};
|
|
|
|
|
|
|
|
// Note that because of the nullptr handle argument below, rocksdb
|
2018-08-21 09:47:05 +02:00
|
|
|
// will run the deleter if the insert throws; just make sure
|
|
|
|
// the argument execution doesn't throw after release()
|
2018-08-19 02:59:31 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
2018-08-21 09:47:05 +02:00
|
|
|
cache.Insert(slice(key),
|
|
|
|
const_cast<char *>(data(value.release())),
|
|
|
|
value_size,
|
|
|
|
deleter,
|
|
|
|
nullptr)
|
2018-08-19 02:59:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::for_each(const rocksdb::Cache *const &cache,
|
2018-05-15 01:53:28 +02:00
|
|
|
const cache_closure &closure)
|
|
|
|
{
|
|
|
|
if(cache)
|
|
|
|
for_each(*cache, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-19 02:59:31 +02:00
|
|
|
ircd::db::for_each(const rocksdb::Cache &cache,
|
2018-05-15 01:53:28 +02:00
|
|
|
const cache_closure &closure)
|
|
|
|
{
|
2018-08-21 09:19:53 +02:00
|
|
|
// 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.
|
2018-08-24 14:33:18 +02:00
|
|
|
thread_local ctx::mutex mutex;
|
2018-08-21 09:19:53 +02:00
|
|
|
const std::lock_guard<decltype(mutex)> lock{mutex};
|
|
|
|
|
2018-05-15 01:53:28 +02:00
|
|
|
thread_local rocksdb::Cache *_cache;
|
2018-08-19 02:59:31 +02:00
|
|
|
_cache = const_cast<rocksdb::Cache *>(&cache);
|
2018-05-15 01:53:28 +02:00
|
|
|
|
|
|
|
thread_local const cache_closure *_closure;
|
|
|
|
_closure = &closure;
|
|
|
|
|
2018-08-19 02:59:31 +02:00
|
|
|
_cache->ApplyToAllCacheEntries([]
|
2018-08-21 09:20:30 +02:00
|
|
|
(void *const value_buffer, const size_t buffer_size)
|
2018-08-21 09:19:53 +02:00
|
|
|
noexcept
|
2018-05-15 01:53:28 +02:00
|
|
|
{
|
|
|
|
assert(_cache);
|
|
|
|
assert(_closure);
|
2018-08-21 09:42:13 +02:00
|
|
|
const const_buffer buf
|
2018-05-15 01:53:28 +02:00
|
|
|
{
|
2018-08-21 09:42:13 +02:00
|
|
|
reinterpret_cast<const char *>(value_buffer), buffer_size
|
2018-05-15 01:53:28 +02:00
|
|
|
};
|
|
|
|
|
2018-08-21 09:42:13 +02:00
|
|
|
(*_closure)(buf);
|
2018-05-15 01:53:28 +02:00
|
|
|
},
|
2018-08-21 09:19:53 +02:00
|
|
|
true);
|
2018-05-15 01:53:28 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:36:48 +02:00
|
|
|
bool
|
2018-08-19 02:59:31 +02:00
|
|
|
ircd::db::exists(const rocksdb::Cache *const &cache,
|
2018-05-15 01:36:48 +02:00
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
return cache? exists(*cache, key) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-08-19 02:59:31 +02:00
|
|
|
ircd::db::exists(const rocksdb::Cache &cache_,
|
2018-05-15 01:36:48 +02:00
|
|
|
const string_view &key)
|
|
|
|
{
|
2018-08-19 02:59:31 +02:00
|
|
|
auto &cache(const_cast<rocksdb::Cache &>(cache_));
|
2018-05-15 01:36:48 +02:00
|
|
|
const custom_ptr<rocksdb::Cache::Handle> handle
|
|
|
|
{
|
|
|
|
cache.Lookup(slice(key)), [&cache](auto *const &handle)
|
|
|
|
{
|
|
|
|
cache.Release(handle);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return bool(handle);
|
|
|
|
}
|
|
|
|
|
2018-09-26 11:34:47 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::pinned(const rocksdb::Cache *const &cache)
|
|
|
|
{
|
|
|
|
return cache? pinned(*cache) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::pinned(const rocksdb::Cache &cache)
|
|
|
|
{
|
|
|
|
return cache.GetPinnedUsage();
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:17:43 +02:00
|
|
|
size_t
|
|
|
|
ircd::db::usage(const rocksdb::Cache *const &cache)
|
|
|
|
{
|
|
|
|
return cache? usage(*cache) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::usage(const rocksdb::Cache &cache)
|
|
|
|
{
|
|
|
|
return cache.GetUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::capacity(rocksdb::Cache *const &cache,
|
|
|
|
const size_t &cap)
|
|
|
|
{
|
|
|
|
if(!cache)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
capacity(*cache, cap);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::db::capacity(rocksdb::Cache &cache,
|
|
|
|
const size_t &cap)
|
|
|
|
{
|
|
|
|
cache.SetCapacity(cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::capacity(const rocksdb::Cache *const &cache)
|
|
|
|
{
|
|
|
|
return cache? capacity(*cache): 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::db::capacity(const rocksdb::Cache &cache)
|
|
|
|
{
|
|
|
|
return cache.GetCapacity();
|
|
|
|
}
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
uint64_t
|
|
|
|
ircd::db::ticker(const rocksdb::Cache *const &cache,
|
|
|
|
const uint32_t &ticker_id)
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
2018-09-27 03:00:18 +02:00
|
|
|
return cache? ticker(*cache, ticker_id) : 0UL;
|
2018-09-05 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 03:00:18 +02:00
|
|
|
const uint64_t &
|
|
|
|
ircd::db::ticker(const rocksdb::Cache &cache,
|
|
|
|
const uint32_t &ticker_id)
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
2018-09-27 03:00:18 +02:00
|
|
|
const auto &c
|
2018-09-05 11:56:50 +02:00
|
|
|
{
|
|
|
|
dynamic_cast<const database::cache &>(cache)
|
|
|
|
};
|
|
|
|
|
2018-10-21 08:30:27 +02:00
|
|
|
static const uint64_t &zero
|
|
|
|
{
|
|
|
|
0ULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return c.stats?
|
|
|
|
c.stats->ticker.at(ticker_id):
|
|
|
|
zero;
|
2018-09-05 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
2017-03-24 02:36:49 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Misc
|
|
|
|
//
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-09-19 04:17:36 +02:00
|
|
|
return column_names(path, database::options{options});
|
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
|
|
|
|
{
|
2018-08-20 04:30:17 +02:00
|
|
|
const ctx::uninterruptible ui;
|
2017-03-24 02:36:49 +01:00
|
|
|
std::vector<std::string> ret;
|
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;
|
|
|
|
}
|
|
|
|
catch(const io_error &e)
|
|
|
|
{
|
|
|
|
return // No database found at path. Assume fresh.
|
|
|
|
{
|
|
|
|
{ rocksdb::kDefaultColumnFamilyName }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::options(const database &d)
|
|
|
|
:options{d.d->GetDBOptions()}
|
2016-09-25 03:18:54 +02:00
|
|
|
{
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::options(const database::column &c)
|
2017-04-03 06:02:32 +02:00
|
|
|
:options
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
rocksdb::ColumnFamilyOptions
|
|
|
|
{
|
|
|
|
c.d->d->GetOptions(c.handle.get())
|
|
|
|
}
|
|
|
|
}{}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::options(const rocksdb::DBOptions &opts)
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetStringFromDBOptions(this, opts)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::options(const rocksdb::ColumnFamilyOptions &opts)
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetStringFromColumnFamilyOptions(this, opts)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::operator rocksdb::PlainTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::PlainTableOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetPlainTableOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::operator rocksdb::BlockBasedTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::BlockBasedTableOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetBlockBasedTableOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::operator rocksdb::ColumnFamilyOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetColumnFamilyOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::operator rocksdb::DBOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::DBOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetDBOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::operator rocksdb::Options()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::Options ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetOptionsFromString(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::map::map(const options &o)
|
|
|
|
{
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::StringToMap(o, this)
|
|
|
|
};
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::map::operator rocksdb::PlainTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::PlainTableOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetPlainTableOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::map::operator rocksdb::BlockBasedTableOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::BlockBasedTableOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetBlockBasedTableOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::map::operator rocksdb::ColumnFamilyOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::ColumnFamilyOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetColumnFamilyOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::database::options::map::operator rocksdb::DBOptions()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
rocksdb::DBOptions ret;
|
2017-04-03 06:02:32 +02:00
|
|
|
throw_on_error
|
|
|
|
{
|
|
|
|
rocksdb::GetDBOptionsFromMap(ret, *this, &ret)
|
|
|
|
};
|
|
|
|
|
2016-09-25 03:18:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-16 18:41:10 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Misc
|
|
|
|
//
|
|
|
|
|
2018-11-03 02:08:40 +01:00
|
|
|
rocksdb::CompressionType
|
|
|
|
ircd::db::find_supported_compression(const std::string &list)
|
|
|
|
{
|
|
|
|
rocksdb::CompressionType ret
|
|
|
|
{
|
|
|
|
rocksdb::kNoCompression
|
|
|
|
};
|
|
|
|
|
|
|
|
tokens(list, ';', [&ret]
|
|
|
|
(const string_view &name)
|
|
|
|
{
|
|
|
|
for(size_t i(0); i < db::compressions.size(); ++i)
|
|
|
|
if(!db::compressions.at(i).empty())
|
|
|
|
if(name == db::compressions.at(i))
|
|
|
|
{
|
|
|
|
ret = rocksdb::CompressionType(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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)
|
|
|
|
*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)
|
|
|
|
*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
|
|
|
|
{
|
|
|
|
database::options(optstr)
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2017-09-23 10:13:26 +02:00
|
|
|
assert(ret.fill_cache);
|
2018-08-16 14:06:26 +02:00
|
|
|
ret.read_tier = BLOCKING;
|
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;
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
ret += opts;
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-31 07:12:58 +02:00
|
|
|
|
2018-05-24 03:43:47 +02:00
|
|
|
ircd::conf::item<bool>
|
|
|
|
read_checksum
|
|
|
|
{
|
|
|
|
{ "name", "ircd.db.read.checksum" },
|
|
|
|
{ "default", false }
|
|
|
|
};
|
|
|
|
|
2018-11-16 05:54:50 +01:00
|
|
|
/// Update a RocksDB options structure with our options structure. We use
|
|
|
|
/// operator+= for fun here; we can avoid reconstructing and returning a new
|
|
|
|
/// options structure in some cases by breaking out this function from
|
|
|
|
/// make_opts().
|
2017-09-22 05:08:11 +02:00
|
|
|
rocksdb::ReadOptions &
|
|
|
|
ircd::db::operator+=(rocksdb::ReadOptions &ret,
|
|
|
|
const gopts &opts)
|
|
|
|
{
|
|
|
|
ret.pin_data = test(opts, get::PIN);
|
|
|
|
ret.fill_cache |= test(opts, get::CACHE);
|
|
|
|
ret.fill_cache &= !test(opts, get::NO_CACHE);
|
|
|
|
ret.tailing = test(opts, get::NO_SNAPSHOT);
|
|
|
|
ret.prefix_same_as_start = test(opts, get::PREFIX);
|
2017-09-24 04:47:36 +02:00
|
|
|
ret.total_order_seek = test(opts, get::ORDERED);
|
2018-05-24 03:43:47 +02:00
|
|
|
ret.verify_checksums = bool(read_checksum);
|
|
|
|
ret.verify_checksums |= test(opts, get::CHECKSUM);
|
|
|
|
ret.verify_checksums &= !test(opts, get::NO_CHECKSUM);
|
2018-11-16 05:54:50 +01:00
|
|
|
|
|
|
|
ret.readahead_size = opts.readahead;
|
|
|
|
ret.iter_start_seqnum = opts.seqnum;
|
|
|
|
|
|
|
|
if(opts.snapshot && !test(opts, get::NO_SNAPSHOT))
|
|
|
|
ret.snapshot = opts.snapshot;
|
|
|
|
|
2016-09-25 03:18:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::WriteOptions
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::make_opts(const sopts &opts)
|
2016-09-25 03:18:54 +02:00
|
|
|
{
|
|
|
|
rocksdb::WriteOptions ret;
|
2017-11-30 20:04:25 +01:00
|
|
|
//ret.no_slowdown = true; // read_tier = NON_BLOCKING for writes
|
2017-09-22 05:08:11 +02:00
|
|
|
ret += opts;
|
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 03:18:54 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
rocksdb::WriteOptions &
|
|
|
|
ircd::db::operator+=(rocksdb::WriteOptions &ret,
|
|
|
|
const sopts &opts)
|
|
|
|
{
|
|
|
|
ret.sync = test(opts, set::FSYNC);
|
|
|
|
ret.disableWAL = test(opts, set::NO_JOURNAL);
|
|
|
|
ret.ignore_missing_column_families = test(opts, set::MISSING_COLUMNS);
|
2016-09-25 03:18:54 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
void
|
2017-09-16 20:48:09 +02:00
|
|
|
ircd::db::valid_eq_or_throw(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2018-04-18 05:07:21 +02:00
|
|
|
assert(!empty(sv));
|
2017-09-16 20:48:09 +02:00
|
|
|
if(!valid_eq(it, sv))
|
|
|
|
{
|
|
|
|
throw_on_error(it.status());
|
2018-04-18 05:07:21 +02:00
|
|
|
throw not_found{};
|
2017-09-16 20:48:09 +02:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-26 06:07:22 +02:00
|
|
|
void
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::valid_or_throw(const rocksdb::Iterator &it)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
|
|
|
if(!valid(it))
|
|
|
|
{
|
|
|
|
throw_on_error(it.status());
|
2018-04-18 05:07:21 +02:00
|
|
|
throw not_found{};
|
2017-03-20 12:25:01 +01:00
|
|
|
//assert(0); // status == ok + !Valid() == ???
|
2016-09-26 06:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-16 20:48:09 +02:00
|
|
|
bool
|
|
|
|
ircd::db::valid_lte(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
|
|
|
{
|
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) <= 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid_gt(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
|
|
|
{
|
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) > 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid_eq(const rocksdb::Iterator &it,
|
|
|
|
const string_view &sv)
|
|
|
|
{
|
|
|
|
return valid(it, [&sv](const auto &it)
|
|
|
|
{
|
|
|
|
return it.key().compare(slice(sv)) == 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid(const rocksdb::Iterator &it,
|
|
|
|
const valid_proffer &proffer)
|
|
|
|
{
|
|
|
|
return valid(it)? proffer(it) : false;
|
|
|
|
}
|
|
|
|
|
2016-09-26 06:07:22 +02:00
|
|
|
bool
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::operator!(const rocksdb::Iterator &it)
|
|
|
|
{
|
2017-09-08 11:14:17 +02:00
|
|
|
return !valid(it);
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::db::valid(const rocksdb::Iterator &it)
|
2016-09-26 06:07:22 +02:00
|
|
|
{
|
2017-09-08 11:14:17 +02:00
|
|
|
switch(it.status().code())
|
|
|
|
{
|
|
|
|
using rocksdb::Status;
|
|
|
|
|
|
|
|
case Status::kOk: break;
|
|
|
|
case Status::kNotFound: break;
|
|
|
|
case Status::kIncomplete: break;
|
|
|
|
default:
|
|
|
|
throw_on_error(it.status());
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
2016-09-26 06:07:22 +02:00
|
|
|
return it.Valid();
|
2016-09-25 03:18:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 13:19:32 +02:00
|
|
|
//
|
|
|
|
// error_to_status
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::db::error_to_status::error_to_status(const fs::error &e)
|
|
|
|
:error_to_status{e.code}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::error_to_status::error_to_status(const std::exception &e)
|
|
|
|
:rocksdb::Status
|
|
|
|
{
|
|
|
|
Status::Aborted(slice(string_view(e.what())))
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::db::error_to_status::error_to_status(const std::error_code &e)
|
|
|
|
:rocksdb::Status{[&e]
|
|
|
|
{
|
|
|
|
using std::errc;
|
|
|
|
|
|
|
|
switch(e.value())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return Status::OK();
|
|
|
|
|
|
|
|
case int(errc::no_such_file_or_directory):
|
|
|
|
return Status::NotFound();
|
|
|
|
|
|
|
|
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:
|
|
|
|
return Status::Aborted(slice(string_view(e.message())));
|
|
|
|
}
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:02:12 +02:00
|
|
|
//
|
|
|
|
// throw_on_error
|
|
|
|
//
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
ircd::db::throw_on_error::throw_on_error(const rocksdb::Status &s)
|
2016-09-24 06:01:57 +02:00
|
|
|
{
|
|
|
|
using rocksdb::Status;
|
|
|
|
|
|
|
|
switch(s.code())
|
|
|
|
{
|
|
|
|
case Status::kOk: return;
|
2017-03-31 00:57:08 +02:00
|
|
|
case Status::kNotFound: throw not_found("%s", s.ToString());
|
|
|
|
case Status::kCorruption: throw corruption("%s", s.ToString());
|
|
|
|
case Status::kNotSupported: throw not_supported("%s", s.ToString());
|
|
|
|
case Status::kInvalidArgument: throw invalid_argument("%s", s.ToString());
|
|
|
|
case Status::kIOError: throw io_error("%s", s.ToString());
|
|
|
|
case Status::kMergeInProgress: throw merge_in_progress("%s", s.ToString());
|
|
|
|
case Status::kIncomplete: throw incomplete("%s", s.ToString());
|
|
|
|
case Status::kShutdownInProgress: throw shutdown_in_progress("%s", s.ToString());
|
|
|
|
case Status::kTimedOut: throw timed_out("%s", s.ToString());
|
|
|
|
case Status::kAborted: throw aborted("%s", s.ToString());
|
|
|
|
case Status::kBusy: throw busy("%s", s.ToString());
|
|
|
|
case Status::kExpired: throw expired("%s", s.ToString());
|
|
|
|
case Status::kTryAgain: throw try_again("%s", s.ToString());
|
2018-08-23 13:02:12 +02:00
|
|
|
default: throw error
|
|
|
|
{
|
|
|
|
"code[%d] %s", s.code(), s.ToString()
|
|
|
|
};
|
2016-09-24 06:01:57 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-25 06:12:43 +02:00
|
|
|
|
2018-08-23 13:02:12 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
std::vector<std::string>
|
|
|
|
ircd::db::available()
|
|
|
|
{
|
2018-05-25 05:01:52 +02:00
|
|
|
const auto prefix
|
|
|
|
{
|
|
|
|
fs::get(fs::DB)
|
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto cpdir : checkpoints) try
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
const auto prefix
|
|
|
|
{
|
|
|
|
fs::get(fs::DB)
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
return fs::make_path(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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-18 05:28:34 +01:00
|
|
|
const char *
|
|
|
|
ircd::db::data(const rocksdb::Slice &slice)
|
|
|
|
{
|
|
|
|
return slice.data();
|
|
|
|
}
|
|
|
|
|
2018-01-18 05:15:13 +01:00
|
|
|
size_t
|
|
|
|
ircd::db::size(const rocksdb::Slice &slice)
|
|
|
|
{
|
|
|
|
return slice.size();
|
|
|
|
}
|
|
|
|
|
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() };
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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 "??????";
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
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;
|
2018-08-16 11:04:16 +02:00
|
|
|
case rocksdb::Env::IOPriority::IO_TOTAL: assert(0); 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 "?????";
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-23 22:37:47 +02:00
|
|
|
bool
|
|
|
|
ircd::db::value_required(const op &op)
|
|
|
|
{
|
|
|
|
switch(op)
|
|
|
|
{
|
|
|
|
case op::SET:
|
|
|
|
case op::MERGE:
|
|
|
|
case op::DELETE_RANGE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case op::GET:
|
|
|
|
case op::DELETE:
|
|
|
|
case op::SINGLE_DELETE:
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-30 23:21:18 +02:00
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return false;
|
2017-08-23 22:37:47 +02:00
|
|
|
}
|