1 /*
2    Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NDBT_RESTARTS_HPP
26 #define NDBT_RESTARTS_HPP
27 
28 #include <NdbRestarter.hpp>
29 #include <NdbTick.h>
30 #include <random.h>
31 
32 /**
33  * This class is used to test Ndb's ability to handle
34  * node- and system-restarts.
35  * For example:
36  *  Node restart:         Restart one node in the cluster.
37  *  System restart:       Restart all nodes in the cluster.
38  *  Node crash:           Crash one node in the middle of execution and bring it up again.
39  *  Multiple node crash:  Crash multiple nodes with a few seconds or milliseconds delay between.
40  *  Initial node restart: Restart one node in the cluster without a filesystem on disk.
41  *
42  * Each restart type is represented by a NdbRestart class and a collection of these are stored
43  * in the NdbRestarts class.
44  *
45  * This class may be used from other programs to execute a particular restart.
46  *
47  */
48 
49 class NDBT_Context;
50 
51 class NdbRestarts {
52 public:
NdbRestarts(const char * _addr=0)53   NdbRestarts(const char* _addr = 0):
54     m_restarter(_addr)
55   {
56     myRandom48Init((long)NdbTick_CurrentMillisecond());
57   }
58 
59   enum NdbRestartType{
60     NODE_RESTART,
61     MULTIPLE_NODE_RESTART,
62     SYSTEM_RESTART
63   };
64 
65   struct NdbRestart {
66     typedef int (restartFunc)(NDBT_Context*, NdbRestarter&, const NdbRestart*);
67 
68     NdbRestart(const char* _name,
69 	       NdbRestartType _type,
70 	       restartFunc* _func,
71 	       int _requiredNodes,
72 	       int _arg1 = -1);
73 
74     const char * m_name;
75     NdbRestartType m_type;
76     restartFunc* m_restartFunc;
77     int m_numRequiredNodes;
78     int m_arg1;
79 
80   };
81 
82   int getNumRestarts();
83 
84   int executeRestart(NDBT_Context*, int _num, unsigned int _to = 120);
85   int executeRestart(NDBT_Context*, const char* _name, unsigned int _to = 120);
86 
87   void listRestarts();
88   void listRestarts(NdbRestartType _type);
89 private:
90   int executeRestart(NDBT_Context*, const NdbRestart*, unsigned int _timeout);
91 
92   struct NdbErrorInsert {
93     NdbErrorInsert(const char* _name,
94 		   int _errorNo);
95 
96     const char * m_name;
97     int m_errorNo;
98 
99   public:
100     const char* getName();
101   };
102 
103   int getNumErrorInserts();
104   const NdbErrorInsert* getError(int _num);
105   const NdbErrorInsert* getRandomError();
106 
107   static const NdbErrorInsert   m_errors[];
108   static const int          m_NoOfErrors;
109 
110   const NdbRestart* getRestart(int _num);
111   const NdbRestart* getRestart(const char* _name);
112 
113   static const NdbRestart   m_restarts[];
114   static const int          m_NoOfRestarts;
115 
116   NdbRestarter m_restarter;
117 };
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 #endif
130