Skip to content

Commit 25843cf

Browse files
committed
WL#7575 Remove ndbinfo's usage of other engine
- Improve creation of the virtual tables as much as possible wihtout having to rewrite NdbInfoScanNodes too much. I.e makeing it as easy as possible to add new tables.
1 parent 5ec87e4 commit 25843cf

File tree

4 files changed

+126
-84
lines changed

4 files changed

+126
-84
lines changed

storage/ndb/src/ndbapi/NdbInfo.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ bool NdbInfo::init(void)
4141
return false;
4242
if (!load_hardcoded_tables())
4343
return false;
44-
if (!create_virtual_tables(m_virtual_tables))
44+
if (!NdbInfoScanVirtual::create_virtual_tables(m_virtual_tables))
4545
return false;
4646
return true;
4747
}
4848

4949
NdbInfo::~NdbInfo(void)
5050
{
51-
delete_virtual_tables(m_virtual_tables);
51+
NdbInfoScanVirtual::delete_virtual_tables(m_virtual_tables);
5252
native_mutex_destroy(&m_mutex);
5353
}
5454

@@ -611,5 +611,32 @@ const NdbInfo::Column* NdbInfo::Table::getColumn(const char * name) const
611611
}
612612

613613

614+
const VirtualTable* NdbInfo::Table::getVirtualTable() const
615+
{
616+
return m_virt;
617+
}
618+
619+
620+
bool NdbInfo::load_virtual_tables(void)
621+
{
622+
// The virtual tables should already have been created
623+
assert(m_virtual_tables.size() > 0);
624+
625+
// Append the virtual tables to the list of tables
626+
for (size_t i = 0; i < m_virtual_tables.size(); i++)
627+
{
628+
Table* tab = m_virtual_tables[i];
629+
assert(tab->m_virt);
630+
assert(tab->m_table_id == Table::InvalidTableId);
631+
632+
BaseString hash_key = mysql_table_name(tab->getName());
633+
tab->m_table_id = m_tables.entries(); // Set increasing table id
634+
if (!m_tables.insert(hash_key.c_str(), *tab))
635+
return false;
636+
}
637+
638+
return true;
639+
}
640+
614641
template class Vector<NdbInfo::Column*>;
615642

storage/ndb/src/ndbapi/NdbInfo.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class NdbInfo
7878
const Column* getColumn(const unsigned attributeId) const;
7979
const Column* getColumn(const char * name) const;
8080

81+
const class VirtualTable* getVirtualTable() const;
82+
8183
private:
8284
friend class NdbInfo;
8385
BaseString m_name;
@@ -127,8 +129,6 @@ class NdbInfo
127129
BaseString mysql_table_name(const char* table_name) const;
128130

129131
Vector<Table*> m_virtual_tables;
130-
static bool create_virtual_tables(Vector<Table*>& list);
131-
static void delete_virtual_tables(Vector<Table*>& list);
132132

133133
};
134134

storage/ndb/src/ndbapi/NdbInfoScanVirtual.cpp

+92-80
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class VirtualTable
140140
bool check_buffer_space(size_t len) const;
141141
};
142142

143+
/*
144+
Return the NdbInfo::Table corresponding to this virtual table
145+
*/
146+
virtual NdbInfo::Table* get_instance() const = 0;
147+
143148
/*
144149
Read one row from the virtual table
145150
@@ -322,28 +327,6 @@ NdbInfoScanVirtual::~NdbInfoScanVirtual()
322327
}
323328

324329

325-
bool NdbInfo::load_virtual_tables(void)
326-
{
327-
// The virtual tables should already have been created
328-
assert(m_virtual_tables.size() > 0);
329-
330-
// Append the virtual tables to the list of tables
331-
for (size_t i = 0; i < m_virtual_tables.size(); i++)
332-
{
333-
Table* tab = m_virtual_tables[i];
334-
assert(tab->m_virt);
335-
assert(tab->m_table_id == Table::InvalidTableId);
336-
337-
BaseString hash_key = mysql_table_name(tab->getName());
338-
tab->m_table_id = m_tables.entries(); // Set increasing table id
339-
if (!m_tables.insert(hash_key.c_str(), *tab))
340-
return false;
341-
}
342-
343-
return true;
344-
}
345-
346-
347330
#include "../src/common/debugger/BlockNames.cpp"
348331
class BlocksTable : public VirtualTable
349332
{
@@ -362,6 +345,21 @@ class BlocksTable : public VirtualTable
362345
w.write_string(bn.name);
363346
return true;
364347
}
348+
349+
NdbInfo::Table* get_instance() const
350+
{
351+
NdbInfo::Table* tab = new NdbInfo::Table("blocks",
352+
NdbInfo::Table::InvalidTableId,
353+
this);
354+
if (!tab)
355+
return NULL;
356+
if (!tab->addColumn(NdbInfo::Column("block_number", 0,
357+
NdbInfo::Column::Number)) ||
358+
!tab->addColumn(NdbInfo::Column("block_name", 1,
359+
NdbInfo::Column::String)))
360+
return NULL;
361+
return tab;
362+
}
365363
};
366364

367365

@@ -377,7 +375,7 @@ class DictObjTypesTable : public VirtualTable
377375
const char* name;
378376
};
379377

380-
Entry entries[] =
378+
static const Entry entries[] =
381379
{
382380
{DictTabInfo::SystemTable, "System table"},
383381
{DictTabInfo::UserTable, "User table"},
@@ -412,6 +410,21 @@ class DictObjTypesTable : public VirtualTable
412410
w.write_string(e.name);
413411
return true;
414412
}
413+
414+
NdbInfo::Table* get_instance() const
415+
{
416+
NdbInfo::Table* tab = new NdbInfo::Table("dict_obj_types",
417+
NdbInfo::Table::InvalidTableId,
418+
this);
419+
if (!tab)
420+
return NULL;
421+
if (!tab->addColumn(NdbInfo::Column("type_id", 0,
422+
NdbInfo::Column::Number)) ||
423+
!tab->addColumn(NdbInfo::Column("type_name", 1,
424+
NdbInfo::Column::String)))
425+
return NULL;
426+
return tab;
427+
}
415428
};
416429

417430

@@ -457,6 +470,22 @@ class ConfigParamsTable : public VirtualTable
457470
w.write_string(param->_fname);
458471
return true;
459472
}
473+
474+
475+
NdbInfo::Table* get_instance() const
476+
{
477+
NdbInfo::Table* tab = new NdbInfo::Table("config_params",
478+
NdbInfo::Table::InvalidTableId,
479+
this);
480+
if (!tab)
481+
return NULL;
482+
if (!tab->addColumn(NdbInfo::Column("param_number", 0,
483+
NdbInfo::Column::Number)) ||
484+
!tab->addColumn(NdbInfo::Column("param_name", 1,
485+
NdbInfo::Column::String)))
486+
return NULL;
487+
return tab;
488+
}
460489
};
461490

462491

@@ -468,11 +497,14 @@ class NdbkernelStateDescTable : public VirtualTable
468497
const ndbkernel_state_desc* m_array;
469498
// Number of elements in the the array
470499
size_t m_array_count;
500+
const char* m_table_name;
471501
public:
472502

473-
NdbkernelStateDescTable(const ndbkernel_state_desc* null_terminated_array) :
503+
NdbkernelStateDescTable(const char* table_name,
504+
const ndbkernel_state_desc* null_terminated_array) :
474505
m_array(null_terminated_array),
475-
m_array_count(0)
506+
m_array_count(0),
507+
m_table_name(table_name)
476508
{
477509
while(m_array[m_array_count].name != 0)
478510
m_array_count++;
@@ -495,6 +527,25 @@ class NdbkernelStateDescTable : public VirtualTable
495527

496528
return true;
497529
}
530+
531+
NdbInfo::Table* get_instance() const
532+
{
533+
NdbInfo::Table* tab = new NdbInfo::Table(m_table_name,
534+
NdbInfo::Table::InvalidTableId,
535+
this);
536+
if (!tab)
537+
return NULL;
538+
if (!tab->addColumn(NdbInfo::Column("state_int_value", 0,
539+
NdbInfo::Column::Number)) ||
540+
!tab->addColumn(NdbInfo::Column("state_name", 1,
541+
NdbInfo::Column::String)) ||
542+
!tab->addColumn(NdbInfo::Column("state_friendly_name", 2,
543+
NdbInfo::Column::String)) ||
544+
!tab->addColumn(NdbInfo::Column("state_description", 3,
545+
NdbInfo::Column::String)))
546+
return NULL;
547+
return tab;
548+
}
498549
};
499550

500551

@@ -505,25 +556,19 @@ class NdbkernelStateDescTable : public VirtualTable
505556
is copied between instances of Table so that all Table instances
506557
use the same Virtual.
507558
508-
The Virtual tables are created during in NdbInfo::init() and destroyed
559+
The Virtual tables are created in NdbInfo::init() and destroyed
509560
by ~NdbInfo(). NdbInfo keeps them in a list which is passed to both
510561
the create and destroy functions.
511562
*/
512-
bool NdbInfo::create_virtual_tables(Vector<Table*>& list)
563+
bool
564+
NdbInfoScanVirtual::create_virtual_tables(Vector<NdbInfo::Table*>& list)
513565
{
514566
{
515567
BlocksTable* blocksTable = new BlocksTable;
516568
if (!blocksTable)
517569
return false;
518570

519-
Table* tab = new Table("blocks", Table::InvalidTableId, blocksTable);
520-
if (!tab)
521-
return false;
522-
if (!tab->addColumn(Column("block_number", 0, Column::Number)) ||
523-
!tab->addColumn(Column("block_name", 1, Column::String)))
524-
return false;
525-
526-
if (list.push_back(tab) != 0)
571+
if (list.push_back(blocksTable->get_instance()) != 0)
527572
return false;
528573
}
529574

@@ -532,15 +577,7 @@ bool NdbInfo::create_virtual_tables(Vector<Table*>& list)
532577
if (!dictObjTypesTable)
533578
return false;
534579

535-
Table* tab = new Table("dict_obj_types", Table::InvalidTableId,
536-
dictObjTypesTable);
537-
if (!tab)
538-
return false;
539-
if (!tab->addColumn(Column("type_id", 0, Column::Number)) ||
540-
!tab->addColumn(Column("type_name", 1, Column::String)))
541-
return false;
542-
543-
if (list.push_back(tab) != 0)
580+
if (list.push_back(dictObjTypesTable->get_instance()) != 0)
544581
return false;
545582
}
546583

@@ -551,55 +588,29 @@ bool NdbInfo::create_virtual_tables(Vector<Table*>& list)
551588
if (!configParamsTable->init())
552589
return false;
553590

554-
Table* tab = new Table("config_params", Table::InvalidTableId,
555-
configParamsTable);
556-
if (!tab)
557-
return false;
558-
if (!tab->addColumn(Column("param_number", 0, Column::Number)) ||
559-
!tab->addColumn(Column("param_name", 1, Column::String)))
560-
return false;
561-
562-
if (list.push_back(tab) != 0)
591+
if (list.push_back(configParamsTable->get_instance()) != 0)
563592
return false;
564593
}
565594

566595
{
567596
NdbkernelStateDescTable* dbtcApiConnectStateTable =
568-
new NdbkernelStateDescTable(g_dbtc_apiconnect_state_desc);
597+
new NdbkernelStateDescTable("dbtc_apiconnect_state",
598+
g_dbtc_apiconnect_state_desc);
569599
if (!dbtcApiConnectStateTable)
570600
return false;
571601

572-
Table* tab = new Table("dbtc_apiconnect_state", Table::InvalidTableId,
573-
dbtcApiConnectStateTable);
574-
if (!tab)
575-
return false;
576-
if (!tab->addColumn(Column("state_int_value", 0, Column::Number)) ||
577-
!tab->addColumn(Column("state_name", 1, Column::String)) ||
578-
!tab->addColumn(Column("state_friendly_name", 2, Column::String)) ||
579-
!tab->addColumn(Column("state_description", 3, Column::String)))
580-
return false;
581-
582-
if (list.push_back(tab) != 0)
602+
if (list.push_back(dbtcApiConnectStateTable->get_instance()) != 0)
583603
return false;
584604
}
585605

586606
{
587607
NdbkernelStateDescTable* dblqhTcConnectStateTable =
588-
new NdbkernelStateDescTable(g_dblqh_tcconnect_state_desc);
608+
new NdbkernelStateDescTable("dblqh_tcconnect_state",
609+
g_dblqh_tcconnect_state_desc);
589610
if (!dblqhTcConnectStateTable)
590611
return false;
591612

592-
Table* tab = new Table("dblqh_tcconnect_state", Table::InvalidTableId,
593-
dblqhTcConnectStateTable);
594-
if (!tab)
595-
return false;
596-
if (!tab->addColumn(Column("state_int_value", 0, Column::Number)) ||
597-
!tab->addColumn(Column("state_name", 1, Column::String)) ||
598-
!tab->addColumn(Column("state_friendly_name", 2, Column::String)) ||
599-
!tab->addColumn(Column("state_description", 3, Column::String)))
600-
return false;
601-
602-
if (list.push_back(tab) != 0)
613+
if (list.push_back(dblqhTcConnectStateTable->get_instance()) != 0)
603614
return false;
604615
}
605616
return true;
@@ -608,12 +619,13 @@ bool NdbInfo::create_virtual_tables(Vector<Table*>& list)
608619
/*
609620
Delete the virtual part of the tables in list
610621
*/
611-
void NdbInfo::delete_virtual_tables(Vector<Table*>& list)
622+
void NdbInfoScanVirtual::delete_virtual_tables(Vector<NdbInfo::Table*>& list)
612623
{
613624
for (unsigned i = 0; i < list.size(); i++)
614625
{
615-
Table* tab = list[i];
616-
delete tab->m_virt;
626+
NdbInfo::Table* tab = list[i];
627+
const VirtualTable* virt = tab->getVirtualTable();
628+
delete virt;
617629
delete tab;
618630
}
619631
list.clear();

storage/ndb/src/ndbapi/NdbInfoScanVirtual.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class NdbInfoScanVirtual : public NdbInfoScanOperation {
3737
NdbInfoScanVirtual(const NdbInfo::Table* table,
3838
const class VirtualTable* virt);
3939
int init();
40+
41+
static bool create_virtual_tables(Vector<NdbInfo::Table*>& list);
42+
static void delete_virtual_tables(Vector<NdbInfo::Table*>& list);
4043
private:
4144
enum State { Undefined, Initial, Prepared,
4245
MoreData, End } m_state;

0 commit comments

Comments
 (0)