Line data Source code
1 : /* 2 : Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain 3 : Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany 4 : 5 : This software was partially supported by the 6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). 7 : 8 : This software was partially supported by the 9 : ADA-FS project under the SPPEXA project funded by the DFG. 10 : 11 : This file is part of GekkoFS. 12 : 13 : GekkoFS is free software: you can redistribute it and/or modify 14 : it under the terms of the GNU General Public License as published by 15 : the Free Software Foundation, either version 3 of the License, or 16 : (at your option) any later version. 17 : 18 : GekkoFS is distributed in the hope that it will be useful, 19 : but WITHOUT ANY WARRANTY; without even the implied warranty of 20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 : GNU General Public License for more details. 22 : 23 : You should have received a copy of the GNU General Public License 24 : along with GekkoFS. If not, see <https://www.gnu.org/licenses/>. 25 : 26 : SPDX-License-Identifier: GPL-3.0-or-later 27 : */ 28 : 29 : #ifndef GEKKOFS_DAEMON_METADATA_LOGGING_HPP 30 : #define GEKKOFS_DAEMON_METADATA_LOGGING_HPP 31 : 32 : #include <spdlog/spdlog.h> 33 : #include <map> 34 : 35 : namespace gkfs::metadata { 36 : 37 : /** 38 : * @brief MetadataModule is a singleton class that holds global data structures 39 : * for all metadata operations. 40 : */ 41 : class MetadataModule { 42 : 43 : private: 44 33 : MetadataModule() = default; 45 : 46 : std::shared_ptr<spdlog::logger> log_; ///< Metadata logger 47 : ///< Map to remember and assign offsets to write append operations 48 : std::map<uint16_t, size_t> append_offset_reserve_{}; 49 : std::mutex append_offset_reserve_mutex_{}; ///< Mutex to protect 50 : ///< append_offset_reserve_ 51 : 52 : public: 53 : ///< Logger name 54 : static constexpr const char* LOGGER_NAME = "MetadataModule"; 55 : 56 : /** 57 : * @brief Get the MetadataModule singleton instance 58 : * @return MetadataModule instance 59 : */ 60 : static MetadataModule* 61 183 : getInstance() { 62 183 : static MetadataModule instance; 63 183 : return &instance; 64 : } 65 : 66 : MetadataModule(MetadataModule const&) = delete; 67 : 68 : void 69 : operator=(MetadataModule const&) = delete; 70 : 71 : const std::shared_ptr<spdlog::logger>& 72 : log() const; 73 : 74 : void 75 : log(const std::shared_ptr<spdlog::logger>& log); 76 : 77 : const std::map<uint16_t, size_t>& 78 : append_offset_reserve() const; 79 : 80 : /** 81 : * @brief Inserts entry into append_offset_reserve_ 82 : * @param merge_id Merge ID 83 : * @param offset Offset to reserve 84 : */ 85 : void 86 : append_offset_reserve_put(uint16_t merge_id, size_t offset); 87 : 88 : /** 89 : * @brief Gets and erases entry from append_offset_reserve_ 90 : * @param merge_id Merge ID 91 : * @return Offset reserved for merge_id 92 : * @throws std::out_of_range if merge_id is not in append_offset_reserve_ 93 : */ 94 : size_t 95 : append_offset_reserve_get_and_erase(uint16_t merge_id); 96 : }; 97 : 98 : #define GKFS_METADATA_MOD \ 99 : (static_cast<gkfs::metadata::MetadataModule*>( \ 100 : gkfs::metadata::MetadataModule::getInstance())) 101 : 102 : } // namespace gkfs::metadata 103 : 104 : #endif // GEKKOFS_DAEMON_METADATA_LOGGING_HPP