1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <NDBT.hpp>
#include <NDBT_Test.hpp>
#include <HugoTransactions.hpp>
#include <UtilTransactions.hpp>
#include <NdbRestarter.hpp>
#include <Vector.hpp>
#include <random.h>
#include <mgmapi.h>
#include <mgmapi_debug.h>
int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
int records = ctx->getNumRecords();
HugoTransactions hugoTrans(*ctx->getTab());
if (hugoTrans.loadTable(GETNDB(step), records) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
int records = ctx->getNumRecords();
UtilTransactions utilTrans(*ctx->getTab());
if (utilTrans.clearTable2(GETNDB(step), records) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
int create_index_on_pk(Ndb* pNdb, const char* tabName){
int result = NDBT_OK;
const NdbDictionary::Table * tab = NDBT_Table::discoverTableFromDb(pNdb,
tabName);
// Create index
const char* idxName = "IDX_ON_PK";
ndbout << "Create: " <<idxName << "( ";
NdbDictionary::Index pIdx(idxName);
pIdx.setTable(tabName);
pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
for (int c = 0; c< tab->getNoOfPrimaryKeys(); c++){
pIdx.addIndexColumn(tab->getPrimaryKey(c));
ndbout << tab->getPrimaryKey(c)<<" ";
}
ndbout << ") ";
if (pNdb->getDictionary()->createIndex(pIdx) != 0){
ndbout << "FAILED!" << endl;
const NdbError err = pNdb->getDictionary()->getNdbError();
ERR(err);
result = NDBT_FAILED;
} else {
ndbout << "OK!" << endl;
}
return result;
}
int drop_index_on_pk(Ndb* pNdb, const char* tabName){
int result = NDBT_OK;
const char* idxName = "IDX_ON_PK";
ndbout << "Drop: " << idxName;
if (pNdb->getDictionary()->dropIndex(idxName, tabName) != 0){
ndbout << "FAILED!" << endl;
const NdbError err = pNdb->getDictionary()->getNdbError();
ERR(err);
result = NDBT_FAILED;
} else {
ndbout << "OK!" << endl;
}
return result;
}
#define CHECK(b) if (!(b)) { \
g_err << "ERR: "<< step->getName() \
<< " failed on line " << __LINE__ << endl; \
result = NDBT_FAILED; \
continue; }
int runTestSingleUserMode(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
Ndb* pNdb = GETNDB(step);
NdbRestarter restarter;
char tabName[255];
strncpy(tabName, ctx->getTab()->getName(), 255);
ndbout << "tabName="<<tabName<<endl;
int i = 0;
int count;
HugoTransactions hugoTrans(*ctx->getTab());
UtilTransactions utilTrans(*ctx->getTab());
while (i<loops && result == NDBT_OK) {
g_info << i << ": ";
int timeout = 120;
// Test that the single user mode api can do everything
CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
CHECK(restarter.waitClusterSingleUser(timeout) == 0);
CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
CHECK(count == records);
CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
CHECK(count == (records/2));
CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
CHECK(restarter.exitSingleUserMode() == 0);
CHECK(restarter.waitClusterStarted(timeout) == 0);
// Test create index in single user mode
CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
CHECK(restarter.waitClusterSingleUser(timeout) == 0);
CHECK(create_index_on_pk(pNdb, tabName) == 0);
CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
CHECK(count == records);
CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
CHECK(drop_index_on_pk(pNdb, tabName) == 0);
CHECK(restarter.exitSingleUserMode() == 0);
CHECK(restarter.waitClusterStarted(timeout) == 0);
// Test recreate index in single user mode
CHECK(create_index_on_pk(pNdb, tabName) == 0);
CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
CHECK(restarter.waitClusterSingleUser(timeout) == 0);
CHECK(drop_index_on_pk(pNdb, tabName) == 0);
CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
CHECK(create_index_on_pk(pNdb, tabName) == 0);
CHECK(restarter.exitSingleUserMode() == 0);
CHECK(restarter.waitClusterStarted(timeout) == 0);
CHECK(drop_index_on_pk(pNdb, tabName) == 0);
CHECK(utilTrans.clearTable(GETNDB(step), records) == 0);
ndbout << "Restarting cluster" << endl;
CHECK(restarter.restartAll() == 0);
CHECK(restarter.waitClusterStarted(timeout) == 0);
CHECK(pNdb->waitUntilReady(timeout) == 0);
i++;
}
return result;
}
int runTestApiSession(NDBT_Context* ctx, NDBT_Step* step)
{
char *mgm= ctx->getRemoteMgm();
NdbMgmHandle h;
h= ndb_mgm_create_handle();
ndb_mgm_set_connectstring(h, mgm);
ndb_mgm_connect(h,0,0,0);
int s= ndb_mgm_get_fd(h);
write(s,"get",3);
ndb_mgm_disconnect(h);
ndb_mgm_destroy_handle(&h);
/** NOTE: WE CANNOT REALLY TEST ANYTHING in 5.0
*
* a more conservative patch for 5.0, full get and list
* sessions in 5.1.
*
* This is kept so that we can at least manually test easily
*/
}
NDBT_TESTSUITE(testMgm);
TESTCASE("SingleUserMode",
"Test single user mode"){
INITIALIZER(runTestSingleUserMode);
FINALIZER(runClearTable);
}
TESTCASE("ApiSessionFailure",
"Test failures in MGMAPI session"){
INITIALIZER(runTestApiSession);
}
NDBT_TESTSUITE_END(testMgm);
int main(int argc, const char** argv){
ndb_init();
myRandom48Init(NdbTick_CurrentMillisecond());
return testMgm.execute(argc, argv);
}
|