NodeI.h
Go to the documentation of this file.
1// **********************************************************************
2//
3// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
4//
5// This copy of Ice is licensed to you under the terms described in the
6// ICE_LICENSE file included in this distribution.
7//
8// **********************************************************************
9
10#ifndef ELECTION_I_H
11#define ELECTION_I_H
12
13#include <set>
14
15#include <Ice/Ice.h>
16#include <IceStorm/Election.h>
17#include <IceStorm/Instance.h>
18#include <IceStorm/Replica.h>
19#include <IceUtil/IceUtil.h>
20#include <IceUtil/Timer.h>
21
22namespace IceStormElection
23{
24
25 class Observers;
26 typedef IceUtil::Handle<Observers> ObserversPtr;
27
28 class NodeI : public Node, public IceUtil::Monitor<IceUtil::RecMutex>
29 {
30 public:
32 const ReplicaPtr&,
33 const Ice::ObjectPrx&,
34 int,
35 const std::map<int, NodePrx>&);
36
37 void start();
38
39 void check();
40 void timeout();
41 void merge(const std::set<int>&);
42 void mergeContinue();
43 virtual void invitation(int, const std::string&, const Ice::Current&);
44 virtual void
45 ready(int, const std::string&, const Ice::ObjectPrx&, int, Ice::Long, const Ice::Current&);
46 virtual void accept(int,
47 const std::string&,
48 const Ice::IntSeq&,
49 const Ice::ObjectPrx&,
50 const LogUpdate&,
51 int,
52 const Ice::Current&);
53 virtual bool areYouCoordinator(const Ice::Current&) const;
54 virtual bool areYouThere(const std::string&, int, const Ice::Current&) const;
55 virtual Ice::ObjectPrx sync(const Ice::Current&) const;
56 virtual NodeInfoSeq nodes(const Ice::Current&) const;
57 virtual QueryInfo query(const Ice::Current&) const;
58 void recovery(Ice::Long = -1);
59
60 void destroy();
61
62 // Notify the node that we're about to start an update.
63 void checkObserverInit(Ice::Long);
64 Ice::ObjectPrx startUpdate(Ice::Long&, const char*, int);
65 Ice::ObjectPrx startCachedRead(Ice::Long&, const char*, int);
66 void startObserverUpdate(Ice::Long, const char*, int);
67 bool updateMaster(const char*, int);
68
69 // The node has completed the update.
70 void finishUpdate();
71
72 private:
73 void setState(NodeState);
74
75 const IceUtil::TimerPtr _timer;
76 const IceStorm::TraceLevelsPtr _traceLevels;
77 const IceStormElection::ObserversPtr _observers;
78 const ReplicaPtr _replica; // The replica.
79 const Ice::ObjectPrx _replicaProxy; // A proxy to the individual replica.
80
81 const int _id; // My node id.
82 const std::map<int, NodePrx> _nodes; // The nodes indexed by their id.
83 const std::map<int, NodePrx>
84 _nodesOneway; // The nodes indexed by their id (as oneway proxies).
85
86 const IceUtil::Time _masterTimeout;
87 const IceUtil::Time _electionTimeout;
88 const IceUtil::Time _mergeTimeout;
89
90 NodeState _state;
91 int _updateCounter;
92
93 int _coord; // Id of the coordinator.
94 std::string _group; // My group id.
95
96 std::set<GroupNodeInfo> _up; // Set of nodes in my group.
97 std::set<int> _invitesIssued; // The issued invitations.
98 std::set<int> _invitesAccepted; // The accepted invitations.
99
100 unsigned int _max; // The highest group count I've seen.
101 Ice::Long _generation; // The current generation (or -1 if not set).
102
103 Ice::ObjectPrx _coordinatorProxy;
104 bool _destroy;
105
106 // Various timers.
107 IceUtil::TimerTaskPtr _mergeTask;
108 IceUtil::TimerTaskPtr _timeoutTask;
109 IceUtil::TimerTaskPtr _checkTask;
110 IceUtil::TimerTaskPtr _mergeContinueTask;
111 };
112
114
116 {
117 public:
118 FinishUpdateHelper(const NodeIPtr& node) : _node(node)
119 {
120 }
121
123 {
124 if (_node)
125 {
126 _node->finishUpdate();
127 }
128 }
129
130 private:
131 const NodeIPtr _node;
132 };
133
135 {
136 public:
137 CachedReadHelper(const NodeIPtr& node, const char* file, int line) : _node(node)
138 {
139 if (_node)
140 {
141 _master = _node->startCachedRead(_generation, file, line);
142 }
143 }
144
146 {
147 if (_node)
148 {
149 _node->finishUpdate();
150 }
151 }
152
153 Ice::ObjectPrx
154 getMaster() const
155 {
156 return _master;
157 }
158
159 Ice::Long
161 {
162 return _generation;
163 }
164
165 bool
167 {
168 return generation == _generation && _master;
169 }
170
171 private:
172 const NodeIPtr _node;
173 Ice::ObjectPrx _master;
174 Ice::Long _generation;
175 };
176
178 {
179 public:
181 Ice::Long generation,
182 const char* file,
183 int line) :
184 _node(node)
185 {
186 if (_node)
187 {
188 _node->startObserverUpdate(generation, file, line);
189 }
190 }
191
193 {
194 if (_node)
195 {
196 _node->finishUpdate();
197 }
198 }
199
200 private:
201 const NodeIPtr _node;
202 };
203
204} // namespace IceStormElection
205
206#endif // ELECTION_I_H
CachedReadHelper(const NodeIPtr &node, const char *file, int line)
Definition NodeI.h:137
Ice::Long generation() const
Definition NodeI.h:160
Ice::ObjectPrx getMaster() const
Definition NodeI.h:154
bool observerPrecondition(Ice::Long generation) const
Definition NodeI.h:166
FinishUpdateHelper(const NodeIPtr &node)
Definition NodeI.h:118
void merge(const std::set< int > &)
Definition NodeI.cpp:419
void checkObserverInit(Ice::Long)
Definition NodeI.cpp:1119
Ice::ObjectPrx startUpdate(Ice::Long &, const char *, int)
Definition NodeI.cpp:1135
virtual void accept(int, const std::string &, const Ice::IntSeq &, const Ice::ObjectPrx &, const LogUpdate &, int, const Ice::Current &)
Definition NodeI.cpp:901
virtual bool areYouThere(const std::string &, int, const Ice::Current &) const
Definition NodeI.cpp:979
virtual void invitation(int, const std::string &, const Ice::Current &)
Definition NodeI.cpp:724
bool updateMaster(const char *, int)
Definition NodeI.cpp:1164
NodeI(const IceStorm::InstancePtr &, const ReplicaPtr &, const Ice::ObjectPrx &, int, const std::map< int, NodePrx > &)
Definition NodeI.cpp:169
void recovery(Ice::Long=-1)
Definition NodeI.cpp:1030
virtual void ready(int, const std::string &, const Ice::ObjectPrx &, int, Ice::Long, const Ice::Current &)
Definition NodeI.cpp:853
void startObserverUpdate(Ice::Long, const char *, int)
Definition NodeI.cpp:1212
Ice::ObjectPrx startCachedRead(Ice::Long &, const char *, int)
Definition NodeI.cpp:1195
ObserverUpdateHelper(const NodeIPtr &node, Ice::Long generation, const char *file, int line)
Definition NodeI.h:180
A replica node.
Definition Election.ice:204
idempotent Object * sync()
Get the sync object for the replica hosted by this node.
idempotent QueryInfo query()
Get the query information for the given node.
idempotent NodeInfoSeq nodes()
Get the replication group information.
idempotent bool areYouCoordinator()
Determine if this node is a coordinator.
NodeState
The node state.
Definition Election.ice:138
::std::vector<::IceStormElection::NodeInfo > NodeInfoSeq
A sequence of node info.
Definition Election.h:1264
IceUtil::Handle< NodeI > NodeIPtr
Definition Instance.h:36
IceUtil::Handle< Replica > ReplicaPtr
Definition Replica.h:49
IceUtil::Handle< Observers > ObserversPtr
Definition Instance.h:33
IceUtil::Handle< TraceLevels > TraceLevelsPtr
Definition Instance.h:44
IceUtil::Handle< Instance > InstancePtr
Definition Instance.h:128
IceUtil::Handle< Timer > TimerPtr
Definition Instance.h:25
A struct used for marking the last log update.
Definition LLURecord.h:103