~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/testSRBank.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
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 as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
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.
 
11
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <NDBT.hpp>
 
17
#include <NDBT_Test.hpp>
 
18
#include <HugoTransactions.hpp>
 
19
#include <UtilTransactions.hpp>
 
20
#include <NdbBackup.hpp>
 
21
 
 
22
#include "bank/Bank.hpp"
 
23
#include <NdbMixRestarter.hpp>
 
24
 
 
25
bool disk = false;
 
26
 
 
27
#define CHECK(b) if (!(b)) { \
 
28
  g_err << "ERR: "<< step->getName() \
 
29
         << " failed on line " << __LINE__ << endl; \
 
30
  result = NDBT_FAILED; \
 
31
  continue; } 
 
32
 
 
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)
 
37
    return NDBT_FAILED;
 
38
  return NDBT_OK;
 
39
}
 
40
 
 
41
/**
 
42
 *
 
43
 * SR 0 - normal
 
44
 * SR 1 - shutdown in progress
 
45
 * SR 2 - restart in progress
 
46
 */
 
47
int 
 
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 
 
51
  
 
52
  ctx->incProperty(NMR_SR_THREADS);
 
53
  while (!ctx->isTestStopped()) 
 
54
  {
 
55
    Bank bank(ctx->m_cluster_connection);
 
56
    while(!ctx->isTestStopped() && 
 
57
          ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
 
58
    {
 
59
      if(bank.performIncreaseTime(wait, yield) == NDBT_FAILED)
 
60
        break;
 
61
    }
 
62
    
 
63
    ndbout_c("runBankTimer is stopped");
 
64
    ctx->incProperty(NMR_SR_THREADS_STOPPED);
 
65
    if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
 
66
      break;
 
67
  }
 
68
  return NDBT_OK;
 
69
}
 
70
 
 
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 
 
74
 
 
75
  ctx->incProperty(NMR_SR_THREADS);
 
76
  while (!ctx->isTestStopped()) 
 
77
  {
 
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)
 
82
        break;
 
83
    
 
84
    ndbout_c("runBankTransactions is stopped");
 
85
    ctx->incProperty(NMR_SR_THREADS_STOPPED);
 
86
    if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
 
87
      break;
 
88
  }
 
89
  return NDBT_OK;
 
90
}
 
91
 
 
92
int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
 
93
  int yield = 1; // Loops before bank returns 
 
94
  int result = NDBT_OK;
 
95
  
 
96
  ctx->incProperty(NMR_SR_THREADS);
 
97
  while (ctx->isTestStopped() == false) 
 
98
  {
 
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)
 
103
      {
 
104
        if(ctx->getProperty(NMR_SR) != NdbMixRestarter::SR_RUNNING)
 
105
          break;
 
106
        ndbout << "bank.performMakeGLs FAILED" << endl;
 
107
        abort();
 
108
        return NDBT_FAILED;
 
109
      }
 
110
    
 
111
    ndbout_c("runBankGL is stopped");
 
112
    ctx->incProperty(NMR_SR_THREADS_STOPPED);
 
113
    if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
 
114
      break;
 
115
  }
 
116
  return NDBT_OK;
 
117
}
 
118
 
 
119
int 
 
120
runBankSrValidator(NDBT_Context* ctx, NDBT_Step* step)
 
121
{
 
122
 
 
123
  ctx->incProperty(NMR_SR_VALIDATE_THREADS);
 
124
 
 
125
  while(!ctx->isTestStopped())
 
126
  {
 
127
    if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_VALIDATING))
 
128
      break;
 
129
    
 
130
    int wait = 0;
 
131
    int yield = 1;
 
132
    Bank bank(ctx->m_cluster_connection);
 
133
    if (bank.performSumAccounts(wait, yield) != 0)
 
134
    {
 
135
      ndbout << "bank.performSumAccounts FAILED" << endl;
 
136
      abort();
 
137
      return NDBT_FAILED;
 
138
    }
 
139
    
 
140
    if (bank.performValidateAllGLs() != 0)
 
141
    {
 
142
      ndbout << "bank.performValidateAllGLs FAILED" << endl;
 
143
      abort();
 
144
      return NDBT_FAILED;
 
145
    }
 
146
    
 
147
    ctx->incProperty(NMR_SR_VALIDATE_THREADS_DONE);
 
148
    
 
149
    if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
 
150
      break;
 
151
  }
 
152
  
 
153
  return NDBT_OK;
 
