PadicoTM

Documentation

« back to PM2 home.
control-bootstrap.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2025 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
55#include <arpa/inet.h>
56
57#include <Padico/Puk.h>
58#include <Padico/PadicoTM.h>
59#include <Padico/Module.h>
60
61#include <Padico/NetSelector.h>
62#include <Padico/Topology.h>
63#include <Padico/PadicoControl.h>
64
65static int control_bootstrap_init(void);
66static void control_bootstrap_finalize(void);
67
69
70PADICO_MODULE_ATTR(mode, "PADICO_BOOTSTRAP_MODE", "mode for the control bootstrap: client, server, cluster, or auto; default = auto",
71 string, "auto");
72
73PADICO_MODULE_ATTR(sync, "PADICO_BOOTSTRAP_SYNC", "synchronization at bootstrap; 'full' = wait all nodes; number = wait n nodes; default = full",
74 string, "full");
75
76PADICO_MODULE_ATTR_FLAG(uuid, "PADICO_BOOTSTRAP_UUID", "UUID of the master node for bootstrap.", string, "", PUK_OPT_FLAG_SYSTEM);
77
78PADICO_MODULE_ATTR_FLAG(host, "PADICO_BOOTSTRAP_HOST", "name of the bootstrap server, as in DNS", string, "", PUK_OPT_FLAG_SYSTEM);
79
80/* ********************************************************* */
81
83
84static struct
85{
89 struct
90 {
93 enum { BOOTSTRAP_MODE_SESSION, BOOTSTRAP_MODE_TOTAL } mode;
98 { .component = NULL, .instance = NULL };
99
100/* ********************************************************* */
101
104{
105 control_bootstrap.component =
107 if(control_bootstrap.component == NULL)
108 {
109 padico_fatal("no PadicoBootstrap assembly found.\n");
110 }
113 {
114 padico_fatal("bootstrap component do not provide required interface (PadicoBootstrap, PadicoControl).\n");
115 }
118 padico_out(50, "init bootstrap served by assembly %s\n", control_bootstrap.instance->component->name);
119}
120
128
130{
132 switch(event->kind)
133 {
135 {
136 const padico_topo_node_t node = event->NODE.node;
139 {
140 if((control_bootstrap.sync.mode == BOOTSTRAP_MODE_TOTAL) ||
141 ((control_bootstrap.sync.mode == BOOTSTRAP_MODE_SESSION) &&
144 {
147 }
148 }
150 }
151 break;
152
154 {
155 const puk_instance_t controler = event->PLUG_CONTROLER.controler;
156 const puk_instance_t server = event->PLUG_CONTROLER.server;
159 if(server && (server_root == control_bootstrap.instance))
160 {
162 }
163 }
164 break;
165
166 default:
167 break;
168 }
169}
170
171
173{
174 puk_iface_register("PadicoBootstrap");
175 int is_rdv_client = 0, is_rdv_server = 0;
180 if((s_bootstrap_uuid == NULL) || (strlen(s_bootstrap_uuid) == 0))
181 {
182 padico_fatal("PADICO_BOOTSTRAP_UUID not set.\n");
183 }
185 const int size = atoi(padico_getenv("PADICO_BOOT_SIZE")?:"1");
186 const int rank = atoi(padico_getenv("PADICO_BOOT_RANK")?:"0");
189 {
190 /* bootstrap master */
191 is_rdv_server = 1;
192 }
193 else
194 {
195 is_rdv_client = 1;
196 }
197
202 control_bootstrap.sync.nodes_ready = 0;
205 .xml_tag = "ControlBootstrap:ready",
206 .start_handler = NULL,
207 .end_handler = &control_bootstrap_ready_handler,
208 .required_level = PUK_TRUST_CONTROL
209 });
210
211 if(strcmp(mode, "client") == 0)
212 {
213 is_rdv_client = 1;
214 }
215 else if(strcmp(mode, "server") == 0)
216 {
217 is_rdv_server = 1;
218 }
219
220 if(is_rdv_server)
221 {
222 /* rendez-vous server */
223 padico_print("I am the rendez-vous node; listening...\n");
225 (*r.driver->bootstrap_new)(r._status);
226 }
227
228 if(is_rdv_client)
229 {
230 /* rendez-vous client */
231 if((!c_rdv_host) || (strlen(c_rdv_host) == 0))
232 padico_fatal("configured as client. Cannot connect to the rendez-vous server because host is not configured. Please give a bootstrap server host with the PADICO_BOOTSTRAP_HOST attribute.\n");
233 padico_print("connecting to rendez-vous host=%s; uuid =%s\n", c_rdv_host, s_bootstrap_uuid);
236 int sleep_msec = 10;
237 const int sleep_msec_warning = 1000;
238 const int sleep_msec_timeout = 20 * 1000; /* 20 seconds */
239 int rc = 0;
240 do
241 {
242 rc = (*r.driver->bootstrap_connect)(r._status, c_rdv_host, bootstrap_uuid);
243 if(rc)
244 {
246 padico_warning("connection failed rc = %d (%s) with component %s- waiting %dmsec.\n",
247 rc, strerror(-rc), control_bootstrap.component->name, sleep_msec);
249 sleep_msec *= 2;
250 }
251 }
252 while(rc && (sleep_msec < sleep_msec_timeout));
253 if(rc)
254 {
255 padico_fatal("connection failed- cannot connect to session leader node.\n");
256 }
257 padico_print("connected.\n");
258 }
259 int wait_nodes = -1;
260 if(sync && strcmp(sync, "full") == 0)
261 {
262 /* full session synchro: all nodes wait for all nodes */
263 control_bootstrap.sync.mode = BOOTSTRAP_MODE_SESSION;
264 wait_nodes = size - 1;
265 padico_print("synchronizing session- waiting for %d nodes in session...\n", wait_nodes + 1);
266
267 }
268 else
269 {
270 control_bootstrap.sync.mode = BOOTSTRAP_MODE_TOTAL;
271 if(sync && (atoi(sync) > 0))
272 {
273 wait_nodes = atoi(sync) - 1;
274 padico_print("synchronizing session- waiting for %d nodes to join...\n", wait_nodes + 1);
275 }
276 else
277 {
278 wait_nodes = 0;
279 }
280 }
281
284 {
285 /* Note: this cond_wait purposely *blocks* the taskengine tasklet.
286 * It prevents following tasks to be processed, but (hopefully)
287 * allows recursive tasks to be processed so as to satisfy dependencies.
288 */
290 }
291 if(control_bootstrap.sync.mode == BOOTSTRAP_MODE_SESSION)
292 {
294 while(padico_topo_network_size(session) < size)
295 {
297 }
298 if(rank == 0)
299 {
300 /* wait all nodes to acknowledge they are ready */
302 while((control_bootstrap.sync.nodes_ready < wait_nodes) ||
304 {
306 }
307 }
308 else
309 {
314 padico_string_printf(msg, "<ControlBootstrap:ready>%s</ControlBootstrap:ready>\n", padico_string_get(self_node));
318 }
319 }
322 padico_print("session is ready.\n");
323
324 return 0;
325}
326
struct ns_rulebucket_hash_entry_s * e
return NULL
Definition Shm.h:88
int r
Definition Shm.h:88
padico_topo_host_t host
padico_topo_host_t const char * uuid
static int done
Definition console-mod.c:49
pthread_mutex_t lock
int nodes_ready
puk_component_t component
component used for listening
control_bootstrap_conn_vect_t conns
list of connections established by ControlBootstrap
static puk_opt_type_string_t padico_module_attr_sync_getvalue(void)
struct @14::@15 sync
static puk_opt_type_string_t padico_module_attr_host_getvalue(void)
pthread_cond_t ready
static void control_bootstrap_event_listener(void *_arg)
static struct @14 control_bootstrap
static puk_opt_type_string_t padico_module_attr_mode_getvalue(void)
static void control_bootstrap_ready_handler(puk_parse_entity_t e)
static void control_bootstrap_finalize(void)
static void padico_bootstrap_indirect(padico_topo_host_t rdv_host, struct puk_receptacle_PadicoBootstrap_s *r)
static int control_bootstrap_init(void)
typdef struct control_bootstrap_conn_vect_s * control_bootstrap_conn_vect_t
puk_instance_t instance
the listening bootstrap instance
padico_topo_node_vect_t nodes
enum @14::@15::@16 mode
static puk_opt_type_string_t padico_module_attr_uuid_getvalue(void)
static int size
Definition datacheck.c:34
static int rank
Definition datacheck.c:35
static int server()
Definition datacheck.c:179
puk_component_t padico_ns_host_selector(padico_topo_host_t host, const char *profile, puk_iface_t iface, uint16_t port, int protocol)
static void padico_control_event_enable(void)
static void puk_instance_indirect_PadicoBootstrap(puk_instance_t instance, const char *label, struct puk_receptacle_PadicoBootstrap_s *receptacle)
static void padico_control_send_oneway(padico_topo_node_t node, const char *msg)
Send a "one way" message on the control channel.
static void padico_control_event_disable(void)
static puk_iface_t puk_iface_PadicoBootstrap(void)
static void padico_control_event_unsubscribe(padico_event_listener_t l)
static void padico_control_event_subscribe(padico_event_listener_t l)
static const struct padico_control_driver_s * puk_component_get_driver_PadicoControl(puk_component_t component, const char *label)
static const struct padico_bootstrap_driver_s * puk_component_get_driver_PadicoBootstrap(puk_component_t component, const char *label)
static void padico_control_event_sync(void)
padico_rc_t rc
Definition PadicoTM.h:146
void padico_tm_msleep(long msec)
Definition tm-boot.c:384
padico_string_t padico_topo_node_serialize(padico_topo_node_t node)
Definition topo-xml.c:168
const struct topo_uuid_s * padico_topo_uuid_t
Definition Topology.h:74
static padico_topo_node_t padico_topo_session_getnodebyrank(const char *session_id, int rank)
Definition Topology.h:338
static padico_topo_network_t padico_topo_session_getnetwork(const char *session_id)
Definition Topology.h:330
int padico_topo_network_size(padico_topo_network_t network)
Definition topology.c:2237
padico_topo_node_t padico_topo_getlocalnode(void)
Definition topology.c:1891
typdef struct padico_topo_node_vect_s * padico_topo_node_vect_t
Definition Topology.h:84
padico_topo_node_t padico_topo_getnodebyuuid(padico_topo_uuid_t uuid)
node lookup, by UUID
Definition topology.c:2407
padico_topo_host_t padico_topo_host_resolvebyname(const char *hostname)
resolve a host from name
Definition topology.c:2681
const char * padico_topo_node_getsession(padico_topo_node_t node)
Get the boot session ID.
Definition topology.c:1922
padico_topo_node_t node
Definition na-control.c:65
puk_instance_t controler
@ PADICO_CONTROL_EVENT_PLUG_CONTROLER
a new controler (PadicoControl) is loaded
@ PADICO_CONTROL_EVENT_NEW_NODE
a new node appeared in the known topology
a network, containing entities with bindings
Node UUID, in plain text (hex encoding)
marcel_cond_t event
Definition tm-boot.c:65