1 /* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 #include <assert.h>
24 #include <stdlib.h>
25
26 #include "xcom_common.h"
27 #include "simset.h"
28 #include "xcom_vp.h"
29 #include "task.h"
30 #include "task_debug.h"
31 #include "node_no.h"
32 #include "server_struct.h"
33 #include "xcom_detector.h"
34 #include "site_struct.h"
35 #include "xcom_transport.h"
36 #include "xcom_base.h"
37 #include "synode_no.h"
38
39 #include "xcom_recover.h"
40 #include "app_data.h"
41 #include "site_def.h"
42
43 extern task_env *boot;
44 extern task_env *net_boot;
45 extern task_env *net_recover;
46 extern task_env *killer;
47
48 extern synode_no executed_msg; /* The message we are waiting to execute */
49
50 start_t start_type;
51 int client_boot_done = 0;
52 int netboot_ok = 0;
53 int booting = 0;
54
55 /* purecov: begin deadcode */
init_recover_vars()56 void init_recover_vars()
57 {
58 start_type = IDLE;
59 client_boot_done = 0;
60 netboot_ok = 0;
61 booting = 0;
62 }
63 /* purecov: end */
64
65 static synode_no log_start; /* Redo log from this synode */
66 static synode_no log_end; /* Redo log until this synode */
67
xcom_recover_init()68 void xcom_recover_init()
69 {
70 log_start = null_synode;
71 log_end = null_synode;
72 }
73
set_log_group_id(uint32_t group_id)74 void set_log_group_id(uint32_t group_id)
75 {
76 log_start.group_id = group_id;
77 log_end.group_id = group_id;
78 }
79
80 /* purecov: begin deadcode */
log_prefetch_task(task_arg arg MY_ATTRIBUTE ((unused)))81 int log_prefetch_task(task_arg arg MY_ATTRIBUTE((unused)))
82 {
83 DECL_ENV
84 int self;
85 int n;
86 END_ENV;
87
88 TASK_BEGIN
89
90 ep->self = 0;
91 ep->n = 0;
92
93 MAY_DBG(FN; NDBG(ep->self, d); NDBG(task_now(), f));
94
95 assert(log_start.msgno != 0);
96
97 while (net_recover && (!synode_gt(executed_msg, log_end))) {
98 request_values(log_start, log_end);
99 ep->n ++;
100 if(ep->n > 1){
101 G_WARNING("log_prefetch_task retry %d",ep->n);
102 }
103 TASK_DELAY(1.0);
104 }
105 FINALLY
106 MAY_DBG(FN; STRLIT(" exit "); NDBG(ep->self, d); NDBG(task_now(), f));
107 TASK_END;
108 }
109
setup_recover(pax_msg * m)110 void setup_recover(pax_msg *m)
111 {
112 DBGOUT(FN; NDBG(client_boot_done, d));
113 if (!client_boot_done) {
114 start_type = RECOVER;
115 client_boot_done = 1; /* Detected incoming recovery from the net */
116 set_group(m->group_id);
117 SET_EXECUTED_MSG(m->synode);
118 check_tasks();
119 }
120 }
121
122
setup_boot(pax_msg * m)123 void setup_boot(pax_msg *m)
124 {
125 DBGOUT(FN; NDBG(client_boot_done, d));
126 if (!client_boot_done) {
127 start_type = BOOT;
128 client_boot_done = 1; /* Detected incoming boot from the net */
129 SET_EXECUTED_MSG(m->synode);
130 check_tasks();
131 }
132 }
133
134
xcom_booted()135 int xcom_booted()
136 {
137 return get_maxnodes(get_site_def()) > 0 && netboot_ok;
138 }
139 /* purecov: end */
140
141
142
143