Atlas Runtime
consistency_mgr.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef CONSISTENCY_MGR_HPP
18 #define CONSISTENCY_MGR_HPP
19 
20 #include <cassert>
21 #include <utility>
22 #include <vector>
23 #include <map>
24 #include <string>
25 
26 #include "helper.hpp"
27 #include "log_mgr.hpp"
28 #include "durability_graph.hpp"
29 #include "fase.hpp"
30 
31 namespace Atlas {
32 
33 // This class manages consistency of persistent data. It is either
34 // invoked by the helper thread during program execution or during
35 // recovery after a failure. Currently, there is at most one instance
36 // of this class.
37 class CSMgr {
38  static CSMgr *Instance_;
39 public:
40  typedef std::map<DGraph::VDesc, bool> MapNodes;
41 
42  // serial mode only
43  static CSMgr& createInstance() {
44  assert(!Instance_);
45  Instance_ = new CSMgr();
46  return *Instance_;
47  }
48 
49  // serial mode only
50  static void deleteInstance() {
51  assert(Instance_);
52  delete Instance_;
53  Instance_ = nullptr;
54  }
55 
56  // serial mode only
57  static CSMgr& getInstance() {
58  assert(Instance_);
59  return *Instance_;
60  }
61 
63  Helper::LogVersions*, bool is_in_recovery);
64 
66  { ExistingRelMap_ = m; }
67 
68  boost::graph_traits<DGraph::DirectedGraph>::vertices_size_type
69  get_num_graph_vertices() const { return Graph_.get_num_vertices(); }
70 
71  void set_is_stable(DGraph::VDesc vertex, bool b)
72  { Graph_.set_is_stable(vertex, b); }
73  bool is_stable(DGraph::VDesc vertex) const
74  { return Graph_.is_stable(vertex); }
75 
76 private:
77 
78  typedef std::pair<LogEntry*, DGraph::VDesc> PendingPair;
79  typedef std::vector<PendingPair> PendingList;
80 
81  typedef std::vector<LogStructure*> LSVec;
82  typedef std::vector<Helper::LogVersions::iterator> LogIterVec;
83  typedef std::map<intptr_t*, bool> Addr2Bool;
84  typedef std::map<LogStructure*, FASection*> FaseMap;
85  typedef std::vector<FASection*> FaseVec;
86 
87  bool IsParentDone_; // Is the parent user thread done?
88  bool IsInRecovery_;
89  DGraph Graph_;
90 
91  // A mapping from a release type log entry to its generation
92  // number. This is currently used only during recovery. Populated
93  // once and not changed later on at all.
94  Helper::MapLog2Int *ExistingRelMap_;
95 
96  // A list of acquire type log entries whose targets are not yet found
97  PendingList PendingList_;
98 
99  // Maps a log header to the first FASE in an analysis round
100  FaseMap FirstFaseOfHeader_;
101 
102  // Vector of all FASEs created in an analysis round
103  FaseVec AllFases_;
104 
105  SetOfInts *GlobalFlush_;
106 
107  explicit CSMgr() :
108  IsParentDone_{false},
109  IsInRecovery_{false},
110  Graph_{},
111  ExistingRelMap_{nullptr},
112  PendingList_{},
113  FirstFaseOfHeader_{},
114  AllFases_{},
115 #if defined(_FLUSH_GLOBAL_COMMIT) && !defined(DISABLE_FLUSHES) && \
116  !defined(_DISABLE_DATA_FLUSH)
117  GlobalFlush_{new SetOfInts}
118 #else
119  GlobalFlush_{nullptr}
120 #endif
121  {}
122 
123  ~CSMgr()
124  {
125 #if defined(_FLUSH_GLOBAL_COMMIT) && !defined(DISABLE_FLUSHES) && \
126  !defined(_DISABLE_DATA_FLUSH)
127  if (GlobalFlush_) {
128  delete GlobalFlush_;
129  GlobalFlush_ = nullptr;
130  }
131 #endif
132  }
133  CSMgr(const CSMgr&) = delete;
134  CSMgr(CSMgr&&) = delete;
135  CSMgr& operator=(const CSMgr&) = delete;
136  CSMgr& operator=(CSMgr&&) = delete;
137 
138  bool isFirstFaseFound(LogStructure *ls) const
139  { return FirstFaseOfHeader_.find(ls) != FirstFaseOfHeader_.end(); }
140  void addFirstFase(LogStructure *ls, FASection *fase) {
141  assert(FirstFaseOfHeader_.find(ls) == FirstFaseOfHeader_.end());
142  FirstFaseOfHeader_.insert(std::make_pair(ls, fase));
143  }
144  void addFaseToVec(FASection *fase)
145  { AllFases_.push_back(fase); }
146  void addToPendingList(LogEntry *le, DGraph::VDesc nid) {
147  PendingPair pp = std::make_pair(le, nid);
148  PendingList_.push_back(pp);
149  }
150  FASection *getFirstFase(LogStructure *ls) {
151  FaseMap::const_iterator ci = FirstFaseOfHeader_.find(ls);
152  if (ci != FirstFaseOfHeader_.end()) return ci->second;
153  else return NULL;
154  }
155 
156  void buildInitialGraph(LogStructure *lsp);
157  void addSyncEdges(const MapNodes&, LogEntry*, DGraph::VDesc);
158  bool isFoundInExistingLog(LogEntry *le, uint64_t gen_num) const;
159  void removeUnresolvedNodes();
160  void createVersions(Helper::LogVersions *log_v);
161  void resolvePendingList();
162  void handleUnresolved(DGraph::VDesc nid, MapNodes *rm);
163  void destroyLogs(Helper::LogVersions*);
164  void fixupNewEntries(LogStructure**, const LSVec&);
165  void copyDeletedLogEntries(LogEntryVec*, const LogEntryVec&);
166  void destroyLogEntries(const LogEntryVec&);
167  void destroyLS(LogStructure*);
168  FASection *buildFASection(LogEntry *le);
169  void addLogStructure(LogEntry *le, LogStructure **header,
170  LogStructure **last_header);
171  void collectLogs(Log2Bool *logs, FASection *fase);
172  bool areLogicallySame(LogStructure *gh, LogStructure *cand_gh);
173  uint32_t getNumNewEntries(LogStructure *new_e, LogStructure *old_e);
174  void destroyFASections();
175 
176  void flushGlobalCommit(const LogEntryVec& logs);
177 
178  bool isInRecovery() const { return IsInRecovery_; }
179  bool areUserThreadsDone() const
181  void traceGraph() {
182 #if defined(_NVM_TRACE) || defined(_NVM_VERBOSE_TRACE)
183  Graph_.trace();
184 #endif
185  }
186  template<class T> void traceHelper(T s) {
187 #if defined (_NVM_TRACE) || defined(_NVM_VERBOSE_TRACE)
189 #endif
190  }
191 
192 };
193 
194 } // namespace Atlas
195 
196 #endif
bool is_stable(VDesc vertex) const
Definition: durability_graph.hpp:83
void set_existing_rel_map(Helper::MapLog2Int *m)
Definition: consistency_mgr.hpp:65
void set_is_stable(VDesc vertex, bool b)
Definition: durability_graph.hpp:81
boost::graph_traits< DirectedGraph >::vertex_descriptor VDesc
Definition: durability_graph.hpp:58
Definition: consistency_mgr.hpp:37
boost::graph_traits< DirectedGraph >::vertices_size_type get_num_vertices() const
Definition: durability_graph.hpp:78
Definition: log_structure.hpp:30
std::map< LogEntry *, bool > Log2Bool
Definition: helper.hpp:32
static Helper & getInstance()
Definition: helper.hpp:66
void trace(T s)
Definition: helper.hpp:78
Definition: fase.hpp:25
std::vector< LogVer > LogVersions
Definition: helper.hpp:49
void set_is_stable(DGraph::VDesc vertex, bool b)
Definition: consistency_mgr.hpp:71
boost::graph_traits< DGraph::DirectedGraph >::vertices_size_type get_num_graph_vertices() const
Definition: consistency_mgr.hpp:69
std::map< LogEntry *, uint64_t > MapLog2Int
Definition: helper.hpp:50
bool areUserThreadsDone() const
Definition: log_mgr.hpp:154
static CSMgr & createInstance()
Definition: consistency_mgr.hpp:43
static CSMgr & getInstance()
Definition: consistency_mgr.hpp:57
static LogMgr & getInstance()
Definition: log_mgr.hpp:75
Definition: log_structure.hpp:77
std::set< uint64_t > SetOfInts
Definition: util.hpp:77
void doConsistentUpdate(LogStructure *, Helper::LogVersions *, bool is_in_recovery)
Main entry point for a single round of consistent state gen.
Definition: consistency_mgr.cpp:35
bool is_stable(DGraph::VDesc vertex) const
Definition: consistency_mgr.hpp:73
std::map< DGraph::VDesc, bool > MapNodes
Definition: consistency_mgr.hpp:40
void trace()
Definition: durability_graph_builder.cpp:215
static void deleteInstance()
Definition: consistency_mgr.hpp:50
std::vector< LogEntry * > LogEntryVec
Definition: log_mgr.hpp:45
Definition: atlas_alloc_cpp.hpp:21
Definition: durability_graph.hpp:35