Skip to content

Commit

Permalink
(WIP) decoupling segment storage
Browse files Browse the repository at this point in the history
  • Loading branch information
KIwabuchi committed Nov 30, 2023
1 parent c63ec18 commit 85d6099
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 272 deletions.
120 changes: 61 additions & 59 deletions include/metall/basic_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class basic_manager {
/// \brief Chunk number type (= chunk_no_type)
using chunk_number_type = chunk_no_type;

/// \brief Path type
using path_type = typename manager_kernel_type::path_type;

private:
// -------------------- //
// Private types and static values
Expand All @@ -121,7 +124,7 @@ class basic_manager {

/// \brief Opens an existing data store.
/// \param base_path Path to a data store.
basic_manager(open_only_t, const char *base_path) noexcept {
basic_manager(open_only_t, const path_type &base_path) noexcept {
try {
m_kernel = std::make_unique<manager_kernel_type>();
m_kernel->open(base_path);
Expand All @@ -135,7 +138,7 @@ class basic_manager {
/// \brief Opens an existing data store with the read only mode.
/// Write accesses will cause segmentation fault.
/// \param base_path Path to a data store.
basic_manager(open_read_only_t, const char *base_path) noexcept {
basic_manager(open_read_only_t, const path_type &base_path) noexcept {
try {
m_kernel = std::make_unique<manager_kernel_type>();
m_kernel->open_read_only(base_path);
Expand All @@ -148,7 +151,7 @@ class basic_manager {

/// \brief Creates a new data store (an existing data store will be
/// overwritten). \param base_path Path to create a data store.
basic_manager(create_only_t, const char *base_path) noexcept {
basic_manager(create_only_t, const path_type &base_path) noexcept {
try {
m_kernel = std::make_unique<manager_kernel_type>();
m_kernel->create(base_path);
Expand All @@ -162,7 +165,7 @@ class basic_manager {
/// \brief Creates a new data store (an existing data store will be
/// overwritten). \param base_path Path to create a data store. \param
/// capacity Maximum total allocation size.
basic_manager(create_only_t, const char *base_path,
basic_manager(create_only_t, const path_type &base_path,
const size_type capacity) noexcept {
try {
m_kernel = std::make_unique<manager_kernel_type>();
Expand Down Expand Up @@ -940,19 +943,18 @@ class basic_manager {
/// \brief Takes a snapshot of the current data. The snapshot has a new UUID.
/// \copydoc doc_single_thread
///
/// \param destination_dir_path Path to store a snapshot.
/// \param destination_path Path to store a snapshot.
/// \param clone Use the file clone mechanism (reflink) instead of normal copy
/// if it is available. \param num_max_copy_threads The maximum number of copy
/// threads to use. If <= 0 is given, the value is automatically determined.
/// \return Returns true on success; other false.
bool snapshot(const char_type *destination_dir_path, const bool clone = true,
bool snapshot(const path_type &destination_path, const bool clone = true,
const int num_max_copy_threads = 0) noexcept {
if (!check_sanity()) {
return false;
}
try {
return m_kernel->snapshot(destination_dir_path, clone,
num_max_copy_threads);
return m_kernel->snapshot(destination_path, clone, num_max_copy_threads);
} catch (...) {
m_kernel.reset(nullptr);
logger::out(logger::level::error, __FILE__, __LINE__,
Expand All @@ -967,19 +969,18 @@ class basic_manager {
/// \copydoc doc_thread_safe
/// \details Copying to the same path simultaneously is prohibited.
///
/// \param source_dir_path Source data store path.\param
/// destination_dir_path Destination data store path. \param clone Use the
/// file clone mechanism (reflink) instead of normal copy if it is available.
/// \param num_max_copy_threads The maximum number of copy threads to use.
/// If <= 0 is given, the value is automatically determined.
/// \param source_path Source data store path.
/// \param destination_path Destination data store path.
/// \param clone Use the file clone mechanism (reflink) instead of normal copy
/// if it is available. \param num_max_copy_threads The maximum number of copy
/// threads to use. If <= 0 is given, the value is automatically determined.
/// \return If succeeded, returns true; other false.
static bool copy(const char_type *source_dir_path,
const char_type *destination_dir_path,
const bool clone = true,
static bool copy(const path_type &source_path,
const path_type &destination_path, const bool clone = true,
const int num_max_copy_threads = 0) noexcept {
try {
return manager_kernel_type::copy(source_dir_path, destination_dir_path,
clone, num_max_copy_threads);
return manager_kernel_type::copy(source_path, destination_path, clone,
num_max_copy_threads);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -993,20 +994,21 @@ class basic_manager {
/// \copydoc doc_thread_safe
/// \details Copying to the same path simultaneously is prohibited.
///
/// \param source_dir_path Source data store path. \param
/// destination_dir_path Destination data store path. \param clone Use the
/// file clone mechanism (reflink) instead of normal copy if it is available.
/// \param num_max_copy_threads The maximum number of copy threads to use.
/// If <= 0 is given, the value is automatically determined.
/// \return Returns an object of std::future.
/// If succeeded, its get() returns true; other false.
static auto copy_async(const char_type *source_dir_path,
const char_type *destination_dir_path,
/// \param source_path Source data store path.
/// \param destination_path Destination data store path.
/// \param clone Use the file clone mechanism (reflink) instead of normal copy
/// if it is available.
/// \param num_max_copy_threads The maximum number of copy threads to use. If
/// <= 0 is given, the value is automatically determined.
/// \return Returns an object of std::future. If succeeded, its get() returns
/// true; other false.
static auto copy_async(const path_type source_path,
const path_type destination_path,
const bool clone = true,
const int num_max_copy_threads = 0) noexcept {
try {
return manager_kernel_type::copy_async(
source_dir_path, destination_dir_path, clone, num_max_copy_threads);
return manager_kernel_type::copy_async(source_path, destination_path,
clone, num_max_copy_threads);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1018,11 +1020,11 @@ class basic_manager {
/// \copydoc doc_thread_safe
/// \details Must not remove the same data store simultaneously.
///
/// \param dir_path Path to a data store to remove. \return If
/// \param path Path to a data store to remove. \return If
/// succeeded, returns true; other false.
static bool remove(const char_type *dir_path) noexcept {
static bool remove(const path_type &path) noexcept {
try {
return manager_kernel_type::remove(dir_path);
return manager_kernel_type::remove(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1034,12 +1036,12 @@ class basic_manager {
/// \copydoc doc_thread_safe
/// \details Must not remove the same data store simultaneously.
///
/// \param dir_path Path to a data store to remove.
/// \param path Path to the data store to remove.
/// \return Returns an object of std::future.
/// If succeeded, its get() returns true; other false
static std::future<bool> remove_async(const char_type *dir_path) noexcept {
static std::future<bool> remove_async(const path_type &path) noexcept {
try {
return std::async(std::launch::async, remove, dir_path);
return std::async(std::launch::async, remove, path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1056,12 +1058,12 @@ class basic_manager {
/// read-only mode is undefined.
/// If the data store is not consistent, it is recommended to remove
/// the data store and create a new one.
/// \param dir_path Path to a data store.
/// \param path Path to a data store.
/// \return Returns true if it exists and is consistent; otherwise, returns
/// false.
static bool consistent(const char_type *dir_path) noexcept {
static bool consistent(const path_type &path) noexcept {
try {
return manager_kernel_type::consistent(dir_path);
return manager_kernel_type::consistent(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand Down Expand Up @@ -1089,11 +1091,11 @@ class basic_manager {
/// \brief Returns a UUID of the data store.
/// \copydoc doc_thread_safe
///
/// \param dir_path Path to a data store.
/// \param path Path to a data store.
/// \return UUID in the std::string format; returns an empty string on error.
static std::string get_uuid(const char_type *dir_path) noexcept {
static std::string get_uuid(const path_type &path) noexcept {
try {
return manager_kernel_type::get_uuid(dir_path);
return manager_kernel_type::get_uuid(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand Down Expand Up @@ -1121,11 +1123,11 @@ class basic_manager {
/// \brief Gets the version of the Metall that created the backing data store.
/// \copydoc doc_thread_safe
///
/// \param dir_path Path to a data store.
/// \param path Path to a data store.
/// \return Returns a version number; returns 0 on error.
static version_type get_version(const char_type *dir_path) noexcept {
static version_type get_version(const path_type &path) noexcept {
try {
return manager_kernel_type::get_version(dir_path);
return manager_kernel_type::get_version(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand Down Expand Up @@ -1163,13 +1165,13 @@ class basic_manager {
/// store).
/// \copydoc doc_const_datastore_thread_safe
///
/// \param dir_path Path to a data store. \param description An std::string
/// \param path Path to a data store. \param description An std::string
/// object that holds a description. \return Returns true on success;
/// otherwise, false.
static bool set_description(const char *dir_path,
static bool set_description(const path_type &path,
const std::string &description) noexcept {
try {
return manager_kernel_type::set_description(dir_path, description);
return manager_kernel_type::set_description(path, description);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand Down Expand Up @@ -1204,14 +1206,14 @@ class basic_manager {
/// object.
/// \copydoc doc_const_datastore_thread_safe
///
/// \param dir_path Path to a data store. \param description A pointer
/// \param path Path to a data store. \param description A pointer
/// to an std::string object to store a description if it exists. \return
/// Returns true on success; returns false on error. Trying to get a
/// non-existent description is not considered as an error.
static bool get_description(const char *dir_path,
static bool get_description(const path_type &path,
std::string *description) noexcept {
try {
return manager_kernel_type::get_description(dir_path, description);
return manager_kernel_type::get_description(path, description);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1224,12 +1226,12 @@ class basic_manager {
/// objects.
/// \copydoc doc_object_attrb_obj_const_thread_safe
///
/// \param dir_path Path to a data store. \return Returns an instance
/// \param path Path to a data store. \return Returns an instance
/// of named_object_attribute_accessor_type.
static named_object_attribute_accessor_type access_named_object_attribute(
const char *dir_path) noexcept {
const path_type &path) noexcept {
try {
return manager_kernel_type::access_named_object_attribute(dir_path);
return manager_kernel_type::access_named_object_attribute(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1241,12 +1243,12 @@ class basic_manager {
/// object.
/// \copydoc doc_object_attrb_obj_const_thread_safe
///
/// \param dir_path Path to a data store. \return Returns an instance
/// \param path Path to a data store. \return Returns an instance
/// of unique_object_attribute_accessor_type.
static unique_object_attribute_accessor_type access_unique_object_attribute(
const char *dir_path) noexcept {
const path_type &path) noexcept {
try {
return manager_kernel_type::access_unique_object_attribute(dir_path);
return manager_kernel_type::access_unique_object_attribute(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand All @@ -1258,12 +1260,12 @@ class basic_manager {
/// anonymous object.
/// \copydoc doc_object_attrb_obj_const_thread_safe
///
/// \param dir_path Path to a data store. \return Returns an
/// \param path Path to a data store. \return Returns an
/// instance of anonymous_object_attribute_accessor_type.
static anonymous_object_attribute_accessor_type
access_anonymous_object_attribute(const char *dir_path) noexcept {
access_anonymous_object_attribute(const path_type &path) noexcept {
try {
return manager_kernel_type::access_anonymous_object_attribute(dir_path);
return manager_kernel_type::access_anonymous_object_attribute(path);
} catch (...) {
logger::out(logger::level::error, __FILE__, __LINE__,
"An exception has been thrown");
Expand Down
Loading

0 comments on commit 85d6099

Please sign in to comment.