Derecho  0.9
Distributed systems toolkit for RDMA
persistence_manager.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <atomic>
9 #include <chrono>
10 #include <errno.h>
11 #include <queue>
12 #include <semaphore.h>
13 #include <thread>
14 
15 #include "../replicated.hpp"
16 #include "derecho_internal.hpp"
17 #include "view_manager.hpp"
19 #include <derecho/utils/logger.hpp>
20 
21 namespace derecho {
22 
23 using persistence_request_t = std::tuple<subgroup_id_t, persistent::version_t>;
24 
29 private:
31  std::thread persist_thread;
33  std::atomic<bool> thread_shutdown;
37  std::queue<persistence_request_t> persistence_request_queue;
39  std::atomic_flag prq_lock = ATOMIC_FLAG_INIT;
40 
44  std::map<subgroup_id_t, std::reference_wrapper<ReplicatedObject>>& objects_by_subgroup_id;
47 
48 public:
53  std::map<subgroup_id_t, std::reference_wrapper<ReplicatedObject>>& objects_map,
54  const persistence_callback_t& _persistence_callback);
55 
56 
59  virtual ~PersistenceManager();
60 
61  void set_view_manager(ViewManager& view_manager);
62 
64  void start();
65 
67  void post_persist_request(const subgroup_id_t& subgroup_id, const persistent::version_t& version);
68 
70  void make_version(const subgroup_id_t& subgroup_id,
71  const persistent::version_t& version, const HLC& mhlc);
72 
76  void shutdown(bool wait);
77 
82 };
83 } // namespace derecho
uint32_t subgroup_id_t
Type alias for the internal Subgroup IDs generated by ViewManager.
std::atomic< bool > thread_shutdown
A flag to singal the persistent thread to shutdown; set to true when the group is destroyed...
std::tuple< subgroup_id_t, persistent::version_t > persistence_request_t
PersistenceManager(std::map< subgroup_id_t, std::reference_wrapper< ReplicatedObject >> &objects_map, const persistence_callback_t &_persistence_callback)
Constructor.
void shutdown(bool wait)
shutdown the thread - wait till the thread finished or not.
std::queue< persistence_request_t > persistence_request_queue
a queue for the requests
persistence_manager_callbacks_t get_callbacks()
get the persistence callbacks.
void post_persist_request(const subgroup_id_t &subgroup_id, const persistent::version_t &version)
post a persistence request
virtual ~PersistenceManager()
default Destructor
void start()
Start the persistent thread.
void make_version(const subgroup_id_t &subgroup_id, const persistent::version_t &version, const HLC &mhlc)
make a version
void set_view_manager(ViewManager &view_manager)
PersistenceManager is responsible for persisting all the data in a group.
std::function< void(subgroup_id_t, persistent::version_t)> persistence_callback_t
std::map< subgroup_id_t, std::reference_wrapper< ReplicatedObject > > & objects_by_subgroup_id
Replicated Objects handle: TODO:make it safer.
ViewManager * view_manager
View Manager pointer.
Definition: HLC.hpp:7
sem_t persistence_request_sem
The semaphore for persistence request the persistent thread.
persistence_callback_t persistence_callback
persistence callback
std::atomic_flag prq_lock
lock for persistence request queue
std::tuple< persistence_manager_make_version_func_t, persistence_manager_post_persist_func_t > persistence_manager_callbacks_t
std::thread persist_thread
Thread handle.