6 #ifndef METALL_BASIC_MANAGER_HPP
7 #define METALL_BASIC_MANAGER_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>
24 #if !defined(DOXYGEN_SKIP)
26 template <
typename storage,
typename segment_storage,
typename chunk_no_type,
27 std::size_t k_chunk_size>
36 template <
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)>
48 kernel::manager_kernel<storage, segment_storage, chunk_no_type,
55 using char_type =
typename manager_kernel_type::char_type;
58 using size_type =
typename manager_kernel_type::size_type;
68 template <
typename OuterT,
typename... InnerT>
101 template <
typename T>
106 template <
typename T>
108 metall::mtlldetail::named_proxy<manager_kernel_type, T, false>;
111 template <
typename T>
113 metall::mtlldetail::named_proxy<manager_kernel_type, T, true>;
121 typename manager_kernel_type::const_named_iterator;
125 typename manager_kernel_type::const_unique_iterator;
129 typename manager_kernel_type::const_anonymous_iterator;
133 typename manager_kernel_type::named_object_attr_accessor_type;
137 typename manager_kernel_type::unique_object_attr_accessor_type;
141 typename manager_kernel_type::anonymous_object_attr_accessor_type;
147 using path_type =
typename manager_kernel_type::path_type;
153 using char_ptr_holder_type =
154 typename manager_kernel_type::char_ptr_holder_type;
167 m_kernel = std::make_unique<manager_kernel_type>();
168 m_kernel->open(base_path);
170 m_kernel.reset(
nullptr);
172 "An exception has been thrown");
181 m_kernel = std::make_unique<manager_kernel_type>();
182 m_kernel->open_read_only(base_path);
184 m_kernel.reset(
nullptr);
186 "An exception has been thrown");
194 m_kernel = std::make_unique<manager_kernel_type>();
195 m_kernel->create(base_path);
197 m_kernel.reset(
nullptr);
199 "An exception has been thrown");
213 m_kernel = std::make_unique<manager_kernel_type>();
214 m_kernel->create(base_path, capacity);
216 m_kernel.reset(
nullptr);
218 "An exception has been thrown");
315 template <typename T>
344 template <
typename T>
370 template <
typename T>
397 template <
typename T>
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);
423 return m_kernel->template find<T>(name);
426 "An exception has been thrown");
429 return std::make_pair(
nullptr, 0);
455 template <
typename T>
457 if (!check_sanity()) {
460 return m_kernel->template destroy<T>(name);
485 template <
typename T>
486 bool destroy(
const metall::mtlldetail::unique_instance_t *
const) {
487 if (!check_sanity()) {
490 return m_kernel->template destroy<T>(metall::unique_instance);
522 if (!check_sanity()) {
525 return m_kernel->template destroy_ptr<T>(ptr);
547 if (!check_sanity()) {
551 return m_kernel->get_instance_name(ptr);
554 "An exception has been thrown");
575 if (!check_sanity()) {
579 return m_kernel->get_instance_kind(ptr);
582 "An exception has been thrown");
604 if (!check_sanity()) {
608 return m_kernel->get_instance_length(ptr);
611 "An exception has been thrown");
631 if (!check_sanity()) {
635 return m_kernel->template is_instance_type<T>(ptr);
638 "An exception has been thrown");
661 if (!check_sanity()) {
665 return m_kernel->get_instance_description(ptr, description);
668 "An exception has been thrown");
691 if (!check_sanity()) {
695 return m_kernel->set_instance_description(ptr, description);
697 m_kernel.reset(
nullptr);
699 "An exception has been thrown");
714 if (!check_sanity()) {
718 return m_kernel->get_num_named_objects();
721 "An exception has been thrown");
733 if (!check_sanity()) {
737 return m_kernel->get_num_unique_objects();
740 "An exception has been thrown");
752 if (!check_sanity()) {
756 return m_kernel->get_num_anonymous_objects();
759 "An exception has been thrown");
770 if (!check_sanity()) {
774 return m_kernel->named_begin();
777 "An exception has been thrown");
789 if (!check_sanity()) {
793 return m_kernel->named_end();
796 "An exception has been thrown");
808 if (!check_sanity()) {
812 return m_kernel->unique_begin();
815 "An exception has been thrown");
827 if (!check_sanity()) {
831 return m_kernel->unique_end();
834 "An exception has been thrown");
846 if (!check_sanity()) {
850 return m_kernel->anonymous_begin();
853 "An exception has been thrown");
864 if (!check_sanity()) {
868 return m_kernel->anonymous_end();
871 "An exception has been thrown");
887 if (!check_sanity()) {
891 return m_kernel->allocate(nbytes);
893 m_kernel.reset(
nullptr);
895 "An exception has been thrown");
910 if (!check_sanity()) {
914 return m_kernel->allocate_aligned(nbytes, alignment);
916 m_kernel.reset(
nullptr);
918 "An exception has been thrown");
931 if (!check_sanity()) {
935 return m_kernel->deallocate(addr);
937 m_kernel.reset(
nullptr);
939 "An exception has been thrown");
953 if (!check_sanity()) {
958 return m_kernel->all_memory_deallocated();
961 "An exception has been thrown");
972 void flush(
const bool synchronous =
true) noexcept {
973 if (!check_sanity()) {
977 m_kernel->flush(synchronous);
979 m_kernel.reset(
nullptr);
981 "An exception has been thrown");
995 const int num_max_copy_threads = 0) noexcept {
996 if (!check_sanity()) {
1000 return m_kernel->snapshot(destination_path, clone, num_max_copy_threads);
1002 m_kernel.reset(
nullptr);
1004 "An exception has been thrown");
1022 const path_type &destination_path,
const bool clone =
true,
1023 const int num_max_copy_threads = 0) noexcept {
1025 return manager_kernel_type::copy(source_path, destination_path, clone,
1026 num_max_copy_threads);
1029 "An exception has been thrown");
1050 const bool clone =
true,
1051 const int num_max_copy_threads = 0) noexcept {
1053 return manager_kernel_type::copy_async(source_path, destination_path,
1054 clone, num_max_copy_threads);
1057 "An exception has been thrown");
1059 return std::future<bool>();
1073 "An exception has been thrown");
1087 return std::async(std::launch::async,
remove, path);
1090 "An exception has been thrown");
1092 return std::future<bool>();
1109 return manager_kernel_type::consistent(path);
1112 "An exception has been thrown");
1122 if (!check_sanity()) {
1126 return m_kernel->get_uuid();
1129 "An exception has been thrown");
1141 return manager_kernel_type::get_uuid(path);
1144 "An exception has been thrown");
1154 if (!check_sanity()) {
1158 return m_kernel->get_version();
1161 "An exception has been thrown");
1173 return manager_kernel_type::get_version(path);
1176 "An exception has been thrown");
1193 if (!check_sanity()) {
1197 return m_kernel->set_description(description);
1199 m_kernel.reset(
nullptr);
1201 "An exception has been thrown");
1217 return manager_kernel_type::set_description(path, description);
1220 "An exception has been thrown");
1235 if (!check_sanity()) {
1239 return m_kernel->get_description(description);
1242 "An exception has been thrown");
1259 return manager_kernel_type::get_description(path, description);
1262 "An exception has been thrown");
1277 return manager_kernel_type::access_named_object_attribute(path);
1280 "An exception has been thrown");
1294 return manager_kernel_type::access_unique_object_attribute(path);
1297 "An exception has been thrown");
1308 static anonymous_object_attribute_accessor_type
1311 return manager_kernel_type::access_anonymous_object_attribute(path);
1314 "An exception has been thrown");
1325 template <
typename T = std::
byte>
1327 if (!check_sanity()) {
1332 &(m_kernel->get_segment_header().manager_kernel_address)));
1335 "An exception has been thrown");
1351 if (!check_sanity()) {
1355 return m_kernel->get_segment();
1358 "An exception has been thrown");
1370 if (!check_sanity()) {
1374 return m_kernel->get_segment_size();
1377 "An exception has been thrown");
1387 if (!check_sanity()) {
1391 return m_kernel->read_only();
1394 "An exception has been thrown");
1405 bool check_sanity() const noexcept {
return !!m_kernel && m_kernel->good(); }
1408 #if !defined(DOXYGEN_SKIP)
1412 template <
typename out_stream_type>
1413 void profile(out_stream_type *log_out) noexcept {
1414 if (!check_sanity()) {
1418 m_kernel->profile(log_out);
1420 m_kernel.reset(
nullptr);
1422 "An exception has been thrown");
1431 std::unique_ptr<manager_kernel_type> m_kernel{
nullptr};