Commit 9d9d7582 authored by unknown's avatar unknown

added support for 'show status like 'Ndb%''

added number_of_replicas printout in show table status


mysql-test/r/ndb_alter_table.result:
  added number_of_replicas to show table status printout
mysql-test/r/ndb_autodiscover.result:
  added number_of_replicas to show table status printout
ndb/include/ndbapi/NdbDictionary.hpp:
  added get method for replica count
ndb/include/ndbapi/ndb_cluster_connection.hpp:
  added get method of node id
ndb/src/ndbapi/NdbDictionary.cpp:
  added get method for replica count
ndb/src/ndbapi/ndb_cluster_connection.cpp:
  added get method of node id
parent e1e34b51
...@@ -34,13 +34,13 @@ col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, ...@@ -34,13 +34,13 @@ col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
col6 int not null, to_be_deleted int) ENGINE=ndbcluster; col6 int not null, to_be_deleted int) ENGINE=ndbcluster;
show table status; show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 ndbcluster 10 Dynamic 0 0 0 0 0 0 1 NULL NULL NULL latin1_swedish_ci NULL t1 ndbcluster 10 Dynamic 0 0 0 0 0 0 1 NULL NULL NULL latin1_swedish_ci NULL number_of_replicas: 2
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
insert into t1 values insert into t1 values
(0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7); (0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
show table status; show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 ndbcluster 10 Dynamic 9 96 131072 0 0 0 101 NULL NULL NULL latin1_swedish_ci NULL t1 ndbcluster 10 Dynamic 9 96 131072 0 0 0 101 NULL NULL NULL latin1_swedish_ci NULL number_of_replicas: 2
select * from t1 order by col1; select * from t1 order by col1;
col1 col2 col3 col4 col5 col6 to_be_deleted col1 col2 col3 col4 col5 col6 to_be_deleted
0 4 3 5 PENDING 1 7 0 4 3 5 PENDING 1 7
...@@ -60,7 +60,7 @@ change column col2 fourth varchar(30) not null after col3, ...@@ -60,7 +60,7 @@ change column col2 fourth varchar(30) not null after col3,
modify column col6 int not null first; modify column col6 int not null first;
show table status; show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 ndbcluster 10 Dynamic 9 152 131072 0 0 0 102 NULL NULL NULL latin1_swedish_ci NULL t1 ndbcluster 10 Dynamic 9 152 131072 0 0 0 102 NULL NULL NULL latin1_swedish_ci NULL number_of_replicas: 2
select * from t1 order by col1; select * from t1 order by col1;
col6 col1 col3 fourth col4 col4_5 col5 col7 col8 col6 col1 col3 fourth col4 col4_5 col5 col7 col8
1 0 3 4 5 PENDING 0000-00-00 00:00:00 1 0 3 4 5 PENDING 0000-00-00 00:00:00
...@@ -75,7 +75,7 @@ col6 col1 col3 fourth col4 col4_5 col5 col7 col8 ...@@ -75,7 +75,7 @@ col6 col1 col3 fourth col4 col4_5 col5 col7 col8
insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00');
show table status; show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 ndbcluster 10 Dynamic 10 152 131072 0 0 0 103 NULL NULL NULL latin1_swedish_ci NULL t1 ndbcluster 10 Dynamic 10 152 131072 0 0 0 103 NULL NULL NULL latin1_swedish_ci NULL number_of_replicas: 2
select * from t1 order by col1; select * from t1 order by col1;
col6 col1 col3 fourth col4 col4_5 col5 col7 col8 col6 col1 col3 fourth col4 col4_5 col5 col7 col8
1 0 3 4 5 PENDING 0000-00-00 00:00:00 1 0 3 4 5 PENDING 0000-00-00 00:00:00
......
...@@ -145,7 +145,7 @@ flush tables; ...@@ -145,7 +145,7 @@ flush tables;
show table status; show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t6 MyISAM 9 Fixed 1 260 # # # 0 NULL # # NULL # NULL t6 MyISAM 9 Fixed 1 260 # # # 0 NULL # # NULL # NULL
t7 ndbcluster 9 Fixed 1 276 # # # 0 NULL # # NULL # NULL t7 ndbcluster 9 Fixed 1 276 # # # 0 NULL # # NULL # NULL number_of_replicas: 2
show status like 'handler_discover%'; show status like 'handler_discover%';
Variable_name Value Variable_name Value
Handler_discover 2 Handler_discover 2
......
...@@ -715,6 +715,8 @@ public: ...@@ -715,6 +715,8 @@ public:
int getRowSizeInBytes() const ; int getRowSizeInBytes() const ;
int createTableInDb(Ndb*, bool existingEqualIsOk = true) const ; int createTableInDb(Ndb*, bool existingEqualIsOk = true) const ;
int getReplicaCount() const ;
#endif #endif
private: private:
......
...@@ -86,6 +86,7 @@ public: ...@@ -86,6 +86,7 @@ public:
void set_optimized_node_selection(int val); void set_optimized_node_selection(int val);
unsigned no_db_nodes(); unsigned no_db_nodes();
unsigned node_id();
#endif #endif
private: private:
......
...@@ -432,6 +432,11 @@ NdbDictionary::Table::getRowSizeInBytes() const { ...@@ -432,6 +432,11 @@ NdbDictionary::Table::getRowSizeInBytes() const {
return sz * 4; return sz * 4;
} }
int
NdbDictionary::Table::getReplicaCount() const {
return m_impl.m_replicaCount;
}
int int
NdbDictionary::Table::createTableInDb(Ndb* pNdb, bool equalOk) const { NdbDictionary::Table::createTableInDb(Ndb* pNdb, bool equalOk) const {
const NdbDictionary::Table * pTab = const NdbDictionary::Table * pTab =
......
...@@ -183,6 +183,12 @@ Ndb_cluster_connection::no_db_nodes() ...@@ -183,6 +183,12 @@ Ndb_cluster_connection::no_db_nodes()
return m_impl.m_all_nodes.size(); return m_impl.m_all_nodes.size();
} }
unsigned
Ndb_cluster_connection::node_id()
{
return m_impl.m_transporter_facade->ownId();
}
int int
Ndb_cluster_connection::wait_until_ready(int timeout, Ndb_cluster_connection::wait_until_ready(int timeout,
......
...@@ -105,6 +105,33 @@ struct Ndb_statistics { ...@@ -105,6 +105,33 @@ struct Ndb_statistics {
Uint64 fragment_memory; Uint64 fragment_memory;
}; };
/* Status variables shown with 'show status like 'Ndb%' */
static long ndb_cluster_node_id= 0;
static const char * ndb_connected_host= 0;
static long ndb_connected_port= 0;
static long ndb_number_of_replicas= 0;
static long ndb_number_of_storage_nodes= 0;
static int update_status_variables(Ndb_cluster_connection *c)
{
ndb_cluster_node_id= c->node_id();
ndb_connected_port= c->get_connected_port();
ndb_connected_host= c->get_connected_host();
ndb_number_of_replicas= 0;
ndb_number_of_storage_nodes= c->no_db_nodes();
return 0;
}
struct show_var_st ndb_status_variables[]= {
{"cluster_node_id", (char*) &ndb_cluster_node_id, SHOW_LONG},
{"connected_host", (char*) &ndb_connected_host, SHOW_CHAR_PTR},
{"connected_port", (char*) &ndb_connected_port, SHOW_LONG},
// {"number_of_replicas", (char*) &ndb_number_of_replicas, SHOW_LONG},
{"number_of_storage_nodes",(char*) &ndb_number_of_storage_nodes, SHOW_LONG},
{NullS, NullS, SHOW_LONG}
};
/* /*
Error handling functions Error handling functions
*/ */
...@@ -4056,6 +4083,8 @@ Thd_ndb* ha_ndbcluster::seize_thd_ndb() ...@@ -4056,6 +4083,8 @@ Thd_ndb* ha_ndbcluster::seize_thd_ndb()
thd_ndb= new Thd_ndb(); thd_ndb= new Thd_ndb();
thd_ndb->ndb->getDictionary()->set_local_table_data_size(sizeof(Ndb_table_local_info)); thd_ndb->ndb->getDictionary()->set_local_table_data_size(sizeof(Ndb_table_local_info));
if (thd_ndb->ndb->init(max_transactions) != 0) if (thd_ndb->ndb->init(max_transactions) != 0)
{ {
ERR_PRINT(thd_ndb->ndb->getNdbError()); ERR_PRINT(thd_ndb->ndb->getNdbError());
...@@ -4381,6 +4410,13 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path, ...@@ -4381,6 +4410,13 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path,
a NDB Cluster table handler a NDB Cluster table handler
*/ */
/* Call back after cluster connect */
static int connect_callback()
{
update_status_variables(g_ndb_cluster_connection);
return 0;
}
bool ndbcluster_init() bool ndbcluster_init()
{ {
int res; int res;
...@@ -4410,6 +4446,7 @@ bool ndbcluster_init() ...@@ -4410,6 +4446,7 @@ bool ndbcluster_init()
if ((res= g_ndb_cluster_connection->connect(0,0,0)) == 0) if ((res= g_ndb_cluster_connection->connect(0,0,0)) == 0)
{ {
connect_callback();
DBUG_PRINT("info",("NDBCLUSTER storage engine at %s on port %d", DBUG_PRINT("info",("NDBCLUSTER storage engine at %s on port %d",
g_ndb_cluster_connection->get_connected_host(), g_ndb_cluster_connection->get_connected_host(),
g_ndb_cluster_connection->get_connected_port())); g_ndb_cluster_connection->get_connected_port()));
...@@ -4417,7 +4454,7 @@ bool ndbcluster_init() ...@@ -4417,7 +4454,7 @@ bool ndbcluster_init()
} }
else if(res == 1) else if(res == 1)
{ {
if (g_ndb_cluster_connection->start_connect_thread()) if (g_ndb_cluster_connection->start_connect_thread(connect_callback))
{ {
DBUG_PRINT("error", ("g_ndb_cluster_connection->start_connect_thread()")); DBUG_PRINT("error", ("g_ndb_cluster_connection->start_connect_thread()"));
goto ndbcluster_init_error; goto ndbcluster_init_error;
...@@ -5285,25 +5322,38 @@ ha_ndbcluster::update_table_comment( ...@@ -5285,25 +5322,38 @@ ha_ndbcluster::update_table_comment(
/* out: table comment + additional */ /* out: table comment + additional */
const char* comment)/* in: table comment defined by user */ const char* comment)/* in: table comment defined by user */
{ {
return (char*)comment;
#if 0 // for the future
uint length= strlen(comment); uint length= strlen(comment);
if(length > 64000 - 3) if(length > 64000 - 3)
{ {
return((char*)comment); /* string too long */ return((char*)comment); /* string too long */
} }
Ndb* ndb;
if (!(ndb= get_ndb()))
{
return((char*)comment);
}
ndb->setDatabaseName(m_dbname);
NDBDICT* dict= ndb->getDictionary();
const NDBTAB* tab;
if (!(tab= dict->getTable(m_tabname)))
{
return((char*)comment);
}
char *str; char *str;
const char *fmt="%s%sRow size: %d"; const char *fmt="%s%snumber_of_replicas: %d";
const unsigned fmt_len_plus_extra= length + strlen(fmt) + 3; const unsigned fmt_len_plus_extra= length + strlen(fmt);
if ((str= my_malloc(fmt_len_plus_extra, MYF(0))) == NULL) if ((str= my_malloc(fmt_len_plus_extra, MYF(0))) == NULL)
{ {
return (char*)comment; return (char*)comment;
} }
snprintf(str,fmt_len_plus_extra,fmt,comment,10); snprintf(str,fmt_len_plus_extra,fmt,comment,
length > 0 ? " ":"",
tab->getReplicaCount());
return str; return str;
#endif
} }
#endif /* HAVE_NDBCLUSTER_DB */ #endif /* HAVE_NDBCLUSTER_DB */
...@@ -279,6 +279,8 @@ class ha_ndbcluster: public handler ...@@ -279,6 +279,8 @@ class ha_ndbcluster: public handler
friend int execute_no_commit_ie(ha_ndbcluster*, NdbTransaction*); friend int execute_no_commit_ie(ha_ndbcluster*, NdbTransaction*);
}; };
extern struct show_var_st ndb_status_variables[];
bool ndbcluster_init(void); bool ndbcluster_init(void);
bool ndbcluster_end(void); bool ndbcluster_end(void);
......
...@@ -5609,6 +5609,9 @@ struct show_var_st status_vars[]= { ...@@ -5609,6 +5609,9 @@ struct show_var_st status_vars[]= {
SHOW_KEY_CACHE_LONG}, SHOW_KEY_CACHE_LONG},
{"Last_query_cost", (char*) &last_query_cost, SHOW_DOUBLE}, {"Last_query_cost", (char*) &last_query_cost, SHOW_DOUBLE},
{"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG},
#ifdef HAVE_NDBCLUSTER_DB
{"Ndb_", (char*) &ndb_status_variables, SHOW_VARS},
#endif /*HAVE_NDBCLUSTER_DB*/
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_CONST}, {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_CONST},
{"Open_files", (char*) &my_file_opened, SHOW_LONG_CONST}, {"Open_files", (char*) &my_file_opened, SHOW_LONG_CONST},
{"Open_streams", (char*) &my_stream_opened, SHOW_LONG_CONST}, {"Open_streams", (char*) &my_stream_opened, SHOW_LONG_CONST},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment