2115
runBug21755(NDBT_Context* ctx, NDBT_Step* step)
2119
NdbDictionary::Table pTab0 = * ctx->getTab();
2120
NdbDictionary::Table pTab1 = pTab0;
2122
if (res.getNumDbNodes() < 2)
2125
Ndb* pNdb = GETNDB(step);
2126
NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
2128
if (pDic->createTable(pTab0))
2130
ndbout << pDic->getNdbError() << endl;
2134
NdbDictionary::Index idx0;
2135
BaseString::snprintf(buf, sizeof(buf), "%s-idx", pTab0.getName());
2137
idx0.setType(NdbDictionary::Index::OrderedIndex);
2138
idx0.setTable(pTab0.getName());
2139
idx0.setStoredIndex(false);
2140
for (Uint32 i = 0; i<pTab0.getNoOfColumns(); i++)
2142
const NdbDictionary::Column * col = pTab0.getColumn(i);
2143
if(col->getPrimaryKey()){
2144
idx0.addIndexColumn(col->getName());
2148
if (pDic->createIndex(idx0))
2150
ndbout << pDic->getNdbError() << endl;
2154
BaseString::snprintf(buf, sizeof(buf), "%s-2", pTab1.getName());
2157
if (pDic->createTable(pTab1))
2159
ndbout << pDic->getNdbError() << endl;
2164
HugoTransactions t0 (*pDic->getTable(pTab0.getName()));
2165
t0.loadTable(pNdb, 1000);
2169
HugoTransactions t1 (*pDic->getTable(pTab1.getName()));
2170
t1.loadTable(pNdb, 1000);
2173
int node = res.getRandomNotMasterNodeId(rand());
2174
res.restartOneDbNode(node, false, true, true);
2176
if (pDic->dropTable(pTab1.getName()))
2178
ndbout << pDic->getNdbError() << endl;
2182
BaseString::snprintf(buf, sizeof(buf), "%s-idx2", pTab0.getName());
2184
if (pDic->createIndex(idx0))
2186
ndbout << pDic->getNdbError() << endl;
2190
res.waitNodesNoStart(&node, 1);
2191
res.startNodes(&node, 1);
2193
if (res.waitClusterStarted())
2198
if (pDic->dropTable(pTab0.getName()))
2200
ndbout << pDic->getNdbError() << endl;
2213
struct Obj* m_parent;
2214
Vector<Obj*> m_dependant;
2217
Vector<Obj*> m_objects;
2219
int schema_op(Ndb*);
2223
Obj* get_obj(Uint32 mask);
2224
int create_table(Ndb*);
2225
int create_index(Ndb*, Obj*);
2226
int drop_obj(Ndb*, Obj*);
2228
void remove_obj(Obj*);
2231
template class Vector<RandSchemaOp::Obj*>;
2234
RandSchemaOp::schema_op(Ndb* ndb)
2236
struct Obj* obj = 0;
2239
switch((rand() >> 16) & 3){
2241
return create_table(ndb);
2243
if ((obj = get_obj(1 << NdbDictionary::Object::UserTable)) == 0)
2245
return create_index(ndb, obj);
2247
type = (1 << NdbDictionary::Object::UserTable);
2251
(1 << NdbDictionary::Object::UniqueHashIndex) |
2252
(1 << NdbDictionary::Object::OrderedIndex);
2259
if ((obj = get_obj(type)) == 0)
2261
return drop_obj(ndb, obj);
2265
RandSchemaOp::get_obj(Uint32 mask)
2268
for (Uint32 i = 0; i<m_objects.size(); i++)
2270
if ((1 << m_objects[i]->m_type) & mask)
2271
tmp.push_back(m_objects[i]);
2276
return tmp[rand()%tmp.size()];
2282
RandSchemaOp::create_table(Ndb* ndb)
2284
int numTables = NDBT_Tables::getNumTables();
2285
int num = myRandom48(numTables);
2286
NdbDictionary::Table pTab = * NDBT_Tables::getTable(num);
2288
NdbDictionary::Dictionary* pDict = ndb->getDictionary();
2290
if (pDict->getTable(pTab.getName()))
2293
BaseString::snprintf(buf, sizeof(buf), "%s-%d",
2294
pTab.getName(), rand());
2296
if (pDict->createTable(pTab))
2301
if (NDBT_Tables::createTable(ndb, pTab.getName()))
2307
ndbout_c("create table %s", pTab.getName());
2308
const NdbDictionary::Table* tab2 = pDict->getTable(pTab.getName());
2309
HugoTransactions trans(*tab2);
2310
trans.loadTable(ndb, 1000);
2313
obj->m_name.assign(pTab.getName());
2314
obj->m_type = NdbDictionary::Object::UserTable;
2316
m_objects.push_back(obj);
2322
RandSchemaOp::create_index(Ndb* ndb, Obj* tab)
2324
NdbDictionary::Dictionary* pDict = ndb->getDictionary();
2325
const NdbDictionary::Table * pTab = pDict->getTable(tab->m_name.c_str());
2332
bool ordered = (rand() >> 16) & 1;
2333
bool stored = (rand() >> 16) & 1;
2335
Uint32 type = ordered ?
2336
NdbDictionary::Index::OrderedIndex :
2337
NdbDictionary::Index::UniqueHashIndex;
2340
BaseString::snprintf(buf, sizeof(buf), "%s-%s",
2342
ordered ? "OI" : "UI");
2344
if (pDict->getIndex(buf, pTab->getName()))
2346
// Index exists...let it be ok
2350
ndbout_c("create index %s", buf);
2351
NdbDictionary::Index idx0;
2353
idx0.setType((NdbDictionary::Index::Type)type);
2354
idx0.setTable(pTab->getName());
2355
idx0.setStoredIndex(ordered ? false : stored);
2357
for (Uint32 i = 0; i<pTab->getNoOfColumns(); i++)
2359
if (pTab->getColumn(i)->getPrimaryKey())
2360
idx0.addColumn(pTab->getColumn(i)->getName());
2362
if (pDict->createIndex(idx0))
2364
ndbout << pDict->getNdbError() << endl;
2368
obj->m_name.assign(buf);
2370
obj->m_parent = tab;
2371
m_objects.push_back(obj);
2373
tab->m_dependant.push_back(obj);
2378
RandSchemaOp::drop_obj(Ndb* ndb, Obj* obj)
2380
NdbDictionary::Dictionary* pDict = ndb->getDictionary();
2382
if (obj->m_type == NdbDictionary::Object::UserTable)
2384
ndbout_c("drop table %s", obj->m_name.c_str());
2386
* Drop of table automatically drops all indexes
2388
if (pDict->dropTable(obj->m_name.c_str()))
2392
while(obj->m_dependant.size())
2394
remove_obj(obj->m_dependant[0]);
2398
else if (obj->m_type == NdbDictionary::Object::UniqueHashIndex ||
2399
obj->m_type == NdbDictionary::Object::OrderedIndex)
2401
ndbout_c("drop index %s", obj->m_name.c_str());
2402
if (pDict->dropIndex(obj->m_name.c_str(),
2403
obj->m_parent->m_name.c_str()))
2413
RandSchemaOp::remove_obj(Obj* obj)
2419
for (i = 0; i<obj->m_parent->m_dependant.size(); i++)
2421
if (obj->m_parent->m_dependant[i] == obj)
2424
obj->m_parent->m_dependant.erase(i);
2433
for (i = 0; i<m_objects.size(); i++)
2435
if (m_objects[i] == obj)
2448
RandSchemaOp::validate(Ndb* ndb)
2450
NdbDictionary::Dictionary* pDict = ndb->getDictionary();
2451
for (Uint32 i = 0; i<m_objects.size(); i++)
2453
if (m_objects[i]->m_type == NdbDictionary::Object::UserTable)
2455
const NdbDictionary::Table* tab2 =
2456
pDict->getTable(m_objects[i]->m_name.c_str());
2457
HugoTransactions trans(*tab2);
2458
trans.scanUpdateRecords(ndb, 1000);
2459
trans.clearTable(ndb);
2460
trans.loadTable(ndb, 1000);
2468
SystemTable = 1, ///< System table
2469
UserTable = 2, ///< User table (may be temporary)
2470
UniqueHashIndex = 3, ///< Unique un-ordered hash index
2471
OrderedIndex = 6, ///< Non-unique ordered index
2472
HashIndexTrigger = 7, ///< Index maintenance, internal
2473
IndexTrigger = 8, ///< Index maintenance, internal
2474
SubscriptionTrigger = 9,///< Backup or replication, internal
2475
ReadOnlyConstraint = 10,///< Trigger, internal
2476
Tablespace = 20, ///< Tablespace
2477
LogfileGroup = 21, ///< Logfile group
2478
Datafile = 22, ///< Datafile
2479
Undofile = 23 ///< Undofile
2483
RandSchemaOp::cleanup(Ndb* ndb)
2486
for (i = m_objects.size() - 1; i >= 0; i--)
2488
switch(m_objects[i]->m_type){
2489
case NdbDictionary::Object::UniqueHashIndex:
2490
case NdbDictionary::Object::OrderedIndex:
2491
if (drop_obj(ndb, m_objects[i]))
2500
for (i = m_objects.size() - 1; i >= 0; i--)
2502
switch(m_objects[i]->m_type){
2503
case NdbDictionary::Object::UserTable:
2504
if (drop_obj(ndb, m_objects[i]))
2512
assert(m_objects.size() == 0);
2517
runDictRestart(NDBT_Context* ctx, NDBT_Step* step)
2519
Ndb* pNdb = GETNDB(step);
2520
int loops = ctx->getNumLoops();
2522
NdbMixRestarter res;
2525
if (res.getNumDbNodes() < 2)
2528
if (res.init(ctx, step))
2531
for (Uint32 i = 0; i<loops; i++)
2533
for (Uint32 j = 0; j<10; j++)
2534
if (dict.schema_op(pNdb))
2537
if (res.dostep(ctx, step))
2540
if (dict.validate(pNdb))
2544
if (res.finish(ctx, step))
2547
if (dict.validate(pNdb))
2550
if (dict.cleanup(pNdb))
2113
2556
NDBT_TESTSUITE(testDict);
2114
2557
TESTCASE("CreateAndDrop",
2115
2558
"Try to create and drop the table loop number of times\n"){