Metall  v0.28
A persistent memory allocator for data-centric analytics
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>
13 #include <metall/stl_allocator.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 
22 namespace metall {
23 
24 #if !defined(DOXYGEN_SKIP)
25 // Forward declaration
26 template <typename storage, typename segment_storage, typename chunk_no_type,
27  std::size_t k_chunk_size>
28 class basic_manager;
29 #endif // DOXYGEN_SKIP
30 
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)>
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. However, a close minimum capacity should be
209  // available.
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>
398  construct_iter_proxy<T> find_or_construct_it(char_ptr_holder_type name) {
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 
713  size_type get_num_named_objects() const noexcept {
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 
788  const_named_iterator named_end() const noexcept {
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()) {
847  return const_anonymous_iterator();
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  }
855  return const_anonymous_iterator();
856  }
857 
864  if (!check_sanity()) {
865  return const_anonymous_iterator();
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  }
873  return const_anonymous_iterator();
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 
908  void *allocate_aligned(size_type nbytes, size_type alignment) noexcept {
909  if (!check_sanity()) {
910  return nullptr;
911  }
912  try {
913  return m_kernel->allocate_aligned(nbytes, alignment);
914  } catch (...) {
915  m_kernel.reset(nullptr);
916  logger::out(logger::level::error, __FILE__, __LINE__,
917  "An exception has been thrown");
918  }
919  return nullptr;
920  }
921 
922  // void allocate_many(const std::nothrow_t &tag, size_type elem_bytes,
923  // size_type n_elements, multiallocation_chain &chain);
924 
929  void deallocate(void *addr) noexcept {
930  if (!check_sanity()) {
931  return;
932  }
933  try {
934  return m_kernel->deallocate(addr);
935  } catch (...) {
936  m_kernel.reset(nullptr);
937  logger::out(logger::level::error, __FILE__, __LINE__,
938  "An exception has been thrown");
939  }
940  }
941 
942  // void deallocate_many(multiallocation_chain &chain);
943 
951  bool all_memory_deallocated() const noexcept {
952  if (!check_sanity()) {
953  return false;
954  }
955 
956  try {
957  return m_kernel->all_memory_deallocated();
958  } catch (...) {
959  logger::out(logger::level::error, __FILE__, __LINE__,
960  "An exception has been thrown");
961  }
962  return false;
963  }
964 
965  // ---------- Flush ---------- //
971  void flush(const bool synchronous = true) noexcept {
972  if (!check_sanity()) {
973  return;
974  }
975  try {
976  m_kernel->flush(synchronous);
977  } catch (...) {
978  m_kernel.reset(nullptr);
979  logger::out(logger::level::error, __FILE__, __LINE__,
980  "An exception has been thrown");
981  }
982  }
983 
984  // -------- Snapshot, copy, data store management -------- //
993  bool snapshot(const path_type &destination_path, const bool clone = true,
994  const int num_max_copy_threads = 0) noexcept {
995  if (!check_sanity()) {
996  return false;
997  }
998  try {
999  return m_kernel->snapshot(destination_path, clone, num_max_copy_threads);
1000  } catch (...) {
1001  m_kernel.reset(nullptr);
1002  logger::out(logger::level::error, __FILE__, __LINE__,
1003  "An exception has been thrown");
1004  }
1005  return false;
1006  }
1007 
1020  static bool copy(const path_type &source_path,
1021  const path_type &destination_path, const bool clone = true,
1022  const int num_max_copy_threads = 0) noexcept {
1023  try {
1024  return manager_kernel_type::copy(source_path, destination_path, clone,
1025  num_max_copy_threads);
1026  } catch (...) {
1027  logger::out(logger::level::error, __FILE__, __LINE__,
1028  "An exception has been thrown");
1029  }
1030  return false;
1031  }
1032 
1047  static auto copy_async(const path_type source_path,
1048  const path_type destination_path,
1049  const bool clone = true,
1050  const int num_max_copy_threads = 0) noexcept {
1051  try {
1052  return manager_kernel_type::copy_async(source_path, destination_path,
1053  clone, num_max_copy_threads);
1054  } catch (...) {
1055  logger::out(logger::level::error, __FILE__, __LINE__,
1056  "An exception has been thrown");
1057  }
1058  return std::future<bool>();
1059  }
1060 
1067  static bool remove(const path_type &path) noexcept {
1068  try {
1069  return manager_kernel_type::remove(path);
1070  } catch (...) {
1071  logger::out(logger::level::error, __FILE__, __LINE__,
1072  "An exception has been thrown");
1073  }
1074  return false;
1075  }
1076 
1084  static std::future<bool> remove_async(const path_type &path) noexcept {
1085  try {
1086  return std::async(std::launch::async, remove, path);
1087  } catch (...) {
1088  logger::out(logger::level::error, __FILE__, __LINE__,
1089  "An exception has been thrown");
1090  }
1091  return std::future<bool>();
1092  }
1093 
1106  static bool consistent(const path_type &path) noexcept {
1107  try {
1108  return manager_kernel_type::consistent(path);
1109  } catch (...) {
1110  logger::out(logger::level::error, __FILE__, __LINE__,
1111  "An exception has been thrown");
1112  }
1113  return false;
1114  }
1115 
1120  std::string get_uuid() const noexcept {
1121  if (!check_sanity()) {
1122  return std::string();
1123  }
1124  try {
1125  return m_kernel->get_uuid();
1126  } catch (...) {
1127  logger::out(logger::level::error, __FILE__, __LINE__,
1128  "An exception has been thrown");
1129  }
1130  return std::string();
1131  }
1132 
1138  static std::string get_uuid(const path_type &path) noexcept {
1139  try {
1140  return manager_kernel_type::get_uuid(path);
1141  } catch (...) {
1142  logger::out(logger::level::error, __FILE__, __LINE__,
1143  "An exception has been thrown");
1144  }
1145  return std::string();
1146  }
1147 
1152  version_type get_version() const noexcept {
1153  if (!check_sanity()) {
1154  return version_type();
1155  }
1156  try {
1157  return m_kernel->get_version();
1158  } catch (...) {
1159  logger::out(logger::level::error, __FILE__, __LINE__,
1160  "An exception has been thrown");
1161  }
1162  return version_type();
1163  }
1164 
1170  static version_type get_version(const path_type &path) noexcept {
1171  try {
1172  return manager_kernel_type::get_version(path);
1173  } catch (...) {
1174  logger::out(logger::level::error, __FILE__, __LINE__,
1175  "An exception has been thrown");
1176  return version_type();
1177  }
1178  }
1179 
1180  // ---------- Data store description ---------- //
1181 
1191  bool set_description(const std::string &description) noexcept {
1192  if (!check_sanity()) {
1193  return false;
1194  }
1195  try {
1196  return m_kernel->set_description(description);
1197  } catch (...) {
1198  m_kernel.reset(nullptr);
1199  logger::out(logger::level::error, __FILE__, __LINE__,
1200  "An exception has been thrown");
1201  }
1202  return false;
1203  }
1204 
1213  static bool set_description(const path_type &path,
1214  const std::string &description) noexcept {
1215  try {
1216  return manager_kernel_type::set_description(path, description);
1217  } catch (...) {
1218  logger::out(logger::level::error, __FILE__, __LINE__,
1219  "An exception has been thrown");
1220  }
1221  return false;
1222  }
1223 
1233  bool get_description(std::string *description) const noexcept {
1234  if (!check_sanity()) {
1235  return false;
1236  }
1237  try {
1238  return m_kernel->get_description(description);
1239  } catch (...) {
1240  logger::out(logger::level::error, __FILE__, __LINE__,
1241  "An exception has been thrown");
1242  }
1243  return false;
1244  }
1245 
1255  static bool get_description(const path_type &path,
1256  std::string *description) noexcept {
1257  try {
1258  return manager_kernel_type::get_description(path, description);
1259  } catch (...) {
1260  logger::out(logger::level::error, __FILE__, __LINE__,
1261  "An exception has been thrown");
1262  }
1263  return false;
1264  }
1265 
1266  // ---------- Object attribute ---------- //
1274  const path_type &path) noexcept {
1275  try {
1276  return manager_kernel_type::access_named_object_attribute(path);
1277  } catch (...) {
1278  logger::out(logger::level::error, __FILE__, __LINE__,
1279  "An exception has been thrown");
1280  }
1282  }
1283 
1291  const path_type &path) noexcept {
1292  try {
1293  return manager_kernel_type::access_unique_object_attribute(path);
1294  } catch (...) {
1295  logger::out(logger::level::error, __FILE__, __LINE__,
1296  "An exception has been thrown");
1297  }
1299  }
1300 
1307  static anonymous_object_attribute_accessor_type
1309  try {
1310  return manager_kernel_type::access_anonymous_object_attribute(path);
1311  } catch (...) {
1312  logger::out(logger::level::error, __FILE__, __LINE__,
1313  "An exception has been thrown");
1314  }
1316  }
1317 
1318  // ---------- etc ---------- //
1324  template <typename T = std::byte>
1326  if (!check_sanity()) {
1327  return allocator_type<T>(nullptr);
1328  }
1329  try {
1330  return allocator_type<T>(reinterpret_cast<manager_kernel_type *const *>(
1331  &(m_kernel->get_segment_header().manager_kernel_address)));
1332  } catch (...) {
1333  logger::out(logger::level::error, __FILE__, __LINE__,
1334  "An exception has been thrown");
1335  }
1336  return allocator_type<T>(nullptr);
1337  }
1338 
1343  static constexpr size_type chunk_size() noexcept { return k_chunk_size; }
1344 
1349  const void *get_address() const noexcept {
1350  if (!check_sanity()) {
1351  return nullptr;
1352  }
1353  try {
1354  return m_kernel->get_segment();
1355  } catch (...) {
1356  logger::out(logger::level::error, __FILE__, __LINE__,
1357  "An exception has been thrown");
1358  }
1359  return nullptr;
1360  }
1361 
1368  size_type get_size() const noexcept {
1369  if (!check_sanity()) {
1370  return 0;
1371  }
1372  try {
1373  return m_kernel->get_segment_size();
1374  } catch (...) {
1375  logger::out(logger::level::error, __FILE__, __LINE__,
1376  "An exception has been thrown");
1377  }
1378  return 0;
1379  }
1380 
1385  bool read_only() const noexcept {
1386  if (!check_sanity()) {
1387  return true;
1388  }
1389  try {
1390  return m_kernel->read_only();
1391  } catch (...) {
1392  logger::out(logger::level::error, __FILE__, __LINE__,
1393  "An exception has been thrown");
1394  }
1395  return true;
1396  }
1397 
1398  // bool belongs_to_segment (const void *ptr) const
1399 
1404  bool check_sanity() const noexcept { return !!m_kernel && m_kernel->good(); }
1405 
1406  // ---------- For profiling and debug ---------- //
1407 #if !defined(DOXYGEN_SKIP)
1411  template <typename out_stream_type>
1412  void profile(out_stream_type *log_out) noexcept {
1413  if (!check_sanity()) {
1414  return;
1415  }
1416  try {
1417  m_kernel->profile(log_out);
1418  } catch (...) {
1419  m_kernel.reset(nullptr);
1420  logger::out(logger::level::error, __FILE__, __LINE__,
1421  "An exception has been thrown");
1422  }
1423  }
1424 #endif
1425 
1426  private:
1427  // -------------------- //
1428  // Private fields
1429  // -------------------- //
1430  std::unique_ptr<manager_kernel_type> m_kernel{nullptr};
1431 };
1432 } // namespace metall
1433 
1434 #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:1385
const_anonymous_iterator anonymous_begin() const noexcept
Returns a constant iterator to the index storing the anonymous objects.
Definition: basic_manager.hpp:845
void * allocate(size_type nbytes) noexcept
Allocates nbytes bytes.
Definition: basic_manager.hpp:886
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:1308
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:1020
typename manager_kernel_type::void_pointer void_pointer
Void pointer type.
Definition: basic_manager.hpp:52
typename manager_kernel_type::path_type path_type
Path type.
Definition: basic_manager.hpp:147
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
const void * get_address() const noexcept
Returns the address of the application data segment.
Definition: basic_manager.hpp:1349
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:1170
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
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:1191
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
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:1273
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:1343
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
allocator_type< T > get_allocator() const noexcept
Returns a STL compatible allocator object.
Definition: basic_manager.hpp:1325
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:1047
~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:971
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
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
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:1404
typename manager_kernel_type::const_named_iterator const_named_iterator
Const iterator for named objects.
Definition: basic_manager.hpp:121
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
version_type get_version() const noexcept
Gets the version of the Metall that created the backing data store.
Definition: basic_manager.hpp:1152
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:1213
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:1106
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:1255
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
static std::future< bool > remove_async(const path_type &path) noexcept
Remove data store asynchronously.
Definition: basic_manager.hpp:1084
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:951
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
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:993
static std::string get_uuid(const path_type &path) noexcept
Returns a UUID of the data store.
Definition: basic_manager.hpp:1138
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:1233
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:1368
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:1290
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
void deallocate(void *addr) noexcept
Deallocates the allocated memory.
Definition: basic_manager.hpp:929
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
static bool remove(const path_type &path) noexcept
Removes data store synchronously.
Definition: basic_manager.hpp:1067
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:1120
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
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:908
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
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
A STL compatible allocator which fallbacks to a heap allocator (e.g., malloc()) if its constructor re...
Definition: fallback_allocator.hpp:21
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
basic_string< char > string
A string container that uses char as its character type and Metall as its default allocator.
Definition: string.hpp:23
boost::container::scoped_allocator_adaptor< OuterAlloc, InnerAlloc... > scoped_allocator_adaptor
An allocator which can be used with multilevel containers.
Definition: scoped_allocator.hpp:16
bool remove(std::string_view path)
Remove a file or directory.
Definition: filesystem.hpp:16
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