154
}
 
155
 
 
156
#if 0
 
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;
 
162
 
 
163
  while (ctx->isTestStopped() == false) 
 
164
  {
 
165
    if (bank.performSumAccounts(wait, yield) != NDBT_OK){
 
166
      ndbout << "bank.performSumAccounts FAILED" << endl;
 
167
      result = NDBT_FAILED;
 
168
    }
 
169
  }
 
170
  return result ;
 
171
}
 
172
#endif
 
173
 
 
174
 
 
175
int
 
176
runMixRestart(NDBT_Context* ctx, NDBT_Step* step)
 
177
{
 
178
  int result = NDBT_OK;
 
179
  NdbMixRestarter res;
 
180
  int runtime = ctx->getNumLoops();
 
181
  int sleeptime = ctx->getNumRecords();
 
182
  Uint32 mask = ctx->getProperty("Type", ~(Uint32)0);
 
183
  res.setRestartTypeMask(mask);
 
184
 
 
185
  if (res.runPeriod(ctx, step, runtime, sleeptime))
 
186
  {
 
187
    abort();
 
188
    return NDBT_FAILED;
 
189
  }
 
190
 
 
191
  ctx->stopTest();
 
192
  return NDBT_OK;
 
193
}
 
194
 
 
195
int 
 
196
runDropBank(NDBT_Context* ctx, NDBT_Step* step){
 
197
  Bank bank(ctx->m_cluster_connection);
 
198
  if (bank.dropBank() != NDBT_OK)
 
199
    return NDBT_FAILED;
 
200
  return NDBT_OK;
 
201
}
 
202
 
 
203
 
 
204
NDBT_TESTSUITE(testSRBank);
 
205
TESTCASE("SR", 
 
206
         " Test that a consistent bank is restored after graceful shutdown\n"
 
207
         "1.  Create bank\n"
 
208
         "2.  Start bank and let it run\n"
 
209
         "3.  Restart ndb and verify consistency\n"
 
210
         "4.  Drop bank\n")
 
211
{
 
212
  TC_PROPERTY("Type", NdbMixRestarter::RTM_SR);
 
213
  INITIALIZER(runCreateBank);
 
214
  STEP(runBankTimer);
 
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);
 
225
  STEP(runBankGL);
 
226
  STEP(runBankSrValidator);
 
227
  STEP(runMixRestart);
 
228
}
 
229
TESTCASE("NR", 
 
230
         " Test that a consistent bank is restored after graceful shutdown\n"
 
231
         "1.  Create bank\n"
 
232
         "2.  Start bank and let it run\n"
 
233
         "3.  Restart ndb and verify consistency\n"
 
234
         "4.  Drop bank\n")
 
235
{
 
236
  TC_PROPERTY("Type", NdbMixRestarter::RTM_NR);
 
237
  INITIALIZER(runCreateBank);
 
238
  STEP(runBankTimer);
 
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);
 
249
  STEP(runBankGL);
 
250
  STEP(runMixRestart);
 
251
  FINALIZER(runDropBank);
 
252
}
 
253
TESTCASE("Mix", 
 
254
         " Test that a consistent bank is restored after graceful shutdown\n"
 
255
         "1.  Create bank\n"
 
256
         "2.  Start bank and let it run\n"
 
257
         "3.  Restart ndb and verify consistency\n"
 
258
         "4.  Drop bank\n")
 
259
{
 
260
  TC_PROPERTY("Type", NdbMixRestarter::RTM_ALL);
 
261
  INITIALIZER(runCreateBank);
 
262
  STEP(runBankTimer);
 
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);
 
273
  STEP(runBankGL);
 
274
  STEP(runMixRestart);
 
275
  STEP(runBankSrValidator);
 
276
  FINALIZER(runDropBank);
 
277
}
 
278
NDBT_TESTSUITE_END(testSRBank);
 
279
 
 
280
int 
 
281
main(int argc, const char** argv){
 
282
  ndb_init();
 
283
  for (int i = 0; i<argc; i++)
 
284
  {
 
285
    if (strcmp(argv[i], "--disk") == 0)
 
286
    {
 
287
      argc--;
 
288
      disk = true;
 
289
      for (; i<argc; i++)
 
290
        argv[i] = argv[i+1];
 
291
      break;
 
292
    }
 
293
  } 
 
294
  return testSRBank.execute(argc, argv);
 
295
}
 
296
 
 
297
template class Vector<ndb_mgm_node_state*>;