Statistics
| Branch: | Tag: | Revision:

root / doc / design-2.0-master-daemon.rst @ efd0d44f

History | View | Annotate | Download (7.2 kB)

1
Ganeti 2.0 Master daemon
2
========================
3

    
4
Objective
5
---------
6

    
7
Many of the important features of Ganeti 2.0 — job queue, granular
8
locking, external API, etc. — will be integrated via a master
9
daemon. While not absolutely necessary, it is the best way to
10
integrate all these components.
11

    
12
Background
13
----------
14

    
15
Currently there is no "master" daemon in Ganeti (1.2). Each command
16
tries to acquire the so called *cmd* lock and when it succeeds, it
17
takes complete ownership of the cluster configuration and state. The
18
scheduled improvements to Ganeti require or can use a daemon that
19
coordinates the activities/jobs scheduled/etc.
20

    
21
Overview
22
--------
23

    
24
The master daemon will be the central point of the cluster; command
25
line tools and the external API will interact with the cluster via
26
this daemon; it will be one coordinating the node daemons.
27

    
28
This design doc is best read in the context of the accompanying design
29
docs for Ganeti 2.0: Granular locking design and Job queue design.
30

    
31

    
32
Detailed Design
33
---------------
34

    
35
In Ganeti 2.0, we will have the following *entities*:
36

    
37
- the master daemon (on master node)
38
- the node daemon (all nodes)
39
- the command line tools (master node)
40
- the RAPI daemon (master node)
41

    
42
Interaction paths are between:
43

    
44
- (CLI tools/RAPI daemon) and the master daemon, via the so called *luxi* API
45
- the master daemon and the node daemons, via the node RPC
46

    
47
The protocol between the master daemon and the node daemons will be
48
changed to HTTP(S), using a simple PUT/GET of JSON-encoded
49
messages. This is done due to difficulties in working with the Twisted
50
framework and its protocols in a multithreaded environment, which we can
51
overcome by using a simpler stack (see the caveats section). The protocol
52
between the CLI/RAPI and the master daemon will be a custom one: on a UNIX
53
socket on the master node, with rights restricted by filesystem
54
permissions, the CLI/RAPI will talk to the master daemon using JSON-encoded
55
messages.
56

    
57
The operations supported over this internal protocol will be encoded
58
via a python library that will expose a simple API for its
59
users. Internally, the protocol will simply encode all objects in JSON
60
format and decode them on the receiver side.
61

    
62
The LUXI protocol
63
~~~~~~~~~~~~~~~~~
64

    
65
We will have two main classes of operations over the master daemon API:
66

    
67
- cluster query functions
68
- job related functions
69

    
70
The cluster query functions are usually short-duration, and are the
71
equivalent of the OP_QUERY_* opcodes in ganeti 1.2 (and they are
72
internally implemented still with these opcodes). The clients are
73
guaranteed to receive the response in a reasonable time via a timeout.
74

    
75
The job-related functions will be:
76

    
77
- submit job
78
- query job (which could also be categorized in the query-functions)
79
- archive job (see the job queue design doc)
80
- wait for job change, which allows a client to wait without polling
81

    
82
For more details, see the job queue design document.
83

    
84
Daemon implementation
85
~~~~~~~~~~~~~~~~~~~~~
86

    
87
The daemon will be based around a main I/O thread that will wait for
88
new requests from the clients, and that does the setup/shutdown of the
89
other thread (pools).
90

    
91
There will two other classes of threads in the daemon:
92

    
93
- job processing threads, part of a thread pool, and which are
94
  long-lived, started at daemon startup and terminated only at shutdown
95
  time
96
- client I/O threads, which are the ones that talk the local protocol
97
  to the clients
98

    
99
Master startup/failover
100
~~~~~~~~~~~~~~~~~~~~~~~
101

    
102
In Ganeti 1.x there is no protection against failing over the master
103
to a node with stale configuration. In effect, the responsibility of
104
correct failovers falls on the admin. This is true both for the new
105
master and for when an old, offline master startup.
106

    
107
Since in 2.x we are extending the cluster state to cover the job queue
108
and have a daemon that will execute by itself the job queue, we want
109
to have more resilience for the master role.
110

    
111
The following algorithm will happen whenever a node is ready to
112
transition to the master role, either at startup time or at node
113
failover:
114

    
115
#. read the configuration file and parse the node list
116
   contained within
117

    
118
#. query all the nodes and make sure we obtain an agreement via
119
   a quorum of at least half plus one nodes for the following:
120

    
121
    - we have the latest configuration and job list (as
122
      determined by the serial number on the configuration and
123
      highest job ID on the job queue)
124

    
125
    - there is not even a single node having a newer
126
      configuration file
127

    
128
    - if we are not failing over (but just starting), the
129
      quorum agrees that we are the designated master
130

    
131
#. at this point, the node transitions to the master role
132

    
133
#. for all the in-progress jobs, mark them as failed, with
134
   reason unknown or something similar (master failed, etc.)
135

    
136

    
137
Logging
138
~~~~~~~
139

    
140
The logging system will be switched completely to the logging module;
141
currently it's logging-based, but exposes a different API, which is
142
just overhead. As such, the code will be switched over to standard
143
logging calls, and only the setup will be custom.
144

    
145
With this change, we will remove the separate debug/info/error logs,
146
and instead have always one logfile per daemon model:
147

    
148
- master-daemon.log for the master daemon
149
- node-daemon.log for the node daemon (this is the same as in 1.2)
150
- rapi-daemon.log for the RAPI daemon logs
151
- rapi-access.log, an additional log file for the RAPI that will be
152
  in the standard http log format for possible parsing by other tools
153

    
154
Since the watcher will only submit jobs to the master for startup of
155
the instances, its log file will contain less information than before,
156
mainly that it will start the instance, but not the results.
157

    
158
Caveats
159
-------
160

    
161
A discussed alternative is to keep the current individual processes
162
touching the cluster configuration model. The reasons we have not
163
chosen this approach is:
164

    
165
- the speed of reading and unserializing the cluster state
166
  today is not small enough that we can ignore it; the addition of
167
  the job queue will make the startup cost even higher. While this
168
  runtime cost is low, it can be on the order of a few seconds on
169
  bigger clusters, which for very quick commands is comparable to
170
  the actual duration of the computation itself
171

    
172
- individual commands would make it harder to implement a
173
  fire-and-forget job request, along the lines "start this
174
  instance but do not wait for it to finish"; it would require a
175
  model of backgrounding the operation and other things that are
176
  much better served by a daemon-based model
177

    
178
Another area of discussion is moving away from Twisted in this new
179
implementation. While Twisted hase its advantages, there are also many
180
disatvantanges to using it:
181

    
182
- first and foremost, it's not a library, but a framework; thus, if
183
  you use twisted, all the code needs to be 'twiste-ized'; we were able
184
  to keep the 1.x code clean by hacking around twisted in an
185
  unsupported, unrecommended way, and the only alternative would have
186
  been to make all the code be written for twisted
187
- it has some weaknesses in working with multiple threads, since its base
188
  model is designed to replace thread usage by using deferred calls, so while
189
  it can use threads, it's not less flexible in doing so
190

    
191
And, since we already have an HTTP server library for the RAPI, we
192
can just reuse that for inter-node communication.