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_METADATA_BACKEND_HPP
30 : #define GEKKOFS_METADATA_BACKEND_HPP
31 :
32 : #include <memory>
33 : #include <spdlog/spdlog.h>
34 : #include <daemon/backend/exceptions.hpp>
35 : #include <tuple>
36 :
37 : namespace gkfs::metadata {
38 :
39 :
40 33 : class AbstractMetadataBackend {
41 : public:
42 : virtual ~AbstractMetadataBackend() = default;
43 :
44 : virtual std::string
45 : get(const std::string& key) const = 0;
46 :
47 : virtual void
48 : put(const std::string& key, const std::string& val) = 0;
49 :
50 : virtual void
51 : put_no_exist(const std::string& key, const std::string& val) = 0;
52 :
53 : virtual void
54 : remove(const std::string& key) = 0;
55 :
56 : virtual bool
57 : exists(const std::string& key) = 0;
58 :
59 : virtual void
60 : update(const std::string& old_key, const std::string& new_key,
61 : const std::string& val) = 0;
62 :
63 : virtual off_t
64 : increase_size(const std::string& key, size_t size, off_t offset,
65 : bool append) = 0;
66 :
67 : virtual void
68 : decrease_size(const std::string& key, size_t size) = 0;
69 :
70 : virtual std::vector<std::pair<std::string, bool>>
71 : get_dirents(const std::string& dir) const = 0;
72 :
73 : virtual std::vector<std::tuple<std::string, bool, size_t, time_t>>
74 : get_dirents_extended(const std::string& dir) const = 0;
75 :
76 : virtual void
77 : iterate_all() const = 0;
78 : };
79 :
80 : template <typename T>
81 33 : class MetadataBackend : public AbstractMetadataBackend {
82 : private:
83 : std::string path;
84 : std::shared_ptr<spdlog::logger> log_;
85 :
86 : public:
87 : std::string
88 1403 : get(const std::string& key) const {
89 1403 : return static_cast<T const&>(*this).get_impl(key);
90 : }
91 :
92 : void
93 1097 : put(const std::string& key, const std::string& val) {
94 1097 : static_cast<T&>(*this).put_impl(key, val);
95 1097 : }
96 :
97 : void
98 1100 : put_no_exist(const std::string& key, const std::string& val) {
99 1100 : static_cast<T&>(*this).put_no_exist_impl(key, val);
100 1097 : }
101 :
102 : void
103 8 : remove(const std::string& key) {
104 8 : static_cast<T&>(*this).remove_impl(key);
105 8 : }
106 :
107 : bool
108 1100 : exists(const std::string& key) {
109 1100 : return static_cast<T&>(*this).exists_impl(key);
110 : }
111 :
112 : void
113 31 : update(const std::string& old_key, const std::string& new_key,
114 : const std::string& val) {
115 31 : static_cast<T&>(*this).update_impl(old_key, new_key, val);
116 31 : }
117 :
118 : off_t
119 41 : increase_size(const std::string& key, size_t size, off_t offset,
120 : bool append) {
121 41 : return static_cast<T&>(*this).increase_size_impl(key, size, offset,
122 41 : append);
123 : }
124 :
125 : void
126 3 : decrease_size(const std::string& key, size_t size) {
127 3 : static_cast<T&>(*this).decrease_size_impl(key, size);
128 3 : }
129 :
130 : std::vector<std::pair<std::string, bool>>
131 25 : get_dirents(const std::string& dir) const {
132 25 : return static_cast<T const&>(*this).get_dirents_impl(dir);
133 : }
134 :
135 : std::vector<std::tuple<std::string, bool, size_t, time_t>>
136 4 : get_dirents_extended(const std::string& dir) const {
137 4 : return static_cast<T const&>(*this).get_dirents_extended_impl(dir);
138 : }
139 :
140 : void
141 0 : iterate_all() const {
142 0 : static_cast<T const&>(*this).iterate_all_impl();
143 0 : }
144 : };
145 :
146 : } // namespace gkfs::metadata
147 :
148 : #endif // GEKKOFS_METADATA_BACKEND_HPP
|