1 /* Copyright (c) 2003, 2005-2007 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17 #include <NDBT_Test.hpp>
18 #include <HugoTransactions.hpp>
19 #include <UtilTransactions.hpp>
20 #include <NdbBackup.hpp>
22 #include "bank/Bank.hpp"
23 #include <NdbMixRestarter.hpp>
27 #define CHECK(b) if (!(b)) { \
28 g_err << "ERR: "<< step->getName() \
29 << " failed on line " << __LINE__ << endl; \
30 result = NDBT_FAILED; \
33 int runCreateBank(NDBT_Context
* ctx
, NDBT_Step
* step
){
34 Bank
bank(ctx
->m_cluster_connection
);
35 int overWriteExisting
= true;
36 if (bank
.createAndLoadBank(overWriteExisting
, disk
, 10) != NDBT_OK
)
44 * SR 1 - shutdown in progress
45 * SR 2 - restart in progress
48 runBankTimer(NDBT_Context
* ctx
, NDBT_Step
* step
){
49 int wait
= 5; // Max seconds between each "day"
50 int yield
= 1; // Loops before bank returns
52 ctx
->incProperty(NMR_SR_THREADS
);
53 while (!ctx
->isTestStopped())
55 Bank
bank(ctx
->m_cluster_connection
);
56 while(!ctx
->isTestStopped() &&
57 ctx
->getProperty(NMR_SR
) <= NdbMixRestarter::SR_STOPPING
)
59 if(bank
.performIncreaseTime(wait
, yield
) == NDBT_FAILED
)
63 ndbout_c("runBankTimer is stopped");
64 ctx
->incProperty(NMR_SR_THREADS_STOPPED
);
65 if(ctx
->getPropertyWait(NMR_SR
, NdbMixRestarter::SR_RUNNING
))
71 int runBankTransactions(NDBT_Context
* ctx
, NDBT_Step
* step
){
72 int wait
= 0; // Max ms between each transaction
73 int yield
= 1; // Loops before bank returns
75 ctx
->incProperty(NMR_SR_THREADS
);
76 while (!ctx
->isTestStopped())
78 Bank
bank(ctx
->m_cluster_connection
);
79 while(!ctx
->isTestStopped() &&
80 ctx
->getProperty(NMR_SR
) <= NdbMixRestarter::SR_STOPPING
)
81 if(bank
.performTransactions(0, 1) == NDBT_FAILED
)
84 ndbout_c("runBankTransactions is stopped");
85 ctx
->incProperty(NMR_SR_THREADS_STOPPED
);
86 if(ctx
->getPropertyWait(NMR_SR
, NdbMixRestarter::SR_RUNNING
))
92 int runBankGL(NDBT_Context
* ctx
, NDBT_Step
* step
){
93 int yield
= 1; // Loops before bank returns
96 ctx
->incProperty(NMR_SR_THREADS
);
97 while (ctx
->isTestStopped() == false)
99 Bank
bank(ctx
->m_cluster_connection
);
100 while(!ctx
->isTestStopped() &&
101 ctx
->getProperty(NMR_SR
) <= NdbMixRestarter::SR_STOPPING
)
102 if (bank
.performMakeGLs(yield
) != NDBT_OK
)
104 if(ctx
->getProperty(NMR_SR
) != NdbMixRestarter::SR_RUNNING
)
106 ndbout
<< "bank.performMakeGLs FAILED" << endl
;
111 ndbout_c("runBankGL is stopped");
112 ctx
->incProperty(NMR_SR_THREADS_STOPPED
);
113 if(ctx
->getPropertyWait(NMR_SR
, NdbMixRestarter::SR_RUNNING
))
120 runBankSrValidator(NDBT_Context
* ctx
, NDBT_Step
* step
)
123 ctx
->incProperty(NMR_SR_VALIDATE_THREADS
);
125 while(!ctx
->isTestStopped())
127 if (ctx
->getPropertyWait(NMR_SR
, NdbMixRestarter::SR_VALIDATING
))
132 Bank
bank(ctx
->m_cluster_connection
);
133 if (bank
.performSumAccounts(wait
, yield
) != 0)
135 ndbout
<< "bank.performSumAccounts FAILED" << endl
;
140 if (bank
.performValidateAllGLs() != 0)
142 ndbout
<< "bank.performValidateAllGLs FAILED" << endl
;
147 ctx
->incProperty(NMR_SR_VALIDATE_THREADS_DONE
);
149 if (ctx
->getPropertyWait(NMR_SR
, NdbMixRestarter::SR_RUNNING
))
157 int runBankSum(NDBT_Context
* ctx
, NDBT_Step
* step
){
158 Bank
bank(ctx
->m_cluster_connection
);
159 int wait
= 2000; // Max ms between each sum of accounts
160 int yield
= 1; // Loops before bank returns
161 int result
= NDBT_OK
;
163 while (ctx
->isTestStopped() == false)
165 if (bank
.performSumAccounts(wait
, yield
) != NDBT_OK
){
166 ndbout
<< "bank.performSumAccounts FAILED" << endl
;
167 result
= NDBT_FAILED
;
176 runMixRestart(NDBT_Context
* ctx
, NDBT_Step
* step
)
178 int result
= NDBT_OK
;
180 int runtime
= ctx
->getNumLoops();
181 int sleeptime
= ctx
->getNumRecords();
182 Uint32 mask
= ctx
->getProperty("Type", ~(Uint32
)0);
183 res
.setRestartTypeMask(mask
);
185 if (res
.runPeriod(ctx
, step
, runtime
, sleeptime
))
196 runDropBank(NDBT_Context
* ctx
, NDBT_Step
* step
){
197 Bank
bank(ctx
->m_cluster_connection
);
198 if (bank
.dropBank() != NDBT_OK
)
204 NDBT_TESTSUITE(testSRBank
);
206 " Test that a consistent bank is restored after graceful shutdown\n"
208 "2. Start bank and let it run\n"
209 "3. Restart ndb and verify consistency\n"
212 TC_PROPERTY("Type", NdbMixRestarter::RTM_SR
);
213 INITIALIZER(runCreateBank
);
215 STEP(runBankTransactions
);
216 STEP(runBankTransactions
);
217 STEP(runBankTransactions
);
218 STEP(runBankTransactions
);
219 STEP(runBankTransactions
);
220 STEP(runBankTransactions
);
221 STEP(runBankTransactions
);
222 STEP(runBankTransactions
);
223 STEP(runBankTransactions
);
224 STEP(runBankTransactions
);
226 STEP(runBankSrValidator
);
230 " Test that a consistent bank is restored after graceful shutdown\n"
232 "2. Start bank and let it run\n"
233 "3. Restart ndb and verify consistency\n"
236 TC_PROPERTY("Type", NdbMixRestarter::RTM_NR
);
237 INITIALIZER(runCreateBank
);
239 STEP(runBankTransactions
);
240 STEP(runBankTransactions
);
241 STEP(runBankTransactions
);
242 STEP(runBankTransactions
);
243 STEP(runBankTransactions
);
244 STEP(runBankTransactions
);
245 STEP(runBankTransactions
);
246 STEP(runBankTransactions
);
247 STEP(runBankTransactions
);
248 STEP(runBankTransactions
);
251 FINALIZER(runDropBank
);
254 " Test that a consistent bank is restored after graceful shutdown\n"
256 "2. Start bank and let it run\n"
257 "3. Restart ndb and verify consistency\n"
260 TC_PROPERTY("Type", NdbMixRestarter::RTM_ALL
);
261 INITIALIZER(runCreateBank
);
263 STEP(runBankTransactions
);
264 STEP(runBankTransactions
);
265 STEP(runBankTransactions
);
266 STEP(runBankTransactions
);
267 STEP(runBankTransactions
);
268 STEP(runBankTransactions
);
269 STEP(runBankTransactions
);
270 STEP(runBankTransactions
);
271 STEP(runBankTransactions
);
272 STEP(runBankTransactions
);
275 STEP(runBankSrValidator
);
276 FINALIZER(runDropBank
);
278 NDBT_TESTSUITE_END(testSRBank
);
281 main(int argc
, const char** argv
){
283 for (int i
= 0; i
<argc
; i
++)
285 if (strcmp(argv
[i
], "--disk") == 0)
294 return testSRBank
.execute(argc
, argv
);
297 template class Vector
<ndb_mgm_node_state
*>;