From 85d6099b73d8edbd35f2ab47ab31730b9c38dcad Mon Sep 17 00:00:00 2001 From: iwabuchi Date: Thu, 30 Nov 2023 11:31:14 -0800 Subject: [PATCH] (WIP) decoupling segment storage --- include/metall/basic_manager.hpp | 120 ++++---- include/metall/kernel/manager_kernel.hpp | 141 +++++---- include/metall/kernel/manager_kernel_impl.ipp | 286 +++++++++--------- include/metall/kernel/mmap_data_storage.hpp | 4 + 4 files changed, 279 insertions(+), 272 deletions(-) diff --git a/include/metall/basic_manager.hpp b/include/metall/basic_manager.hpp index 7ef91570..8404cec6 100644 --- a/include/metall/basic_manager.hpp +++ b/include/metall/basic_manager.hpp @@ -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 @@ -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(); m_kernel->open(base_path); @@ -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(); m_kernel->open_read_only(base_path); @@ -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(); m_kernel->create(base_path); @@ -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(); @@ -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__, @@ -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"); @@ -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"); @@ -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"); @@ -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 remove_async(const char_type *dir_path) noexcept { + static std::future 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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); diff --git a/include/metall/kernel/manager_kernel.hpp b/include/metall/kernel/manager_kernel.hpp index ab3f9b97..a2977c6b 100644 --- a/include/metall/kernel/manager_kernel.hpp +++ b/include/metall/kernel/manager_kernel.hpp @@ -110,7 +110,6 @@ class manager_kernel { mdtl::round_up(sizeof(segment_header_type), k_chunk_size); using data_storage_type = data_storage; - using path_type = typename data_storage_type::path_type; // For actual memory allocation layer static constexpr const char *k_segment_memory_allocator_prefix = @@ -165,6 +164,7 @@ class manager_kernel { using anonymous_object_attr_accessor_type = anonymous_object_attr_accessor< attributed_object_directory_type::offset_type, attributed_object_directory_type::size_type>; + using path_type = typename data_storage_type::path_type; // -------------------- // // Constructor & assign operator @@ -184,25 +184,25 @@ class manager_kernel { // -------------------- // /// \brief Creates a new datastore /// Expect to be called by a single thread - /// \param base_dir_path + /// \param base_path /// \param vm_reserve_size /// \return Returns true if success; otherwise, returns false - bool create(const path_type &base_dir_path, + bool create(const path_type &base_path, size_type vm_reserve_size = k_default_vm_reserve_size); /// \brief Opens an existing datastore /// Expect to be called by a single thread - /// \param base_dir_path + /// \param base_path /// \param vm_reserve_size /// \return Returns true if success; otherwise, returns false - bool open(const path_type &base_dir_path, + bool open(const path_type &base_path, size_type vm_reserve_size = k_default_vm_reserve_size); /// \brief Opens an existing datastore with read only /// Expect to be called by a single thread - /// \param base_dir_path + /// \param base_path /// \return Returns true if success; otherwise, returns false - bool open_read_only(const path_type &base_dir_path); + bool open_read_only(const path_type &base_path); /// \brief Expect to be called by a single thread void close(); @@ -279,7 +279,7 @@ class manager_kernel { /// construct/find_or_construct functions (1 if is a single element, >=1 if /// it's an array), is T. \tparam T \param ptr \return template - bool is_instance_type(const void *const ptr) const; + bool is_instance_type(const void *ptr) const; /// \brief Gets the description of an object created with /// construct/find_or_construct. \tparam T The type of the object. \param ptr @@ -359,48 +359,47 @@ class manager_kernel { size_type get_segment_size() const; /// \brief Takes a snapshot. The snapshot has a different UUID. - /// \param destination_dir_path Destination path + /// \param destination_base_path Destination path /// \param clone Use clone (reflink) to copy data. /// \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 - bool snapshot(const path_type &destination_dir_path, const bool clone, - const int num_max_copy_threads); + bool snapshot(const path_type &destination_base_path, bool clone, + int num_max_copy_threads); /// \brief Copies a data store synchronously, keeping the same UUID. - /// \param source_dir_path Source path. - /// \param destination_dir_path Destination path. + /// \param source_base_path Source path. + /// \param destination_base_path Destination path. /// \param clone Use clone (reflink) to copy data. /// \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 path_type &source_dir_path, - const path_type &destination_dir_path, const bool clone, - const int num_max_copy_threads); + static bool copy(const path_type &source_base_path, + const path_type &destination_base_path, bool clone, + int num_max_copy_threads); /// \brief Copies a data store asynchronously, keeping the same UUID. - /// \param source_dir_path Source path. - /// \param destination_dir_path Destination path. + /// \param source_base_path Source path. + /// \param destination_base_path Destination path. /// \param clone Use clone (reflink) to copy data. /// \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 std::future copy_async(const path_type &source_dir_path, - const path_type &destination_dir_path, - const bool clone, - const int num_max_copy_threads); + static std::future copy_async(const path_type &source_base_path, + const path_type &destination_base_path, + bool clone, int num_max_copy_threads); /// \brief Remove a data store synchronously - /// \param base_dir_path + /// \param base_path /// \return If succeeded, returns True; other false - static bool remove(const path_type &base_dir_path); + static bool remove(const path_type &base_path); /// \brief Remove a data store asynchronously - /// \param base_dir_path + /// \param base_path /// \return Returns an object of std::future /// If succeeded, its get() returns True; other false - static std::future remove_async(const path_type &base_dir_path); + static std::future remove_async(const path_type &base_path); /// \brief Check if the backing data store is consistent, /// i.e. it was closed properly. @@ -413,18 +412,18 @@ class manager_kernel { std::string get_uuid() const; /// \brief Returns the UUID of the backing data store. - /// \param dir_path Path to a data store. + /// \param base_path Path to a data store. /// \return Returns UUID in std::string; returns an empty string on error. - static std::string get_uuid(const path_type &dir_path); + static std::string get_uuid(const path_type &base_path); /// \brief Gets the version number of the backing data store. /// \return Returns a version number; returns 0 on error. version_type get_version() const; /// \brief Gets the version number of the backing data store. - /// \param dir_path Path to a data store. + /// \param base_path Path to a data store. /// \return Returns a version number; returns 0 on error. - static version_type get_version(const path_type &dir_path); + static version_type get_version(const path_type &base_path); /// \brief Gets a description from a file. /// \param description A pointer to a string buffer. @@ -432,10 +431,10 @@ class manager_kernel { bool get_description(std::string *description) const; /// \brief Gets a description from a file. - /// \param base_dir_path Path to a data store. + /// \param base_path Path to a data store. /// \param description A pointer to a string buffer. /// \return Returns false on error. - static bool get_description(const std::string &base_dir_path, + static bool get_description(const path_type &base_path, std::string *description); /// \brief Sets a description to a file. @@ -444,29 +443,29 @@ class manager_kernel { bool set_description(const std::string &description); /// \brief Sets a description to a file. - /// \param base_dir_path Path to a data store. + /// \param base_path Path to a data store. /// \param description A description to write. /// \return Returns false on error. - static bool set_description(const std::string &base_dir_path, + static bool set_description(const path_type &base_path, const std::string &description); /// \brief Returns an instance that provides access to the attribute of named - /// objects. \param base_dir_path Path to a data store. \return Returns an + /// objects. \param base_path Path to a data store. \return Returns an /// instance of named_object_attr_accessor_type. static named_object_attr_accessor_type access_named_object_attribute( - const std::string &base_dir_path); + const path_type &base_path); /// \brief Returns an instance that provides access to the attribute of unique - /// object. \param base_dir_path Path to a data store. \return Returns an + /// object. \param base_path Path to a data store. \return Returns an /// instance of unique_object_attr_accessor_type. static unique_object_attr_accessor_type access_unique_object_attribute( - const std::string &base_dir_path); + const path_type &base_path); /// \brief Returns an instance that provides access to the attribute of - /// anonymous object. \param base_dir_path Path to a data store. \return + /// anonymous object. \param base_path Path to a data store. \return /// Returns an instance of anonymous_object_attr_accessor_type. static anonymous_object_attr_accessor_type access_anonymous_object_attribute( - const std::string &base_dir_path); + const path_type &base_path); /// \brief Checks if the status of this kernel is good. /// \return Returns true if it is good; otherwise, returns false. @@ -486,35 +485,33 @@ class manager_kernel { void priv_sanity_check() const; bool priv_validate_runtime_configuration() const; - difference_type priv_to_offset(const void *const ptr) const; + difference_type priv_to_offset(const void *ptr) const; void *priv_to_address(difference_type offset) const; // ---------- For data store structure ---------- // // Directory structure: - // base_dir_path/ <- this path is given by user + // base_path/ <- this path is given by user // top_dir/ // some top-level files // management_dir/ // directories and files for allocation management // segment_dir/ // directories and files for application data segment - static std::string priv_make_top_dir_path(const std::string &base_dir_path); - static std::string priv_make_top_level_file_name( - const std::string &base_dir_path, const std::string &item_name); - static std::string priv_make_management_dir_path( - const std::string &base_dir_path); - static std::string priv_make_management_file_name( - const std::string &base_dir_path, const std::string &item_name); - static std::string priv_make_segment_dir_path( - const std::string &base_dir_path); - static bool priv_init_datastore_directory(const std::string &base_dir_path); + static path_type priv_make_top_dir_path(const path_type &base_path); + static path_type priv_make_top_level_file_name(const path_type &base_path, + const std::string &item_name); + static path_type priv_make_management_dir_path(const path_type &base_path); + static path_type priv_make_management_file_name(const path_type &base_path, + const std::string &item_name); + static path_type priv_make_segment_dir_path(const path_type &base_path); + static bool priv_init_datastore_directory(const path_type &base_path); // ---------- For consistence support ---------- // - static bool priv_consistent(const std::string &base_dir_path); + static bool priv_consistent(const path_type &base_path); static bool priv_check_version(const json_store &metadata_json); - static bool priv_properly_closed(const std::string &base_dir_path); - static bool priv_mark_properly_closed(const std::string &base_dir_path); - static bool priv_unmark_properly_closed(const std::string &base_dir_path); + static bool priv_properly_closed(const path_type &base_path); + static bool priv_mark_properly_closed(const path_type &base_path); + static bool priv_unmark_properly_closed(const path_type &base_path); // ---------- For constructed objects ---------- // template @@ -526,11 +523,10 @@ class manager_kernel { difference_type offset, size_type length); - bool priv_remove_attr_object_no_mutex(const difference_type offset); + bool priv_remove_attr_object_no_mutex(difference_type offset); template - void priv_destruct_and_free_memory(const difference_type offset, - const size_type length); + void priv_destruct_and_free_memory(difference_type offset, size_type length); // ---------- For segment ---------- // bool priv_reserve_vm_region(size_type nbytes); @@ -538,9 +534,9 @@ class manager_kernel { bool priv_allocate_segment_header(void *addr); bool priv_deallocate_segment_header(); - bool priv_open(const path_type &base_dir_path, bool read_only, + bool priv_open(const path_type &base_path, bool read_only, size_type vm_reserve_size_request = 0); - bool priv_create(const path_type &base_dir_path, size_type vm_reserve_size); + bool priv_create(const path_type &base_path, size_type vm_reserve_size); // ---------- For serializing/deserializing ---------- // bool priv_serialize_management_data(); @@ -548,23 +544,22 @@ class manager_kernel { // ---------- snapshot ---------- // /// \brief Takes a snapshot. The snapshot has a different UUID. - bool priv_snapshot(const path_type &destination_base_dir_path, - const bool clone, const int num_max_copy_threads); + bool priv_snapshot(const path_type &destination_base_path, bool clone, + int num_max_copy_threads); // ---------- File operations ---------- // /// \brief Copies all backing files using reflink if possible - static bool priv_copy_data_store(const path_type &src_base_dir_path, - const path_type &dst_base_dir_path, - const bool clone, - const int num_max_copy_threads); + static bool priv_copy_data_store(const path_type &src_base_path, + const path_type &dst_base_path, bool clone, + int num_max_copy_threads); /// \brief Removes all backing files - static bool priv_remove_data_store(const path_type &dir_path); + static bool priv_remove_data_store(const path_type &base_path); // ---------- Management metadata ---------- // - static bool priv_read_management_metadata(const path_type &base_dir_path, + static bool priv_read_management_metadata(const path_type &base_path, json_store *json_root); - static bool priv_write_management_metadata(const path_type &base_dir_path, + static bool priv_write_management_metadata(const path_type &base_path, const json_store &json_root); static version_type priv_get_version(const json_store &metadata_json); @@ -574,16 +569,16 @@ class manager_kernel { static std::string priv_get_uuid(const json_store &metadata_json); // ---------- Description ---------- // - static bool priv_read_description(const path_type &base_dir_path, + static bool priv_read_description(const path_type &base_path, std::string *description); - static bool priv_write_description(const path_type &base_dir_path, + static bool priv_write_description(const path_type &base_path, const std::string &description); // -------------------- // // Private fields // -------------------- // bool m_good{false}; - path_type m_base_dir_path{}; + path_type m_base_path{}; size_type m_vm_region_size{0}; void *m_vm_region{nullptr}; segment_header_type *m_segment_header{nullptr}; diff --git a/include/metall/kernel/manager_kernel_impl.ipp b/include/metall/kernel/manager_kernel_impl.ipp index 42df0563..64ae1f7b 100644 --- a/include/metall/kernel/manager_kernel_impl.ipp +++ b/include/metall/kernel/manager_kernel_impl.ipp @@ -39,20 +39,20 @@ manager_kernel::~manager_kernel() noexcept { // Public methods // -------------------- // template -bool manager_kernel::create(const path_type& base_dir_path, +bool manager_kernel::create(const path_type &base_path, const size_type vm_reserve_size) { - return m_good = priv_create(base_dir_path, vm_reserve_size); + return m_good = priv_create(base_path, vm_reserve_size); } template -bool manager_kernel::open_read_only(const path_type& base_dir_path) { - return m_good = priv_open(base_dir_path, true, 0); +bool manager_kernel::open_read_only(const path_type &base_path) { + return m_good = priv_open(base_path, true, 0); } template -bool manager_kernel::open(const path_type& base_dir_path, +bool manager_kernel::open(const path_type &base_path, const size_type vm_reserve_size_request) { - return m_good = priv_open(base_dir_path, false, vm_reserve_size_request); + return m_good = priv_open(base_path, false, vm_reserve_size_request); } template @@ -71,7 +71,7 @@ void manager_kernel::close() { if (!m_data_storage.read_only()) { // This function must be called at the end - priv_mark_properly_closed(m_base_dir_path); + priv_mark_properly_closed(m_base_path); } } } @@ -120,7 +120,7 @@ void *manager_kernel::allocate_aligned( } template -void manager_kernel::deallocate(void *addr) { +void manager_kernel::deallocate(void *const addr) { priv_sanity_check(); if (m_data_storage.read_only()) return; if (!addr) return; @@ -445,56 +445,56 @@ manager_kernel::get_segment_size() const { } template -bool manager_kernel::snapshot(const path_type& destination_base_dir_path, - const bool clone, - const int num_max_copy_threads) { - return priv_snapshot(destination_base_dir_path, clone, num_max_copy_threads); +bool manager_kernel::snapshot( + const path_type &destination_base_path, const bool clone, + const int num_max_copy_threads) { + return priv_snapshot(destination_base_path, clone, num_max_copy_threads); } template -bool manager_kernel::copy(const path_type& source_base_dir_path, - const path_type& destination_base_dir_path, +bool manager_kernel::copy(const path_type &source_base_path, + const path_type &destination_base_path, const bool clone, const int num_max_copy_threads) { - return priv_copy_data_store(source_base_dir_path, destination_base_dir_path, - clone, num_max_copy_threads); + return priv_copy_data_store(source_base_path, destination_base_path, clone, + num_max_copy_threads); } template std::future manager_kernel::copy_async( - const path_type& source_dir_path, const path_type& destination_dir_path, + const path_type &source_base_path, const path_type &destination_base_path, const bool clone, const int num_max_copy_threads) { - return std::async(std::launch::async, copy, source_dir_path, - destination_dir_path, clone, num_max_copy_threads); + return std::async(std::launch::async, copy, source_base_path, destination_base_path, + clone, num_max_copy_threads); } template -bool manager_kernel::remove(const path_type& base_dir_path) { - return priv_remove_data_store(base_dir_path); +bool manager_kernel::remove(const path_type &base_path) { + return priv_remove_data_store(base_path); } template std::future manager_kernel::remove_async( - const path_type& base_dir_path) { - return std::async(std::launch::async, remove, base_dir_path); + const path_type &base_path) { + return std::async(std::launch::async, remove, base_path); } template -bool manager_kernel::consistent(const path_type& dir_path) { - return priv_consistent(dir_path); +bool manager_kernel::consistent(const path_type &base_path) { + return priv_consistent(base_path); } template std::string manager_kernel::get_uuid() const { - return self_type::get_uuid(m_base_dir_path); + return self_type::get_uuid(m_base_path); } template -std::string manager_kernel::get_uuid(const path_type& dir_path) { +std::string manager_kernel::get_uuid(const path_type &base_path) { json_store meta_data; - if (!priv_read_management_metadata(dir_path, &meta_data)) { + if (!priv_read_management_metadata(base_path, &meta_data)) { std::stringstream ss; - ss << "Cannot read management metadata in " << dir_path; + ss << "Cannot read management metadata in " << base_path; logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); return ""; } @@ -503,15 +503,16 @@ std::string manager_kernel::get_uuid(const path_type& dir_path) { template version_type manager_kernel::get_version() const { - return self_type::get_version(m_base_dir_path); + return self_type::get_version(m_base_path); } template -version_type manager_kernel::get_version(const path_type& dir_path) { +version_type manager_kernel::get_version( + const path_type &base_path) { json_store meta_data; - if (!priv_read_management_metadata(dir_path, &meta_data)) { + if (!priv_read_management_metadata(base_path, &meta_data)) { std::stringstream ss; - ss << "Cannot read management metadata in " << dir_path; + ss << "Cannot read management metadata in " << base_path; logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); return 0; } @@ -520,51 +521,51 @@ version_type manager_kernel::get_version(const path_type& dir_path) } template -bool manager_kernel::get_description( - const std::string &base_dir_path, std::string *description) { - return priv_read_description(base_dir_path, description); +bool manager_kernel::get_description(const path_type &base_path, + std::string *description) { + return priv_read_description(base_path, description); } template bool manager_kernel::get_description( std::string *description) const { - return priv_read_description(m_base_dir_path, description); + return priv_read_description(m_base_path, description); } template bool manager_kernel::set_description( - const std::string &base_dir_path, const std::string &description) { - return priv_write_description(base_dir_path, description); + const path_type &base_path, const std::string &description) { + return priv_write_description(base_path, description); } template bool manager_kernel::set_description( const std::string &description) { - return set_description(m_base_dir_path, description); + return set_description(m_base_path, description); } template typename manager_kernel::named_object_attr_accessor_type manager_kernel::access_named_object_attribute( - const std::string &base_dir_path) { + const path_type &base_path) { return named_object_attr_accessor_type(priv_make_management_file_name( - base_dir_path, k_named_object_directory_prefix)); + base_path, k_named_object_directory_prefix)); } template typename manager_kernel::unique_object_attr_accessor_type manager_kernel::access_unique_object_attribute( - const std::string &base_dir_path) { + const path_type &base_path) { return unique_object_attr_accessor_type(priv_make_management_file_name( - base_dir_path, k_unique_object_directory_prefix)); + base_path, k_unique_object_directory_prefix)); } template typename manager_kernel::anonymous_object_attr_accessor_type manager_kernel::access_anonymous_object_attribute( - const std::string &base_dir_path) { + const path_type &base_path) { return anonymous_object_attr_accessor_type(priv_make_management_file_name( - base_dir_path, k_anonymous_object_directory_prefix)); + base_path, k_anonymous_object_directory_prefix)); } template @@ -589,65 +590,73 @@ void *manager_kernel::priv_to_address( } template -std::string manager_kernel::priv_make_top_dir_path( - const std::string &base_dir_path) { - return base_dir_path + "/" + k_datastore_top_dir_name; +typename manager_kernel::path_type +manager_kernel::priv_make_top_dir_path(const path_type &base_path) { + const auto path = data_storage_type::get_path(base_path); + return path + "/" + k_datastore_top_dir_name; } template -std::string manager_kernel::priv_make_top_level_file_name( - const std::string &base_dir_path, const std::string &item_name) { - return priv_make_top_dir_path(base_dir_path) + "/" + item_name; +typename manager_kernel::path_type +manager_kernel::priv_make_top_level_file_name( + const path_type &base_path, const std::string &item_name) { + return priv_make_top_dir_path(base_path) + "/" + item_name; } template -std::string manager_kernel::priv_make_management_dir_path( - const std::string &base_dir_path) { - return priv_make_top_dir_path(base_dir_path) + "/" + +typename manager_kernel::path_type +manager_kernel::priv_make_management_dir_path( + const path_type &base_path) { + return priv_make_top_dir_path(base_path) + "/" + k_datastore_management_dir_name + "/"; } template -std::string manager_kernel::priv_make_management_file_name( - const std::string &base_dir_path, const std::string &item_name) { - return priv_make_management_dir_path(base_dir_path) + "/" + item_name; +typename manager_kernel::path_type +manager_kernel::priv_make_management_file_name( + const path_type &base_path, const std::string &item_name) { + return priv_make_management_dir_path(base_path) + "/" + item_name; } template -std::string manager_kernel::priv_make_segment_dir_path( - const std::string &base_dir_path) { - return priv_make_top_dir_path(base_dir_path) + "/" + +typename manager_kernel::path_type +manager_kernel::priv_make_segment_dir_path( + const path_type &base_path) { + return priv_make_top_dir_path(base_path) + "/" + k_datastore_segment_dir_name + "/"; } template bool manager_kernel::priv_init_datastore_directory( - const std::string &base_dir_path) { - // Create the base directory if needed - if (!mdtl::create_directory(base_dir_path)) { - std::string s("Failed to create directory: " + base_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); - return false; + const path_type &base_path) { + { + const auto base_dir = data_storage_type::get_path(base_path); + // Create the base directory if needed + if (!mdtl::create_directory(base_dir)) { + std::string s("Failed to create directory: " + base_dir); + logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + return false; + } } // Remove existing directory to certainly create a new data store - if (!remove(base_dir_path.c_str())) { - std::string s("Failed to remove a directory: " + base_dir_path); + if (!remove(base_path.c_str())) { + std::string s("Failed to remove a directory: " + base_path); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } // Create internal directories if needed - if (!mdtl::create_directory(priv_make_management_dir_path(base_dir_path))) { + if (!mdtl::create_directory(priv_make_management_dir_path(base_path))) { std::string s("Failed to create directory: " + - priv_make_management_dir_path(base_dir_path)); + priv_make_management_dir_path(base_path)); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } - if (!mdtl::create_directory(priv_make_segment_dir_path(base_dir_path))) { + if (!mdtl::create_directory(priv_make_segment_dir_path(base_path))) { std::string s("Failed to create directory: " + - priv_make_segment_dir_path(base_dir_path)); + priv_make_segment_dir_path(base_path)); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } @@ -658,7 +667,7 @@ bool manager_kernel::priv_init_datastore_directory( template void manager_kernel::priv_sanity_check() const { assert(m_good); - assert(!m_base_dir_path.empty()); + assert(!m_base_path.empty()); assert(m_vm_region_size > 0); assert(m_vm_region); assert(m_segment_header); @@ -700,11 +709,10 @@ bool manager_kernel::priv_validate_runtime_configuration() const { } template -bool manager_kernel::priv_consistent( - const std::string &base_dir_path) { +bool manager_kernel::priv_consistent(const path_type &base_path) { json_store metadata; - return priv_properly_closed(base_dir_path) && - (priv_read_management_metadata(base_dir_path, &metadata) && + return priv_properly_closed(base_path) && + (priv_read_management_metadata(base_path, &metadata) && priv_check_version(metadata)); } @@ -716,23 +724,23 @@ bool manager_kernel::priv_check_version( template bool manager_kernel::priv_properly_closed( - const std::string &base_dir_path) { + const path_type &base_path) { return mdtl::file_exist(priv_make_top_level_file_name( - base_dir_path, k_properly_closed_mark_file_name)); + base_path, k_properly_closed_mark_file_name)); } template bool manager_kernel::priv_mark_properly_closed( - const std::string &base_dir_path) { + const path_type &base_path) { return mdtl::create_file(priv_make_top_level_file_name( - base_dir_path, k_properly_closed_mark_file_name)); + base_path, k_properly_closed_mark_file_name)); } template bool manager_kernel::priv_unmark_properly_closed( - const std::string &base_dir_path) { + const path_type &base_path) { return mdtl::remove_file(priv_make_top_level_file_name( - base_dir_path, k_properly_closed_mark_file_name)); + base_path, k_properly_closed_mark_file_name)); } template @@ -743,7 +751,7 @@ bool manager_kernel::priv_reserve_vm_region( const auto alignment = k_chunk_size; assert(alignment > 0); - m_vm_region_size = mdtl::round_up(nbytes, alignment); + m_vm_region_size = mdtl::round_up((int64_t)nbytes, alignment); m_vm_region = mdtl::reserve_aligned_vm_region(alignment, m_vm_region_size); if (!m_vm_region) { std::stringstream ss; @@ -941,13 +949,13 @@ void manager_kernel::priv_destruct_and_free_memory( template bool manager_kernel::priv_open( - const char *base_dir_path, const bool read_only, + const path_type &base_path, const bool read_only, const size_type vm_reserve_size_request) { if (!priv_validate_runtime_configuration()) { return false; } - if (!priv_read_management_metadata(base_dir_path, m_manager_metadata.get())) { + if (!priv_read_management_metadata(base_path, m_manager_metadata.get())) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to read management metadata"); return false; @@ -962,17 +970,17 @@ bool manager_kernel::priv_open( return false; } - if (!priv_properly_closed(base_dir_path)) { + if (!priv_properly_closed(base_path)) { logger::out(logger::level::error, __FILE__, __LINE__, "Inconsistent data store — it was not closed properly and " "might have been collapsed."); return false; } - m_base_dir_path = base_dir_path; + m_base_path = base_path; const size_type existing_segment_size = - data_storage_type::get_size(priv_make_segment_dir_path(m_base_dir_path)); + data_storage_type::get_size(priv_make_segment_dir_path(m_base_path)); const size_type vm_reserve_size = (read_only) ? existing_segment_size + k_segment_header_size : std::max(existing_segment_size + k_segment_header_size, @@ -988,7 +996,7 @@ bool manager_kernel::priv_open( } // Clear the consistent mark before opening with the write mode - if (!read_only && !priv_unmark_properly_closed(m_base_dir_path)) { + if (!read_only && !priv_unmark_properly_closed(m_base_path)) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to erase the properly close mark before opening"); priv_deallocate_segment_header(); @@ -997,7 +1005,7 @@ bool manager_kernel::priv_open( } if (!m_data_storage.open( - priv_make_segment_dir_path(m_base_dir_path), + priv_make_segment_dir_path(m_base_path), m_vm_region_size - k_segment_header_size, static_cast(m_vm_region) + k_segment_header_size, read_only)) { @@ -1017,7 +1025,7 @@ bool manager_kernel::priv_open( } template -bool manager_kernel::priv_create(const char *base_dir_path, +bool manager_kernel::priv_create(const path_type &base_path, const size_type vm_reserve_size) { if (!priv_validate_runtime_configuration()) { return false; @@ -1031,12 +1039,12 @@ bool manager_kernel::priv_create(const char *base_dir_path, return false; } - m_base_dir_path = base_dir_path; + m_base_path = base_path; - if (!priv_unmark_properly_closed(m_base_dir_path) || - !priv_init_datastore_directory(base_dir_path)) { + if (!priv_unmark_properly_closed(m_base_path) || + !priv_init_datastore_directory(base_path)) { std::stringstream ss; - ss << "Failed to initialize datastore directory under " << base_dir_path; + ss << "Failed to initialize datastore directory under " << base_path; logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); return false; } @@ -1051,7 +1059,7 @@ bool manager_kernel::priv_create(const char *base_dir_path, } if (!m_data_storage.create( - priv_make_segment_dir_path(m_base_dir_path), + priv_make_segment_dir_path(m_base_path), m_vm_region_size - k_segment_header_size, static_cast(m_vm_region) + k_segment_header_size, k_initial_segment_size)) { @@ -1064,7 +1072,7 @@ bool manager_kernel::priv_create(const char *base_dir_path, if (!priv_set_uuid(m_manager_metadata.get()) || !priv_set_version(m_manager_metadata.get()) || - !priv_write_management_metadata(m_base_dir_path, *m_manager_metadata)) { + !priv_write_management_metadata(m_base_path, *m_manager_metadata)) { m_data_storage.destroy(); priv_deallocate_segment_header(); priv_release_vm_region(); @@ -1082,7 +1090,7 @@ bool manager_kernel::priv_serialize_management_data() { if (m_data_storage.read_only()) return true; if (!m_named_object_directory.serialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_named_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1091,7 +1099,7 @@ bool manager_kernel::priv_serialize_management_data() { } if (!m_unique_object_directory.serialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_unique_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1100,7 +1108,7 @@ bool manager_kernel::priv_serialize_management_data() { } if (!m_anonymous_object_directory.serialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_anonymous_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1109,7 +1117,7 @@ bool manager_kernel::priv_serialize_management_data() { } if (!m_segment_memory_allocator.serialize(priv_make_management_file_name( - m_base_dir_path, k_segment_memory_allocator_prefix))) { + m_base_path, k_segment_memory_allocator_prefix))) { return false; } @@ -1119,7 +1127,7 @@ bool manager_kernel::priv_serialize_management_data() { template bool manager_kernel::priv_deserialize_management_data() { if (!m_named_object_directory.deserialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_named_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1128,7 +1136,7 @@ bool manager_kernel::priv_deserialize_management_data() { } if (!m_unique_object_directory.deserialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_unique_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1137,7 +1145,7 @@ bool manager_kernel::priv_deserialize_management_data() { } if (!m_anonymous_object_directory.deserialize( - priv_make_management_file_name(m_base_dir_path, + priv_make_management_file_name(m_base_path, k_anonymous_object_directory_prefix) .c_str())) { logger::out(logger::level::error, __FILE__, __LINE__, @@ -1146,7 +1154,7 @@ bool manager_kernel::priv_deserialize_management_data() { } if (!m_segment_memory_allocator.deserialize(priv_make_management_file_name( - m_base_dir_path, k_segment_memory_allocator_prefix))) { + m_base_path, k_segment_memory_allocator_prefix))) { return false; } @@ -1156,13 +1164,13 @@ bool manager_kernel::priv_deserialize_management_data() { // ---------- snapshot ---------- // template bool manager_kernel::priv_snapshot( - const char *destination_base_dir_path, const bool clone, + const path_type &destination_base_path, const bool clone, const int num_max_copy_threads) { priv_sanity_check(); m_data_storage.sync(true); priv_serialize_management_data(); - const auto dst_top_dir = priv_make_top_dir_path(destination_base_dir_path); + const auto dst_top_dir = priv_make_top_dir_path(destination_base_path); if (!mdtl::create_directory(dst_top_dir)) { std::stringstream ss; ss << "Failed to create a directory: " << dst_top_dir; @@ -1171,9 +1179,8 @@ bool manager_kernel::priv_snapshot( } // Copy segment directory - const auto src_seg_dir = priv_make_segment_dir_path(m_base_dir_path); - const auto dst_seg_dir = - priv_make_segment_dir_path(destination_base_dir_path); + const auto src_seg_dir = priv_make_segment_dir_path(m_base_path); + const auto dst_seg_dir = priv_make_segment_dir_path(destination_base_path); if (!mdtl::create_directory(dst_seg_dir)) { std::stringstream ss; ss << "Failed to create directory: " << dst_seg_dir; @@ -1189,9 +1196,8 @@ bool manager_kernel::priv_snapshot( } // Copy management dircotry - const auto src_mng_dir = priv_make_management_dir_path(m_base_dir_path); - const auto dst_mng_dir = - priv_make_management_dir_path(destination_base_dir_path); + const auto src_mng_dir = priv_make_management_dir_path(m_base_path); + const auto dst_mng_dir = priv_make_management_dir_path(destination_base_path); if (!mdtl::create_directory(dst_mng_dir)) { std::stringstream ss; ss << "Failed to create directory: " << dst_mng_dir; @@ -1212,11 +1218,11 @@ bool manager_kernel::priv_snapshot( json_store meta_data; if (!priv_set_uuid(&meta_data)) return false; if (!priv_set_version(&meta_data)) return false; - if (!priv_write_management_metadata(destination_base_dir_path, meta_data)) + if (!priv_write_management_metadata(destination_base_path, meta_data)) return false; // Finally, mark it as properly-closed - if (!priv_mark_properly_closed(destination_base_dir_path)) { + if (!priv_mark_properly_closed(destination_base_path)) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to create a properly closed mark"); return false; @@ -1228,33 +1234,33 @@ bool manager_kernel::priv_snapshot( // ---------- File operations ---------- // template bool manager_kernel::priv_copy_data_store( - const std::string &src_base_dir_path, const std::string &dst_base_dir_path, + const path_type &src_base_path, const path_type &dst_base_path, const bool use_clone, const int num_max_copy_threads) { - if (!consistent(src_base_dir_path.data())) { + if (!consistent(src_base_path.data())) { std::string s( "Source directory is not consistnt (may not have closed properly or " "may still be open): " + - src_base_dir_path); + src_base_path); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } - const std::string src_top_dir = priv_make_top_dir_path(src_base_dir_path); + const std::string src_top_dir = priv_make_top_dir_path(src_base_path); if (!mdtl::directory_exist(src_top_dir)) { std::string s("Source directory does not exist: " + src_top_dir); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } - if (!mdtl::create_directory(priv_make_top_dir_path(dst_base_dir_path))) { - std::string s("Failed to create directory: " + dst_base_dir_path); + if (!mdtl::create_directory(priv_make_top_dir_path(dst_base_path))) { + std::string s("Failed to create directory: " + dst_base_path); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); return false; } // Copy segment directory - const auto src_seg_dir = priv_make_segment_dir_path(src_base_dir_path); - const auto dst_seg_dir = priv_make_segment_dir_path(dst_base_dir_path); + const auto src_seg_dir = priv_make_segment_dir_path(src_base_path); + const auto dst_seg_dir = priv_make_segment_dir_path(dst_base_path); if (!mdtl::create_directory(dst_seg_dir)) { std::string s("Failed to create directory: " + dst_seg_dir); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); @@ -1269,8 +1275,8 @@ bool manager_kernel::priv_copy_data_store( } // Copy management dircotry - const auto src_mng_dir = priv_make_management_dir_path(src_base_dir_path); - const auto dst_mng_dir = priv_make_management_dir_path(dst_base_dir_path); + const auto src_mng_dir = priv_make_management_dir_path(src_base_path); + const auto dst_mng_dir = priv_make_management_dir_path(dst_base_path); if (!mdtl::create_directory(dst_mng_dir)) { std::string s("Failed to create directory: " + dst_mng_dir); logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); @@ -1287,7 +1293,7 @@ bool manager_kernel::priv_copy_data_store( } // Finally, mark it as properly-closed - if (!priv_mark_properly_closed(dst_base_dir_path)) { + if (!priv_mark_properly_closed(dst_base_path)) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to create a properly closed mark"); return false; @@ -1298,17 +1304,17 @@ bool manager_kernel::priv_copy_data_store( template bool manager_kernel::priv_remove_data_store( - const std::string &base_dir_path) { - return mdtl::remove_file(priv_make_top_dir_path(base_dir_path)); + const path_type &base_path) { + return mdtl::remove_file(priv_make_top_dir_path(base_path)); } // ---------- Management metadata ---------- // template bool manager_kernel::priv_write_management_metadata( - const std::string &base_dir_path, const json_store &json_root) { - if (!mdtl::ptree::write_json( - json_root, priv_make_management_file_name( - base_dir_path, k_manager_metadata_file_name))) { + const path_type &base_path, const json_store &json_root) { + if (!mdtl::ptree::write_json(json_root, + priv_make_management_file_name( + base_path, k_manager_metadata_file_name))) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to write management metadata"); return false; @@ -1319,9 +1325,9 @@ bool manager_kernel::priv_write_management_metadata( template bool manager_kernel::priv_read_management_metadata( - const std::string &base_dir_path, json_store *json_root) { + const path_type &base_path, json_store *json_root) { if (!mdtl::ptree::read_json(priv_make_management_file_name( - base_dir_path, k_manager_metadata_file_name), + base_path, k_manager_metadata_file_name), json_root)) { logger::out(logger::level::error, __FILE__, __LINE__, "Failed to read management metadata"); @@ -1397,9 +1403,9 @@ bool manager_kernel::priv_set_uuid(json_store *metadata_json) { template bool manager_kernel::priv_read_description( - const std::string &base_dir_path, std::string *description) { + const path_type &base_path, std::string *description) { const auto &file_name = - priv_make_management_file_name(base_dir_path, k_description_file_name); + priv_make_management_file_name(base_path, k_description_file_name); if (!mdtl::file_exist(file_name)) { return false; // This is not an error @@ -1422,9 +1428,9 @@ bool manager_kernel::priv_read_description( template bool manager_kernel::priv_write_description( - const std::string &base_dir_path, const std::string &description) { + const path_type &base_path, const std::string &description) { const auto &file_name = - priv_make_management_file_name(base_dir_path, k_description_file_name); + priv_make_management_file_name(base_path, k_description_file_name); std::ofstream ofs(file_name); if (!ofs.is_open()) { diff --git a/include/metall/kernel/mmap_data_storage.hpp b/include/metall/kernel/mmap_data_storage.hpp index 7ccbd6da..b23e5467 100644 --- a/include/metall/kernel/mmap_data_storage.hpp +++ b/include/metall/kernel/mmap_data_storage.hpp @@ -32,6 +32,10 @@ class mmap_data_storage { using different_type = std::ptrdiff_t; using path_type = std::string; + inline static path_type get_path(const path_type &base_path) { + return base_path; + } + mmap_data_storage() { #ifdef METALL_USE_ANONYMOUS_NEW_MAP logger::out(logger::level::info, __FILE__, __LINE__,