MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testSRBank.cpp
1 /*
2  Copyright (C) 2005-2008 MySQL AB, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <NDBT.hpp>
20 #include <NDBT_Test.hpp>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
23 #include <NdbBackup.hpp>
24 
25 #include "bank/Bank.hpp"
26 #include <NdbMixRestarter.hpp>
27 
28 bool disk = false;
29 
30 #define CHECK(b) if (!(b)) { \
31  g_err << "ERR: "<< step->getName() \
32  << " failed on line " << __LINE__ << endl; \
33  result = NDBT_FAILED; \
34  continue; }
35 
36 int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
37  Bank bank(ctx->m_cluster_connection);
38  int overWriteExisting = true;
39  if (bank.createAndLoadBank(overWriteExisting, disk, 10) != NDBT_OK)
40  return NDBT_FAILED;
41  return NDBT_OK;
42 }
43 
50 int
51 runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
52  int wait = 5; // Max seconds between each "day"
53  int yield = 1; // Loops before bank returns
54 
55  ctx->incProperty(NMR_SR_THREADS);
56  while (!ctx->isTestStopped())
57  {
58  Bank bank(ctx->m_cluster_connection);
59  while(!ctx->isTestStopped() &&
60  ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
61  {
62  if(bank.performIncreaseTime(wait, yield) == NDBT_FAILED)
63  break;
64  }
65 
66  ndbout_c("runBankTimer is stopped");
67  ctx->incProperty(NMR_SR_THREADS_STOPPED);
68  if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
69  break;
70  }
71  return NDBT_OK;
72 }
73 
74 int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
75  int wait = 0; // Max ms between each transaction
76  int yield = 1; // Loops before bank returns
77 
78  ctx->incProperty(NMR_SR_THREADS);
79  while (!ctx->isTestStopped())
80  {
81  Bank bank(ctx->m_cluster_connection);
82  while(!ctx->isTestStopped() &&
83  ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
84  if(bank.performTransactions(wait, yield) == NDBT_FAILED)
85  break;
86 
87  ndbout_c("runBankTransactions is stopped");
88  ctx->incProperty(NMR_SR_THREADS_STOPPED);
89  if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
90  break;
91  }
92  return NDBT_OK;
93 }
94 
95 int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
96  int yield = 1; // Loops before bank returns
97  //int result = NDBT_OK;
98 
99  ctx->incProperty(NMR_SR_THREADS);
100  while (ctx->isTestStopped() == false)
101  {
102  Bank bank(ctx->m_cluster_connection);
103  while(!ctx->isTestStopped() &&
104  ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
105  if (bank.performMakeGLs(yield) != NDBT_OK)
106  {
107  Uint32 state = ctx->getProperty(NMR_SR);
108  if(state != NdbMixRestarter::SR_RUNNING)
109  break;
110  ndbout << "bank.performMakeGLs FAILED: " << state << endl;
111  abort();
112  return NDBT_FAILED;
113  }
114 
115  ndbout_c("runBankGL is stopped");
116  ctx->incProperty(NMR_SR_THREADS_STOPPED);
117  if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
118  break;
119  }
120  return NDBT_OK;
121 }
122 
123 int
124 runBankSrValidator(NDBT_Context* ctx, NDBT_Step* step)
125 {
126 
127  ctx->incProperty(NMR_SR_VALIDATE_THREADS);
128 
129  while(!ctx->isTestStopped())
130  {
131  if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_VALIDATING))
132  break;
133 
134  int wait = 0;
135  int yield = 1;
136  Bank bank(ctx->m_cluster_connection);
137  if (bank.performSumAccounts(wait, yield) != 0)
138  {
139  ndbout << "bank.performSumAccounts FAILED" << endl;
140  abort();
141  return NDBT_FAILED;
142  }
143 
144  if (bank.performValidateAllGLs() != 0)
145  {
146  ndbout << "bank.performValidateAllGLs FAILED" << endl;
147  abort();
148  return NDBT_FAILED;
149  }
150 
151  ctx->incProperty(NMR_SR_VALIDATE_THREADS_DONE);
152 
153  if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
154  break;
155  }
156 
157  return NDBT_OK;
158 }
159 
160 #if 0
161 int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
162  Bank bank(ctx->m_cluster_connection);
163  int wait = 2000; // Max ms between each sum of accounts
164  int yield = 1; // Loops before bank returns
165  int result = NDBT_OK;
166 
167  while (ctx->isTestStopped() == false)
168  {
169  if (bank.performSumAccounts(wait, yield) != NDBT_OK){
170  ndbout << "bank.performSumAccounts FAILED" << endl;
171  result = NDBT_FAILED;
172  }
173  }
174  return result ;
175 }
176 #endif
177 
178 
179 int
180 runMixRestart(NDBT_Context* ctx, NDBT_Step* step)
181 {
182  //int result = NDBT_OK;
183  NdbMixRestarter res;
184  int runtime = ctx->getNumLoops();
185  int sleeptime = ctx->getNumRecords();
186  Uint32 mask = ctx->getProperty("Type", ~(Uint32)0);
187  res.setRestartTypeMask(mask);
188 
189  if (res.runPeriod(ctx, step, runtime, sleeptime))
190  {
191  abort();
192  return NDBT_FAILED;
193  }
194 
195  ctx->stopTest();
196  return NDBT_OK;
197 }
198 
199 int
200 runDropBank(NDBT_Context* ctx, NDBT_Step* step){
201  Bank bank(ctx->m_cluster_connection);
202  if (bank.dropBank() != NDBT_OK)
203  return NDBT_FAILED;
204  return NDBT_OK;
205 }
206 
207 
208 NDBT_TESTSUITE(testSRBank);
209 TESTCASE("SR",
210  " Test that a consistent bank is restored after graceful shutdown\n"
211  "1. Create bank\n"
212  "2. Start bank and let it run\n"
213  "3. Restart ndb and verify consistency\n"
214  "4. Drop bank\n")
215 {
216  TC_PROPERTY("Type", NdbMixRestarter::RTM_SR);
217  INITIALIZER(runCreateBank);
218  STEP(runBankTimer);
219  STEPS(runBankTransactions, 10);
220  STEP(runBankGL);
221  STEP(runBankSrValidator);
222  STEP(runMixRestart);
223  FINALIZER(runDropBank);
224 }
225 TESTCASE("NR",
226  " Test that a consistent bank is restored after graceful shutdown\n"
227  "1. Create bank\n"
228  "2. Start bank and let it run\n"
229  "3. Restart ndb and verify consistency\n"
230  "4. Drop bank\n")
231 {
232  TC_PROPERTY("Type", NdbMixRestarter::RTM_NR);
233  INITIALIZER(runCreateBank);
234  STEP(runBankTimer);
235  STEPS(runBankTransactions, 10);
236  STEP(runBankGL);
237  STEP(runMixRestart);
238  FINALIZER(runDropBank);
239 }
240 TESTCASE("Mix",
241  " Test that a consistent bank is restored after graceful shutdown\n"
242  "1. Create bank\n"
243  "2. Start bank and let it run\n"
244  "3. Restart ndb and verify consistency\n"
245  "4. Drop bank\n")
246 {
247  TC_PROPERTY("Type", NdbMixRestarter::RTM_ALL);
248  INITIALIZER(runCreateBank);
249  STEP(runBankTimer);
250  STEPS(runBankTransactions, 10);
251  STEP(runBankGL);
252  STEP(runMixRestart);
253  STEP(runBankSrValidator);
254  FINALIZER(runDropBank);
255 }
256 NDBT_TESTSUITE_END(testSRBank);
257 
258 int
259 main(int argc, const char** argv){
260  ndb_init();
261  for (int i = 0; i<argc; i++)
262  {
263  if (strcmp(argv[i], "--disk") == 0)
264  {
265  argc--;
266  disk = true;
267  for (; i<argc; i++)
268  argv[i] = argv[i+1];
269  break;
270  }
271  }
272  NDBT_TESTSUITE_INSTANCE(testSRBank);
273  return testSRBank.execute(argc, argv);
274 }
275