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");
909 if (!check_sanity()) {
913 return m_kernel->allocate_aligned(nbytes, alignment);
915 m_kernel.reset(
nullptr);
917 "An exception has been thrown");
930 if (!check_sanity()) {
934 return m_kernel->deallocate(addr);
936 m_kernel.reset(
nullptr);
938 "An exception has been thrown");
952 if (!check_sanity()) {
957 return m_kernel->all_memory_deallocated();
960 "An exception has been thrown");
971 void flush(
const bool synchronous =
true) noexcept {
972 if (!check_sanity()) {
976 m_kernel->flush(synchronous);
978 m_kernel.reset(
nullptr);
980 "An exception has been thrown");
994 const int num_max_copy_threads = 0) noexcept {
995 if (!check_sanity()) {
999 return m_kernel->snapshot(destination_path, clone, num_max_copy_threads);
1001 m_kernel.reset(
nullptr);
1003 "An exception has been thrown");
1021 const path_type &destination_path,
const bool clone =
true,
1022 const int num_max_copy_threads = 0) noexcept {
1024 return manager_kernel_type::copy(source_path, destination_path, clone,
1025 num_max_copy_threads);
1028 "An exception has been thrown");
1049 const bool clone =
true,
1050 const int num_max_copy_threads = 0) noexcept {
1052 return manager_kernel_type::copy_async(source_path, destination_path,
1053 clone, num_max_copy_threads);
1056 "An exception has been thrown");
1058 return std::future<bool>();
1072 "An exception has been thrown");
1086 return std::async(std::launch::async,
remove, path);
1089 "An exception has been thrown");
1091 return std::future<bool>();
1108 return manager_kernel_type::consistent(path);
1111 "An exception has been thrown");
1121 if (!check_sanity()) {
1125 return m_kernel->get_uuid();
1128 "An exception has been thrown");
1140 return manager_kernel_type::get_uuid(path);
1143 "An exception has been thrown");
1153 if (!check_sanity()) {
1157 return m_kernel->get_version();
1160 "An exception has been thrown");
1172 return manager_kernel_type::get_version(path);
1175 "An exception has been thrown");
1192 if (!check_sanity()) {
1196 return m_kernel->set_description(description);
1198 m_kernel.reset(
nullptr);
1200 "An exception has been thrown");
1216 return manager_kernel_type::set_description(path, description);
1219 "An exception has been thrown");
1234 if (!check_sanity()) {
1238 return m_kernel->get_description(description);
1241 "An exception has been thrown");
1258 return manager_kernel_type::get_description(path, description);
1261 "An exception has been thrown");
1276 return manager_kernel_type::access_named_object_attribute(path);
1279 "An exception has been thrown");
1293 return manager_kernel_type::access_unique_object_attribute(path);
1296 "An exception has been thrown");
1307 static anonymous_object_attribute_accessor_type
1310 return manager_kernel_type::access_anonymous_object_attribute(path);
1313 "An exception has been thrown");
1324 template <
typename T = std::
byte>
1326 if (!check_sanity()) {
1331 &(m_kernel->get_segment_header().manager_kernel_address)));
1334 "An exception has been thrown");
1350 if (!check_sanity()) {
1354 return m_kernel->get_segment();
1357 "An exception has been thrown");
1369 if (!check_sanity()) {
1373 return m_kernel->get_segment_size();
1376 "An exception has been thrown");
1386 if (!check_sanity()) {
1390 return m_kernel->read_only();
1393 "An exception has been thrown");
1404 bool check_sanity() const noexcept {
return !!m_kernel && m_kernel->good(); }
1407 #if !defined(DOXYGEN_SKIP)
1411 template <
typename out_stream_type>
1412 void profile(out_stream_type *log_out) noexcept {
1413 if (!check_sanity()) {
1417 m_kernel->profile(log_out);
1419 m_kernel.reset(
nullptr);
1421 "An exception has been thrown");
1430 std::unique_ptr<manager_kernel_type> m_kernel{
nullptr};