Metall v0.30
A persistent memory allocator for data-centric analytics
 
Loading...
Searching...
No Matches
basic_manager.hpp
Go to the documentation of this file.
1// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall
2// Project Developers. See the top-level COPYRIGHT file for details.
3//
4// SPDX-License-Identifier: (Apache-2.0 OR MIT)
5
6#ifndef METALL_BASIC_MANAGER_HPP
7#define METALL_BASIC_MANAGER_HPP
8
9#include <cstddef>
10#include <memory>
11
12#include <metall/tags.hpp>
16#include <metall/kernel/manager_kernel.hpp>
17#include <metall/detail/named_proxy.hpp>
18#include <metall/kernel/segment_storage.hpp>
19#include <metall/kernel/storage.hpp>
20#include <metall/kernel/segment_storage.hpp>
21
22namespace metall {
23
24#if !defined(DOXYGEN_SKIP)
25// Forward declaration
26template <typename storage, typename segment_storage, typename chunk_no_type,
27 std::size_t k_chunk_size>
28class basic_manager;
29#endif // DOXYGEN_SKIP
30
36template <typename storage = kernel::storage,
37 typename segment_storage = kernel::segment_storage,
38 typename chunk_no_type = uint32_t,
39 std::size_t k_chunk_size = (1ULL << 21ULL)>
41 public:
42 // -------------------- //
43 // Public types and static values
44 // -------------------- //
45
48 kernel::manager_kernel<storage, segment_storage, chunk_no_type,
49 k_chunk_size>;
50
52 using void_pointer = typename manager_kernel_type::void_pointer;
53
55 using char_type = typename manager_kernel_type::char_type;
56
58 using size_type = typename manager_kernel_type::size_type;
59
61 using difference_type = typename manager_kernel_type::difference_type;
62
64 template <typename T>
66
68 template <typename OuterT, typename... InnerT>
72
96 template <typename T>
99
101 template <typename T>
104
106 template <typename T>
108 metall::mtlldetail::named_proxy<manager_kernel_type, T, false>;
109
111 template <typename T>
113 metall::mtlldetail::named_proxy<manager_kernel_type, T, true>;
114
117 using instance_kind = typename manager_kernel_type::instance_kind;
118
121 typename manager_kernel_type::const_named_iterator;
122
125 typename manager_kernel_type::const_unique_iterator;
126
129 typename manager_kernel_type::const_anonymous_iterator;
130
133 typename manager_kernel_type::named_object_attr_accessor_type;
134
137 typename manager_kernel_type::unique_object_attr_accessor_type;
138
141 typename manager_kernel_type::anonymous_object_attr_accessor_type;
142
144 using chunk_number_type = chunk_no_type;
145
147 using path_type = typename manager_kernel_type::path_type;
148
149 private:
150 // -------------------- //
151 // Private types and static values
152 // -------------------- //
153 using char_ptr_holder_type =
154 typename manager_kernel_type::char_ptr_holder_type;
155 using self_type =
157
158 public:
159 // -------------------- //
160 // Constructor & assign operator
161 // -------------------- //
162
165 basic_manager(open_only_t, const path_type &base_path) noexcept {
166 try {
167 m_kernel = std::make_unique<manager_kernel_type>();
168 m_kernel->open(base_path);
169 } catch (...) {
170 m_kernel.reset(nullptr);
171 logger::out(logger::level::error, __FILE__, __LINE__,
172 "An exception has been thrown");
173 }
174 }
175
179 basic_manager(open_read_only_t, const path_type &base_path) noexcept {
180 try {
181 m_kernel = std::make_unique<manager_kernel_type>();
182 m_kernel->open_read_only(base_path);
183 } catch (...) {
184 m_kernel.reset(nullptr);
185 logger::out(logger::level::error, __FILE__, __LINE__,
186 "An exception has been thrown");
187 }
188 }
189
192 basic_manager(create_only_t, const path_type &base_path) noexcept {
193 try {
194 m_kernel = std::make_unique<manager_kernel_type>();
195 m_kernel->create(base_path);
196 } catch (...) {
197 m_kernel.reset(nullptr);
198 logger::out(logger::level::error, __FILE__, __LINE__,
199 "An exception has been thrown");
200 }
201 }
202
207 // The actual limit could be smaller or larger than this value, depending on
208 // the internal implementation. The gap between the hint and the actual limit
209 // will be reasonable (e.g., less than a few chunk sizes).
211 const size_type capacity) noexcept {
212 try {
213 m_kernel = std::make_unique<manager_kernel_type>();
214 m_kernel->create(base_path, capacity);
215 } catch (...) {
216 m_kernel.reset(nullptr);
217 logger::out(logger::level::error, __FILE__, __LINE__,
218 "An exception has been thrown");
219 }
220 }
221
223 basic_manager() = delete;
224
226 ~basic_manager() noexcept = default;
227
229 basic_manager(const basic_manager &) = delete;
230
232 basic_manager(basic_manager &&) noexcept = default;
233
236 basic_manager &operator=(const basic_manager &) = delete;
237
240 basic_manager &operator=(basic_manager &&) noexcept = default;
241
242 // -------------------- //
243 // Public methods
244 // -------------------- //
245
261
265
270
276
281
286
291
315 template <typename T>
316 construct_proxy<T> construct(char_ptr_holder_type name) {
317 return construct_proxy<T>(m_kernel.get(), name, false, false);
318 }
319
344 template <typename T>
345 construct_proxy<T> find_or_construct(char_ptr_holder_type name) {
346 return construct_proxy<T>(m_kernel.get(), name, true, false);
347 }
348
370 template <typename T>
371 construct_iter_proxy<T> construct_it(char_ptr_holder_type name) {
372 return construct_iter_proxy<T>(m_kernel.get(), name, false, false);
373 }
374
397 template <typename T>
399 return construct_iter_proxy<T>(m_kernel.get(), name, true, false);
400 }
401
416 template <typename T>
417 std::pair<T *, size_type> find(char_ptr_holder_type name) const noexcept {
418 if (!check_sanity()) {
419 return std::make_pair(nullptr, 0);
420 }
421
422 try {
423 return m_kernel->template find<T>(name);
424 } catch (...) {
425 logger::out(logger::level::error, __FILE__, __LINE__,
426 "An exception has been thrown");
427 }
428
429 return std::make_pair(nullptr, 0);
430 }
431
455 template <typename T>
456 bool destroy(const char *name) {
457 if (!check_sanity()) {
458 return false;
459 }
460 return m_kernel->template destroy<T>(name);
461 }
462
485 template <typename T>
486 bool destroy(const metall::mtlldetail::unique_instance_t *const) {
487 if (!check_sanity()) {
488 return false;
489 }
490 return m_kernel->template destroy<T>(metall::unique_instance);
491 }
492
520 template <class T>
521 bool destroy_ptr(const T *ptr) {
522 if (!check_sanity()) {
523 return false;
524 }
525 return m_kernel->template destroy_ptr<T>(ptr);
526 }
527
545 template <class T>
546 const char_type *get_instance_name(const T *ptr) const noexcept {
547 if (!check_sanity()) {
548 return nullptr;
549 }
550 try {
551 return m_kernel->get_instance_name(ptr);
552 } catch (...) {
553 logger::out(logger::level::error, __FILE__, __LINE__,
554 "An exception has been thrown");
555 }
556 return nullptr;
557 }
558
573 template <class T>
574 instance_kind get_instance_kind(const T *ptr) const noexcept {
575 if (!check_sanity()) {
576 return instance_kind();
577 }
578 try {
579 return m_kernel->get_instance_kind(ptr);
580 } catch (...) {
581 logger::out(logger::level::error, __FILE__, __LINE__,
582 "An exception has been thrown");
583 }
584 return instance_kind();
585 }
586
602 template <class T>
603 size_type get_instance_length(const T *ptr) const noexcept {
604 if (!check_sanity()) {
605 return 0;
606 }
607 try {
608 return m_kernel->get_instance_length(ptr);
609 } catch (...) {
610 logger::out(logger::level::error, __FILE__, __LINE__,
611 "An exception has been thrown");
612 }
613 return 0;
614 }
615
629 template <class T>
630 bool is_instance_type(const void *const ptr) const noexcept {
631 if (!check_sanity()) {
632 return false;
633 }
634 try {
635 return m_kernel->template is_instance_type<T>(ptr);
636 } catch (...) {
637 logger::out(logger::level::error, __FILE__, __LINE__,
638 "An exception has been thrown");
639 }
640 return false;
641 }
642
658 template <class T>
659 bool get_instance_description(const T *ptr,
660 std::string *description) const noexcept {
661 if (!check_sanity()) {
662 return false;
663 }
664 try {
665 return m_kernel->get_instance_description(ptr, description);
666 } catch (...) {
667 logger::out(logger::level::error, __FILE__, __LINE__,
668 "An exception has been thrown");
669 }
670 return false;
671 }
672
688 template <class T>
689 bool set_instance_description(const T *ptr,
690 const std::string &description) noexcept {
691 if (!check_sanity()) {
692 return false;
693 }
694 try {
695 return m_kernel->set_instance_description(ptr, description);
696 } catch (...) {
697 m_kernel.reset(nullptr);
698 logger::out(logger::level::error, __FILE__, __LINE__,
699 "An exception has been thrown");
700 }
701 return false;
702 }
703
714 if (!check_sanity()) {
715 return 0;
716 }
717 try {
718 return m_kernel->get_num_named_objects();
719 } catch (...) {
720 logger::out(logger::level::error, __FILE__, __LINE__,
721 "An exception has been thrown");
722 }
723 return 0;
724 }
725
733 if (!check_sanity()) {
734 return 0;
735 }
736 try {
737 return m_kernel->get_num_unique_objects();
738 } catch (...) {
739 logger::out(logger::level::error, __FILE__, __LINE__,
740 "An exception has been thrown");
741 }
742 return 0;
743 }
744
752 if (!check_sanity()) {
753 return 0;
754 }
755 try {
756 return m_kernel->get_num_anonymous_objects();
757 } catch (...) {
758 logger::out(logger::level::error, __FILE__, __LINE__,
759 "An exception has been thrown");
760 }
761 return 0;
762 }
763
770 if (!check_sanity()) {
771 return const_named_iterator();
772 }
773 try {
774 return m_kernel->named_begin();
775 } catch (...) {
776 logger::out(logger::level::error, __FILE__, __LINE__,
777 "An exception has been thrown");
778 }
779 return const_named_iterator();
780 }
781
789 if (!check_sanity()) {
790 return const_named_iterator();
791 }
792 try {
793 return m_kernel->named_end();
794 } catch (...) {
795 logger::out(logger::level::error, __FILE__, __LINE__,
796 "An exception has been thrown");
797 }
798 return const_named_iterator();
799 }
800
808 if (!check_sanity()) {
809 return const_unique_iterator();
810 }
811 try {
812 return m_kernel->unique_begin();
813 } catch (...) {
814 logger::out(logger::level::error, __FILE__, __LINE__,
815 "An exception has been thrown");
816 }
817 return const_unique_iterator();
818 }
819
827 if (!check_sanity()) {
828 return const_unique_iterator();
829 }
830 try {
831 return m_kernel->unique_end();
832 } catch (...) {
833 logger::out(logger::level::error, __FILE__, __LINE__,
834 "An exception has been thrown");
835 }
836 return const_unique_iterator();
837 }
838
846 if (!check_sanity()) {
848 }
849 try {
850 return m_kernel->anonymous_begin();
851 } catch (...) {
852 logger::out(logger::level::error, __FILE__, __LINE__,
853 "An exception has been thrown");
854 }
856 }
857
864 if (!check_sanity()) {
866 }
867 try {
868 return m_kernel->anonymous_end();
869 } catch (...) {
870 logger::out(logger::level::error, __FILE__, __LINE__,
871 "An exception has been thrown");
872 }
874 }
875
876 // TODO: implement
877 // bool belongs_to_segment (const void *ptr) const;
878
879 // ---------- Allocate memory by size ---------- //
880
886 void *allocate(size_type nbytes) noexcept {
887 if (!check_sanity()) {
888 return nullptr;
889 }
890 try {
891 return m_kernel->allocate(nbytes);
892 } catch (...) {
893 m_kernel.reset(nullptr);
894 logger::out(logger::level::error, __FILE__, __LINE__,
895 "An exception has been thrown");
896 }
897 return nullptr;
898 }
899
909 void *allocate_aligned(size_type nbytes, size_type alignment) noexcept {
910 if (!check_sanity()) {
911 return nullptr;
912 }
913 try {
914 return m_kernel->allocate_aligned(nbytes, alignment);
915 } catch (...) {
916 m_kernel.reset(nullptr);
917 logger::out(logger::level::error, __FILE__, __LINE__,
918 "An exception has been thrown");
919 }
920 return nullptr;
921 }
922
923 // void allocate_many(const std::nothrow_t &tag, size_type elem_bytes,
924 // size_type n_elements, multiallocation_chain &chain);
925
930 void deallocate(void *addr) noexcept {
931 if (!check_sanity()) {
932 return;
933 }
934 try {
935 return m_kernel->deallocate(addr);
936 } catch (...) {
937 m_kernel.reset(nullptr);
938 logger::out(logger::level::error, __FILE__, __LINE__,
939 "An exception has been thrown");
940 }
941 }
942
943 // void deallocate_many(multiallocation_chain &chain);
944
952 bool all_memory_deallocated() const noexcept {
953 if (!check_sanity()) {
954 return false;
955 }
956
957 try {
958 return m_kernel->all_memory_deallocated();
959 } catch (...) {
960 logger::out(logger::level::error, __FILE__, __LINE__,
961 "An exception has been thrown");
962 }
963 return false;
964 }
965
966 // ---------- Flush ---------- //
972 void flush(const bool synchronous = true) noexcept {
973 if (!check_sanity()) {
974 return;
975 }
976 try {
977 m_kernel->flush(synchronous);
978 } catch (...) {
979 m_kernel.reset(nullptr);
980 logger::out(logger::level::error, __FILE__, __LINE__,
981 "An exception has been thrown");
982 }
983 }
984
985 // -------- Snapshot, copy, data store management -------- //
994 bool snapshot(const path_type &destination_path, const bool clone = true,
995 const int num_max_copy_threads = 0) noexcept {
996 if (!check_sanity()) {
997 return false;
998 }
999 try {
1000 return m_kernel->snapshot(destination_path, clone, num_max_copy_threads);
1001 } catch (...) {
1002 m_kernel.reset(nullptr);
1003 logger::out(logger::level::error, __FILE__, __LINE__,
1004 "An exception has been thrown");
1005 }
1006 return false;
1007 }
1008
1021 static bool copy(const path_type &source_path,
1022 const path_type &destination_path, const bool clone = true,
1023 const int num_max_copy_threads = 0) noexcept {
1024 try {
1025 return manager_kernel_type::copy(source_path, destination_path, clone,
1026 num_max_copy_threads);
1027 } catch (...) {
1028 logger::out(logger::level::error, __FILE__, __LINE__,
1029 "An exception has been thrown");
1030 }
1031 return false;
1032 }
1033
1048 static auto copy_async(const path_type source_path,
1049 const path_type destination_path,
1050 const bool clone = true,
1051 const int num_max_copy_threads = 0) noexcept {
1052 try {
1053 return manager_kernel_type::copy_async(source_path, destination_path,
1054 clone, num_max_copy_threads);
1055 } catch (...) {
1056 logger::out(logger::level::error, __FILE__, __LINE__,
1057 "An exception has been thrown");
1058 }
1059 return std::future<bool>();
1060 }
1061
1068 static bool remove(const path_type &path) noexcept {
1069 try {
1070 return manager_kernel_type::remove(path);
1071 } catch (...) {
1072 logger::out(logger::level::error, __FILE__, __LINE__,
1073 "An exception has been thrown");
1074 }
1075 return false;
1076 }
1077
1085 static std::future<bool> remove_async(const path_type &path) noexcept {
1086 try {
1087 return std::async(std::launch::async, remove, path);
1088 } catch (...) {
1089 logger::out(logger::level::error, __FILE__, __LINE__,
1090 "An exception has been thrown");
1091 }
1092 return std::future<bool>();
1093 }
1094
1107 static bool consistent(const path_type &path) noexcept {
1108 try {
1109 return manager_kernel_type::consistent(path);
1110 } catch (...) {
1111 logger::out(logger::level::error, __FILE__, __LINE__,
1112 "An exception has been thrown");
1113 }
1114 return false;
1115 }
1116
1121 std::string get_uuid() const noexcept {
1122 if (!check_sanity()) {
1123 return std::string();
1124 }
1125 try {
1126 return m_kernel->get_uuid();
1127 } catch (...) {
1128 logger::out(logger::level::error, __FILE__, __LINE__,
1129 "An exception has been thrown");
1130 }
1131 return std::string();
1132 }
1133
1139 static std::string get_uuid(const path_type &path) noexcept {
1140 try {
1141 return manager_kernel_type::get_uuid(path);
1142 } catch (...) {
1143 logger::out(logger::level::error, __FILE__, __LINE__,
1144 "An exception has been thrown");
1145 }
1146 return std::string();
1147 }
1148
1153 version_type get_version() const noexcept {
1154 if (!check_sanity()) {
1155 return version_type();
1156 }
1157 try {
1158 return m_kernel->get_version();
1159 } catch (...) {
1160 logger::out(logger::level::error, __FILE__, __LINE__,
1161 "An exception has been thrown");
1162 }
1163 return version_type();
1164 }
1165
1171 static version_type get_version(const path_type &path) noexcept {
1172 try {
1173 return manager_kernel_type::get_version(path);
1174 } catch (...) {
1175 logger::out(logger::level::error, __FILE__, __LINE__,
1176 "An exception has been thrown");
1177 return version_type();
1178 }
1179 }
1180
1181 // ---------- Data store description ---------- //
1182
1192 bool set_description(const std::string &description) noexcept {
1193 if (!check_sanity()) {
1194 return false;
1195 }
1196 try {
1197 return m_kernel->set_description(description);
1198 } catch (...) {
1199 m_kernel.reset(nullptr);
1200 logger::out(logger::level::error, __FILE__, __LINE__,
1201 "An exception has been thrown");
1202 }
1203 return false;
1204 }
1205
1214 static bool set_description(const path_type &path,
1215 const std::string &description) noexcept {
1216 try {
1217 return manager_kernel_type::set_description(path, description);
1218 } catch (...) {
1219 logger::out(logger::level::error, __FILE__, __LINE__,
1220 "An exception has been thrown");
1221 }
1222 return false;
1223 }
1224
1234 bool get_description(std::string *description) const noexcept {
1235 if (!check_sanity()) {
1236 return false;
1237 }
1238 try {
1239 return m_kernel->get_description(description);
1240 } catch (...) {
1241 logger::out(logger::level::error, __FILE__, __LINE__,
1242 "An exception has been thrown");
1243 }
1244 return false;
1245 }
1246
1256 static bool get_description(const path_type &path,
1257 std::string *description) noexcept {
1258 try {
1259 return manager_kernel_type::get_description(path, description);
1260 } catch (...) {
1261 logger::out(logger::level::error, __FILE__, __LINE__,
1262 "An exception has been thrown");
1263 }
1264 return false;
1265 }
1266
1267 // ---------- Object attribute ---------- //
1275 const path_type &path) noexcept {
1276 try {
1277 return manager_kernel_type::access_named_object_attribute(path);
1278 } catch (...) {
1279 logger::out(logger::level::error, __FILE__, __LINE__,
1280 "An exception has been thrown");
1281 }
1283 }
1284
1292 const path_type &path) noexcept {
1293 try {
1294 return manager_kernel_type::access_unique_object_attribute(path);
1295 } catch (...) {
1296 logger::out(logger::level::error, __FILE__, __LINE__,
1297 "An exception has been thrown");
1298 }
1300 }
1301
1308 static anonymous_object_attribute_accessor_type
1310 try {
1311 return manager_kernel_type::access_anonymous_object_attribute(path);
1312 } catch (...) {
1313 logger::out(logger::level::error, __FILE__, __LINE__,
1314 "An exception has been thrown");
1315 }
1317 }
1318
1319 // ---------- etc ---------- //
1325 template <typename T = std::byte>
1327 if (!check_sanity()) {
1328 return allocator_type<T>(nullptr);
1329 }
1330 try {
1331 return allocator_type<T>(reinterpret_cast<manager_kernel_type *const *>(
1332 &(m_kernel->get_segment_header().manager_kernel_address)));
1333 } catch (...) {
1334 logger::out(logger::level::error, __FILE__, __LINE__,
1335 "An exception has been thrown");
1336 }
1337 return allocator_type<T>(nullptr);
1338 }
1339
1344 static constexpr size_type chunk_size() noexcept { return k_chunk_size; }
1345
1350 const void *get_address() const noexcept {
1351 if (!check_sanity()) {
1352 return nullptr;
1353 }
1354 try {
1355 return m_kernel->get_segment();
1356 } catch (...) {
1357 logger::out(logger::level::error, __FILE__, __LINE__,
1358 "An exception has been thrown");
1359 }
1360 return nullptr;
1361 }
1362
1369 size_type get_size() const noexcept {
1370 if (!check_sanity()) {
1371 return 0;
1372 }
1373 try {
1374 return m_kernel->get_segment_size();
1375 } catch (...) {
1376 logger::out(logger::level::error, __FILE__, __LINE__,
1377 "An exception has been thrown");
1378 }
1379 return 0;
1380 }
1381
1386 bool read_only() const noexcept {
1387 if (!check_sanity()) {
1388 return true;
1389 }
1390 try {
1391 return m_kernel->read_only();
1392 } catch (...) {
1393 logger::out(logger::level::error, __FILE__, __LINE__,
1394 "An exception has been thrown");
1395 }
1396 return true;
1397 }
1398
1399 // bool belongs_to_segment (const void *ptr) const
1400
1405 bool check_sanity() const noexcept { return !!m_kernel && m_kernel->good(); }
1406
1407 // ---------- For profiling and debug ---------- //
1408#if !defined(DOXYGEN_SKIP)
1412 template <typename out_stream_type>
1413 void profile(out_stream_type *log_out) noexcept {
1414 if (!check_sanity()) {
1415 return;
1416 }
1417 try {
1418 m_kernel->profile(log_out);
1419 } catch (...) {
1420 m_kernel.reset(nullptr);
1421 logger::out(logger::level::error, __FILE__, __LINE__,
1422 "An exception has been thrown");
1423 }
1424 }
1425#endif
1426
1427 private:
1428 // -------------------- //
1429 // Private fields
1430 // -------------------- //
1431 std::unique_ptr<manager_kernel_type> m_kernel{nullptr};
1432};
1433} // namespace metall
1434
1435#endif // METALL_BASIC_MANAGER_HPP
A generalized Metall manager class.
Definition basic_manager.hpp:40
bool read_only() const noexcept
Returns if this manager was opened as read-only.
Definition basic_manager.hpp:1386
const_anonymous_iterator anonymous_begin() const noexcept
Returns a constant iterator to the index storing the anonymous objects.
Definition basic_manager.hpp:845
basic_manager(create_only_t, const path_type &base_path, const size_type capacity) noexcept
Creates a new data store (an existing data store will be overwritten).
Definition basic_manager.hpp:210
static anonymous_object_attribute_accessor_type access_anonymous_object_attribute(const path_type &path) noexcept
Returns an instance that provides access to the attribute of anonymous object.
Definition basic_manager.hpp:1309
typename manager_kernel_type::unique_object_attr_accessor_type unique_object_attribute_accessor_type
Provides access to unique object attribute.
Definition basic_manager.hpp:137
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
Copies data store synchronously. The behavior of copying a data store that is open without the read-o...
Definition basic_manager.hpp:1021
typename manager_kernel_type::void_pointer void_pointer
Void pointer type.
Definition basic_manager.hpp:52
std::pair< T *, size_type > find(char_ptr_holder_type name) const noexcept
Tries to find a previously created object.
Definition basic_manager.hpp:417
typename manager_kernel_type::path_type path_type
Path type.
Definition basic_manager.hpp:147
static std::future< bool > remove_async(const path_type &path) noexcept
Remove data store asynchronously.
Definition basic_manager.hpp:1085
basic_manager(open_read_only_t, const path_type &base_path) noexcept
Opens an existing data store with the read only mode. Write accesses will cause segmentation fault.
Definition basic_manager.hpp:179
static version_type get_version(const path_type &path) noexcept
Gets the version of the Metall that created the backing data store.
Definition basic_manager.hpp:1171
size_type get_instance_length(const T *ptr) const noexcept
Returns the length of an object created with construct/find_or_construct functions (1 if is a single ...
Definition basic_manager.hpp:603
metall::mtlldetail::named_proxy< manager_kernel_type, T, false > construct_proxy
Construct proxy.
Definition basic_manager.hpp:108
bool destroy_ptr(const T *ptr)
Destroys a object (named, unique, or anonymous) by its address. Calls the destructor and frees the me...
Definition basic_manager.hpp:521
basic_manager()=delete
Deleted.
typename manager_kernel_type::char_type char_type
Char type.
Definition basic_manager.hpp:55
stl_allocator< T, manager_kernel_type > allocator_type
Allocator type.
Definition basic_manager.hpp:65
construct_iter_proxy< T > construct_it(char_ptr_holder_type name)
Allocates an array of objects of type T, receiving arguments from iterators.
Definition basic_manager.hpp:371
bool set_description(const std::string &description) noexcept
Sets a description to a Metall data store. An existing description is overwritten (only one descripti...
Definition basic_manager.hpp:1192
basic_manager(open_only_t, const path_type &base_path) noexcept
Opens an existing data store.
Definition basic_manager.hpp:165
typename manager_kernel_type::instance_kind instance_kind
An value that describes the type of the instance constructed in memory.
Definition basic_manager.hpp:117
bool is_instance_type(const void *const ptr) const noexcept
Checks if the type of an object, which was created with construct/find_or_construct functions,...
Definition basic_manager.hpp:630
typename manager_kernel_type::anonymous_object_attr_accessor_type anonymous_object_attribute_accessor_type
Provides access to anonymous object attribute.
Definition basic_manager.hpp:141
static named_object_attribute_accessor_type access_named_object_attribute(const path_type &path) noexcept
Returns an instance that provides access to the attribute of named objects.
Definition basic_manager.hpp:1274
basic_manager(create_only_t, const path_type &base_path) noexcept
Creates a new data store (an existing data store will be overwritten).
Definition basic_manager.hpp:192
chunk_no_type chunk_number_type
Chunk number type (= chunk_no_type)
Definition basic_manager.hpp:144
static constexpr size_type chunk_size() noexcept
Returns the internal chunk size.
Definition basic_manager.hpp:1344
bool get_instance_description(const T *ptr, std::string *description) const noexcept
Gets the description of an object created with construct/find_or_construct.
Definition basic_manager.hpp:659
kernel::manager_kernel< storage, segment_storage, chunk_no_type, k_chunk_size > manager_kernel_type
Manager kernel type.
Definition basic_manager.hpp:49
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
Copies data store asynchronously. The behavior of copying a data store that is open without the read-...
Definition basic_manager.hpp:1048
~basic_manager() noexcept=default
Destructor.
const_unique_iterator unique_end() const noexcept
Returns a constant iterator to the end of the index storing the unique allocations.
Definition basic_manager.hpp:826
void flush(const bool synchronous=true) noexcept
Flush data to persistent memory.
Definition basic_manager.hpp:972
instance_kind get_instance_kind(const T *ptr) const noexcept
Returns the kind of an object created with construct/find_or_construct functions.
Definition basic_manager.hpp:574
size_type get_num_anonymous_objects() const noexcept
Returns Returns the number of anonymous objects (objects constructed with metall::anonymous_instance)...
Definition basic_manager.hpp:751
typename manager_kernel_type::const_unique_iterator const_unique_iterator
Const iterator for unique objects.
Definition basic_manager.hpp:125
bool check_sanity() const noexcept
Checks the sanity.
Definition basic_manager.hpp:1405
typename manager_kernel_type::const_named_iterator const_named_iterator
Const iterator for named objects.
Definition basic_manager.hpp:121
version_type get_version() const noexcept
Gets the version of the Metall that created the backing data store.
Definition basic_manager.hpp:1153
static bool set_description(const path_type &path, const std::string &description) noexcept
Sets a description to a Metall data store. An existing description is overwritten (only one descripti...
Definition basic_manager.hpp:1214
const void * get_address() const noexcept
Returns the address of the application data segment.
Definition basic_manager.hpp:1350
static bool consistent(const path_type &path) noexcept
Check if a data store exists and is consistent (i.e., it was closed properly in the previous run).
Definition basic_manager.hpp:1107
typename manager_kernel_type::difference_type difference_type
Difference type.
Definition basic_manager.hpp:61
bool destroy(const metall::mtlldetail::unique_instance_t *const)
Destroys a unique object of type T. Calls the destructor and frees the memory.
Definition basic_manager.hpp:486
static bool get_description(const path_type &path, std::string *description) noexcept
Gets a description. If there is no description, nothing to happen to the given description object.
Definition basic_manager.hpp:1256
typename manager_kernel_type::size_type size_type
Size type.
Definition basic_manager.hpp:58
container::scoped_allocator_adaptor< allocator_type< OuterT >, allocator_type< InnerT >... > scoped_allocator_type
Allocator type wrapped by scoped_allocator_adaptor.
Definition basic_manager.hpp:71
bool set_instance_description(const T *ptr, const std::string &description) noexcept
Sets a description to an object created with construct/find_or_construct.
Definition basic_manager.hpp:689
bool all_memory_deallocated() const noexcept
Check if all allocated memory has been deallocated.
Definition basic_manager.hpp:952
size_type get_num_named_objects() const noexcept
Returns Returns the number of named objects stored in the managed segment.
Definition basic_manager.hpp:713
typename manager_kernel_type::const_anonymous_iterator const_anonymous_iterator
Const iterator for anonymous objects.
Definition basic_manager.hpp:129
const char_type * get_instance_name(const T *ptr) const noexcept
Returns the name of an object created with construct/find_or_construct functions.
Definition basic_manager.hpp:546
bool snapshot(const path_type &destination_path, const bool clone=true, const int num_max_copy_threads=0) noexcept
Takes a snapshot of the current data. The snapshot has a new UUID.
Definition basic_manager.hpp:994
static std::string get_uuid(const path_type &path) noexcept
Returns a UUID of the data store.
Definition basic_manager.hpp:1139
bool get_description(std::string *description) const noexcept
Gets a description. If there is no description, nothing to happen to the given description object.
Definition basic_manager.hpp:1234
size_type get_size() const noexcept
Returns the size (i.e., the maximum total allocation size) of the application data segment....
Definition basic_manager.hpp:1369
const_unique_iterator unique_begin() const noexcept
Returns a constant iterator to the index storing the unique objects.
Definition basic_manager.hpp:807
static unique_object_attribute_accessor_type access_unique_object_attribute(const path_type &path) noexcept
Returns an instance that provides access to the attribute of unique object.
Definition basic_manager.hpp:1291
const_anonymous_iterator anonymous_end() const noexcept
Returns a constant iterator to the end of the index storing the anonymous allocations.
Definition basic_manager.hpp:863
container::fallback_allocator_adaptor< allocator_type< T > > fallback_allocator
A STL compatible allocator which fallbacks to a heap allocator (e.g., malloc()) if no argument is pro...
Definition basic_manager.hpp:98
allocator_type< T > get_allocator() const noexcept
Returns a STL compatible allocator object.
Definition basic_manager.hpp:1326
void deallocate(void *addr) noexcept
Deallocates the allocated memory.
Definition basic_manager.hpp:930
construct_iter_proxy< T > find_or_construct_it(char_ptr_holder_type name)
Tries to find an already constructed object. If not exist, constructs an array of objects of type T,...
Definition basic_manager.hpp:398
static bool remove(const path_type &path) noexcept
Removes data store synchronously.
Definition basic_manager.hpp:1068
const_named_iterator named_begin() const noexcept
Returns a constant iterator to the index storing the named objects.
Definition basic_manager.hpp:769
metall::mtlldetail::named_proxy< manager_kernel_type, T, true > construct_iter_proxy
Construct iterator proxy.
Definition basic_manager.hpp:113
std::string get_uuid() const noexcept
Returns a UUID of the data store.
Definition basic_manager.hpp:1121
container::scoped_allocator_adaptor< fallback_allocator< T > > scoped_fallback_allocator_type
Fallback allocator type wrapped by scoped_allocator_adaptor.
Definition basic_manager.hpp:103
const_named_iterator named_end() const noexcept
Returns a constant iterator to the end of the index storing the named allocations.
Definition basic_manager.hpp:788
bool destroy(const char *name)
Destroys a previously created object. Calls the destructor and frees the memory.
Definition basic_manager.hpp:456
typename manager_kernel_type::named_object_attr_accessor_type named_object_attribute_accessor_type
Provides access to named object attribute.
Definition basic_manager.hpp:133
void * allocate(size_type nbytes) noexcept
Allocates nbytes bytes.
Definition basic_manager.hpp:886
void * allocate_aligned(size_type nbytes, size_type alignment) noexcept
Allocates nbytes bytes. The address of the allocated memory will be a multiple of alignment.
Definition basic_manager.hpp:909
construct_proxy< T > find_or_construct(char_ptr_holder_type name)
Tries to find an already constructed object. If not exist, constructs an object of type T.
Definition basic_manager.hpp:345
size_type get_num_unique_objects() const noexcept
Returns Returns the number of unique objects stored in the managed segment.
Definition basic_manager.hpp:732
static void out(const level lvl, const char *const file_name, const int line_no, const char *const message) noexcept
Log a message.
Definition logger.hpp:35
@ error
Error logger message.
A STL compatible allocator.
Definition stl_allocator.hpp:34
boost::container::vector< T, Allocator > vector
A vector container that uses Metall as its default allocator.
Definition vector.hpp:17
The top level of namespace of Metall.
Definition basic_manager.hpp:22
uint32_t version_type
Variable type to handle a version data.
Definition version.hpp:21
Tag type to create the segment always. The existing segment with the same name is over written.
Definition tags.hpp:15
Tag type to open an already created segment.
Definition tags.hpp:22
Tag type to open an already created segment as read only.
Definition tags.hpp:28