Atlas Runtime
durability_graph.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 DURABILITY_GRAPH_HPP
18 #define DURABILITY_GRAPH_HPP
19 
20 #include <utility>
21 
22 #include <boost/graph/graph_traits.hpp>
23 #include <boost/graph/adjacency_list.hpp>
24 #include <boost/graph/graphviz.hpp>
25 
26 #include "helper.hpp"
27 #include "fase.hpp"
28 
29 namespace Atlas {
30 
31 // This is the durability graph built for consistency management of
32 // persistent data. A node denotes a failure-atomic section of code
33 // (FASE). An edge denotes a happens-after relationship. So if there
34 // is an edge from src to dest, src "happens-after" dest.
35 class DGraph {
36 
37 public:
38 
39  // Vertex properties. A vertex, corresponding to a FASE, is stable
40  // and is included in a consistent state if all FASEs that happen
41  // before it are also stable and are included in the consistent
42  // state.
43  struct VProp {
44  VProp(FASection *fase, bool is_stable)
45  : Fase_(fase), isStable_(is_stable) {}
46  VProp() = delete;
47 
49  bool isStable_;
50  };
51 
52  typedef boost::adjacency_list<
53  boost::setS /* OutEdges: not allowing multi-graph */,
54  boost::listS /* Vertices: don't tolerate renumbered vertex indices */,
55  boost::bidirectionalS /* required for durability graph */,
57 
58  typedef boost::graph_traits<DirectedGraph>::vertex_descriptor VDesc;
59  typedef boost::graph_traits<DirectedGraph>::edge_descriptor EDesc;
60  typedef boost::graph_traits<DirectedGraph>::vertex_iterator VIter;
61  typedef boost::graph_traits<DirectedGraph>::in_edge_iterator IEIter;
62 
63  // Status of a node in a given consistent state
65 
66  struct NodeInfo {
67  NodeInfo(VDesc nid, NodeType node_type)
68  : NodeId_(nid), NodeType_(node_type) {}
69  NodeInfo() = delete;
70 
71  VDesc NodeId_;
73  };
74 
75  typedef std::map<LogEntry*, NodeInfo> NodeInfoMap;
76 
77  boost::graph_traits<DirectedGraph>::vertices_size_type
79  { return boost::num_vertices(DirectedGraph_); }
80 
81  void set_is_stable(VDesc vertex, bool b)
82  { DirectedGraph_[vertex].isStable_ = b; }
83  bool is_stable(VDesc vertex) const
84  { return DirectedGraph_[vertex].isStable_; }
85 
86  void addToNodeInfoMap(LogEntry *le, VDesc nid, NodeType nt);
88 
89  VDesc createNode(FASection *fase);
90  EDesc createEdge(VDesc src, VDesc tgt);
91 
92  const DirectedGraph& get_directed_graph() const
93  { return DirectedGraph_; }
94 
95  void clear_vertex(VDesc vertex)
96  { boost::clear_vertex(vertex, DirectedGraph_); }
97  void remove_vertex(VDesc vertex)
98  { boost::remove_vertex(vertex, DirectedGraph_); }
99 
100  FASection *get_fase(VDesc vertex) const
101  { return DirectedGraph_[vertex].Fase_; }
102 
103  void trace();
104  template<class T> void traceHelper(T tt)
105  { Helper::getInstance().trace(tt); }
106 
107 private:
108 
109  DirectedGraph DirectedGraph_;
110  NodeInfoMap NodeInfoMap_;
111 
112  void PrintLogs(FASection *fase);
113  void PrintDummyLog(LogEntry *le);
114  void PrintAcqLog(LogEntry *le);
115  void PrintRdLockLog(LogEntry *le);
116  void PrintWrLockLog(LogEntry *le);
117  void PrintBeginDurableLog(LogEntry *le);
118  void PrintRelLog(LogEntry *le);
119  void PrintRWUnlockLog(LogEntry *le);
120  void PrintEndDurableLog(LogEntry *le);
121  void PrintStrLog(LogEntry *le);
122  void PrintMemOpLog(LogEntry *le);
123  void PrintStrOpLog(LogEntry *le);
124  void PrintAllocLog(LogEntry *le);
125  void PrintFreeLog(LogEntry *le);
126 };
127 
129 {
130  // default attribute is stable. If any contained log entry is
131  // unresolved, the stable bit is flipped and the corresponding node
132  // removed from the graph
133  return boost::add_vertex(VProp(fase, true /* stable */),
134  DirectedGraph_);
135 }
136 
138 {
139  // TODO: are we creating a multi-graph? Or does add_edge filter
140  // that out?
141  std::pair<EDesc, bool> edge_pair =
142  boost::add_edge(src, tgt, DirectedGraph_);
143  return edge_pair.first;
144 }
145 
146 } // end namespace
147 
148 #endif
bool is_stable(VDesc vertex) const
Definition: durability_graph.hpp:83
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
std::map< LogEntry *, NodeInfo > NodeInfoMap
Definition: durability_graph.hpp:75
boost::graph_traits< DirectedGraph >::vertices_size_type get_num_vertices() const
Definition: durability_graph.hpp:78
FASection * Fase_
Definition: durability_graph.hpp:48
const DirectedGraph & get_directed_graph() const
Definition: durability_graph.hpp:92
Definition: log_structure.hpp:30
bool isStable_
Definition: durability_graph.hpp:49
boost::graph_traits< DirectedGraph >::in_edge_iterator IEIter
Definition: durability_graph.hpp:61
Definition: durability_graph.hpp:66
void remove_vertex(VDesc vertex)
Definition: durability_graph.hpp:97
static Helper & getInstance()
Definition: helper.hpp:66
void trace(T s)
Definition: helper.hpp:78
Definition: fase.hpp:25
Definition: durability_graph.hpp:64
VDesc createNode(FASection *fase)
Definition: durability_graph.hpp:128
EDesc createEdge(VDesc src, VDesc tgt)
Definition: durability_graph.hpp:137
boost::graph_traits< DirectedGraph >::edge_descriptor EDesc
Definition: durability_graph.hpp:59
boost::graph_traits< DirectedGraph >::vertex_iterator VIter
Definition: durability_graph.hpp:60
NodeInfo(VDesc nid, NodeType node_type)
Definition: durability_graph.hpp:67
Definition: durability_graph.hpp:43
void traceHelper(T tt)
Definition: durability_graph.hpp:104
VDesc NodeId_
Definition: durability_graph.hpp:71
NodeType
Definition: durability_graph.hpp:64
NodeInfo getTargetNodeInfo(LogEntry *tgt_le)
Definition: durability_graph_builder.cpp:195
Definition: durability_graph.hpp:64
boost::adjacency_list< boost::setS, boost::listS, boost::bidirectionalS, VProp > DirectedGraph
Definition: durability_graph.hpp:56
void trace()
Definition: durability_graph_builder.cpp:215
NodeType NodeType_
Definition: durability_graph.hpp:72
Definition: atlas_alloc_cpp.hpp:21
void addToNodeInfoMap(LogEntry *le, VDesc nid, NodeType nt)
Definition: durability_graph_builder.cpp:206
FASection * get_fase(VDesc vertex) const
Definition: durability_graph.hpp:100
VProp(FASection *fase, bool is_stable)
Definition: durability_graph.hpp:44
void clear_vertex(VDesc vertex)
Definition: durability_graph.hpp:95
Definition: durability_graph.hpp:35