summaryrefslogtreecommitdiff
path: root/ndb/src/mgmsrv/main.cpp
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-09-06 15:14:10 +0300
committerunknown <monty@mysql.com>2004-09-06 15:14:10 +0300
commit4ad51359c1b7b5ed854f1af8df06fd6912068d28 (patch)
treed9ef905036723648a1d354d0523ef8124e4dee76 /ndb/src/mgmsrv/main.cpp
parentfa3bfbe45796edd85cce30e62ff1fcfb81df745c (diff)
parent9a63c8e0e468d7a64dcb7e23f4e5c344eebf635b (diff)
downloadmariadb-git-4ad51359c1b7b5ed854f1af8df06fd6912068d28.tar.gz
Merge with 4.1
(Includes merge of arena code in 4.1 and 5.0) BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union VC++Files/sql/mysqld.dsp: Auto merged client/mysql.cc: Auto merged client/mysqltest.c: Auto merged include/my_global.h: Auto merged include/my_sys.h: Auto merged include/mysql.h: Auto merged include/mysql_com.h: Auto merged innobase/row/row0sel.c: Auto merged libmysql/client_settings.h: Auto merged libmysql/libmysql.c: Auto merged libmysqld/Makefile.am: Auto merged libmysqld/examples/Makefile.am: Auto merged libmysqld/lib_sql.cc: Auto merged myisam/mi_check.c: Auto merged myisam/myisamchk.c: Auto merged myisam/sort.c: Auto merged mysql-test/r/connect.result: Auto merged mysql-test/r/ctype_recoding.result: Auto merged mysql-test/r/ctype_ucs.result: Auto merged mysql-test/r/func_in.result: Auto merged mysql-test/r/func_like.result: Auto merged mysql-test/r/gis.result: Auto merged mysql-test/r/having.result: Auto merged mysql-test/r/heap.result: Auto merged mysql-test/r/join.result: Auto merged mysql-test/r/key.result: Auto merged mysql-test/r/lowercase_table.result: Auto merged mysql-test/r/ndb_autodiscover.result: Auto merged mysql-test/r/null.result: Auto merged mysql-test/r/olap.result: Auto merged mysql-test/r/order_by.result: Auto merged mysql-test/r/ps_1general.result: Auto merged mysql-test/r/ps_2myisam.result: Auto merged mysql-test/r/ps_3innodb.result: Auto merged mysql-test/r/ps_4heap.result: Auto merged mysql-test/r/ps_5merge.result: Auto merged mysql-test/r/ps_6bdb.result: Auto merged mysql-test/r/range.result: Auto merged mysql-test/r/rename.result: Auto merged mysql-test/r/show_check.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/union.result: Auto merged mysql-test/r/variables.result: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/null.test: Auto merged mysql-test/t/ps_1general.test: Auto merged mysql-test/t/rpl_charset.test: Auto merged mysql-test/t/rpl_heap.test: Auto merged mysql-test/t/rpl_relayrotate.test: Auto merged mysql-test/t/subselect.test: Auto merged mysql-test/t/variables.test: Auto merged netware/mysql_test_run.c: Auto merged scripts/make_binary_distribution.sh: Auto merged scripts/mysql_create_system_tables.sh: Auto merged scripts/mysql_fix_privilege_tables.sql: Auto merged scripts/mysql_install_db.sh: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.h: Auto merged sql/item_create.cc: Auto merged sql/item_create.h: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_timefunc.cc: Auto merged sql/item_timefunc.h: Auto merged sql/lex.h: Auto merged sql/lock.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql/opt_sum.cc: Auto merged sql/protocol.cc: Auto merged sql/records.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/slave.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_acl.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_list.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_rename.cc: Auto merged sql/sql_select.h: Auto merged sql/sql_show.cc: Auto merged sql/sql_string.h: Auto merged sql/table.cc: Auto merged sql-common/client.c: Auto merged client/mysqlbinlog.cc: Merge with 4.1 configure.in: Merge with 4.1 include/mysqld_error.h: Add new error message (1) from 4.1 mysql-test/mysql-test-run.sh: Merge with 4.1 mysql-test/r/func_gconcat.result: Merge with 4.1 mysql-test/r/func_if.result: Merge with 4.1 mysql-test/r/grant.result: Merge with 4.1 mysql-test/r/join_outer.result: Merge with 4.1 mysql-test/r/rpl_charset.result: Merge with 4.1 (This has to be fixed before pushing) mysql-test/r/system_mysql_db.result: Merge with 4.1. Added collation to new privileges mysql-test/t/grant.test: Merge with 4.1 mysql-test/t/grant_cache.test: Merge with 4.1 mysql-test/t/show_check.test: Merge with 4.1 sql/Makefile.am: Merge with 4.1 sql/item.cc: Merge with 4.1 sql/item_cmpfunc.cc: Merge with 4.1 (arena code) sql/item_subselect.cc: Merge with 4.1 sql/item_subselect.h: Merge with 4.1 sql/item_sum.cc: Merge with 4.1 sql/item_sum.h: Merge with 4.1 sql/log.cc: Merge with 4.1 (Remove code that is not relevant for 5.0) sql/mysqld.cc: Merge with 4.1 sql/opt_range.cc: Merge with 4.1 sql/share/czech/errmsg.txt: Merge with 4.1 sql/share/danish/errmsg.txt: Merge with 4.1 sql/share/dutch/errmsg.txt: Merge with 4.1 sql/share/english/errmsg.txt: Merge with 4.1 sql/share/estonian/errmsg.txt: Merge with 4.1 sql/share/french/errmsg.txt: Merge with 4.1 sql/share/german/errmsg.txt: Merge with 4.1 sql/share/greek/errmsg.txt: Merge with 4.1 sql/share/hungarian/errmsg.txt: Merge with 4.1 sql/share/italian/errmsg.txt: Merge with 4.1 sql/share/japanese/errmsg.txt: Merge with 4.1 sql/share/korean/errmsg.txt: Merge with 4.1 sql/share/norwegian-ny/errmsg.txt: Merge with 4.1 sql/share/norwegian/errmsg.txt: Merge with 4.1 sql/share/polish/errmsg.txt: Merge with 4.1 sql/share/portuguese/errmsg.txt: Merge with 4.1 sql/share/romanian/errmsg.txt: Merge with 4.1 sql/share/russian/errmsg.txt: Merge with 4.1 sql/share/serbian/errmsg.txt: Merge with 4.1 sql/share/slovak/errmsg.txt: Merge with 4.1 sql/share/spanish/errmsg.txt: Merge with 4.1 sql/share/swedish/errmsg.txt: Merge with 4.1 sql/share/ukrainian/errmsg.txt: Merge with 4.1 sql/sql_base.cc: Merge with 4.1 sql/sql_class.cc: Merge with 4.1 Use arena code from 4.1 sql/sql_class.h: Merge with 4.1 Use arena code from 4.1 sql/sql_derived.cc: Merge with 4.1 sql/sql_lex.cc: Merge with 4.1 sql/sql_lex.h: Merge with 4.1 sql/sql_parse.cc: Merge with 4.1 sql/sql_prepare.cc: Merge with 4.1 sql/sql_select.cc: Merge with 4.1 sql/sql_table.cc: Merge with 4.1 sql/sql_union.cc: Merge with 4.1 sql/sql_yacc.yy: Merge with 4.1 sql/tztime.cc: Merge with 4.1 tests/client_test.c: Merge with 4.1
Diffstat (limited to 'ndb/src/mgmsrv/main.cpp')
-rw-r--r--ndb/src/mgmsrv/main.cpp196
1 files changed, 45 insertions, 151 deletions
diff --git a/ndb/src/mgmsrv/main.cpp b/ndb/src/mgmsrv/main.cpp
index d9eb0001c44..719226b51df 100644
--- a/ndb/src/mgmsrv/main.cpp
+++ b/ndb/src/mgmsrv/main.cpp
@@ -16,11 +16,9 @@
#include <ndb_global.h>
-#include <signal.h>
-
#include "MgmtSrvr.hpp"
#include "EventLogger.hpp"
-#include "Config.hpp"
+#include <Config.hpp>
#include "InitConfigFileParser.hpp"
#include <SocketServer.hpp>
#include "Services.hpp"
@@ -37,6 +35,8 @@
#include <mgmapi_config_parameters.h>
#include <getarg.h>
+#include <NdbAutoPtr.hpp>
+
#if defined NDB_OSE || defined NDB_SOFTOSE
#include <efs.h>
#else
@@ -88,7 +88,6 @@ static MgmGlobals glob;
******************************************************************************/
static bool readLocalConfig();
static bool readGlobalConfig();
-static bool setPortNo();
/**
* Global variables
@@ -100,16 +99,16 @@ extern int global_mgmt_server_check;
int _print_version = 0;
struct getargs args[] = {
- { "version", 0, arg_flag, &_print_version,
- "Print versions"},
- { NULL, 'c', arg_string, &glob.config_filename,
- "Running cluster configuration file", "filename" },
- { NULL, 'd', arg_flag, &glob.daemon,
- "Daemon mode" },
+ { "version", 'v', arg_flag, &_print_version,
+ "Print ndb_mgmd version"},
+ { "config-file", 'c', arg_string, &glob.config_filename,
+ "Specify cluster configuration file", "filename" },
+ { "daemon", 'd', arg_flag, &glob.daemon,
+ "Run ndb_mgmd in daemon mode" },
{ NULL, 'l', arg_string, &glob.local_config_filename,
- "Local configuration file (Ndb.cfg)",
+ "Specify configuration file connect string (will default use Ndb.cfg if available)",
"filename" },
- { NULL, 'n', arg_flag, &glob.non_interactive,
+ { "nodaemon", 'n', arg_flag, &glob.non_interactive,
"Don't run as daemon, but don't read from stdin", "non-interactive" }
};
@@ -146,7 +145,9 @@ NDB_MAIN(mgmsrv){
exit(1);
}
glob.socketServer = new SocketServer();
+
MgmApiService * mapi = new MgmApiService();
+
MgmStatService * mstat = new MgmStatService();
/****************************
@@ -157,16 +158,34 @@ NDB_MAIN(mgmsrv){
if (!readGlobalConfig())
goto error_end;
- if (!setPortNo())
+ glob.mgmObject = new MgmtSrvr(glob.localNodeId,
+ BaseString(glob.config_filename),
+ BaseString(glob.local_config_filename == 0 ?
+ "" : glob.local_config_filename),
+ glob.cluster_config);
+
+ glob.cluster_config = 0;
+ glob.localNodeId= glob.mgmObject->getOwnNodeId();
+
+ if (glob.localNodeId == 0) {
goto error_end;
-
+ }
+
+ glob.port= glob.mgmObject->getPort();
+
+ if (glob.port == 0)
+ goto error_end;
+
+ glob.interface_name = 0;
+ glob.use_specific_ip = false;
+
if(!glob.use_specific_ip){
if(!glob.socketServer->tryBind(glob.port, glob.interface_name)){
ndbout_c("Unable to setup port: %s:%d!\n"
"Please check if the port is already used,\n"
"(perhaps a mgmtsrvr is already running),\n"
"and if you are executing on the correct computer",
- glob.interface_name, glob.port);
+ (glob.interface_name ? glob.interface_name : "*"), glob.port);
goto error_end;
}
free(glob.interface_name);
@@ -190,31 +209,25 @@ NDB_MAIN(mgmsrv){
goto error_end;
}
- glob.mgmObject = new MgmtSrvr(glob.localNodeId,
- BaseString(glob.config_filename),
- BaseString(glob.local_config_filename == 0 ? "" : glob.local_config_filename),
- glob.cluster_config);
-
- glob.cluster_config = 0;
-
if(!glob.mgmObject->check_start()){
- ndbout_c("Unable to start management server.");
+ ndbout_c("Unable to check start management server.");
ndbout_c("Probably caused by illegal initial configuration file.");
goto error_end;
}
if (glob.daemon) {
// Become a daemon
- char homePath[255],lockfile[255], logfile[255];
- NdbConfig_HomePath(homePath, 255);
- snprintf(lockfile, 255, "%snode%d.pid", homePath, glob.localNodeId);
- snprintf(logfile, 255, "%snode%d.out", homePath, glob.localNodeId);
+ char *lockfile= NdbConfig_PidFileName(glob.localNodeId);
+ char *logfile= NdbConfig_StdoutFileName(glob.localNodeId);
+ NdbAutoPtr<char> tmp_aptr1(lockfile), tmp_aptr2(logfile);
+
if (NdbDaemon_Make(lockfile, logfile, 0) == -1) {
ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl;
return 1;
}
}
+ signal(SIGPIPE, SIG_IGN);
if(!glob.mgmObject->start()){
ndbout_c("Unable to start management server.");
ndbout_c("Probably caused by illegal initial configuration file.");
@@ -233,8 +246,8 @@ NDB_MAIN(mgmsrv){
ndbout_c(msg);
g_EventLogger.info(msg);
- snprintf(msg, 256, "Command port: %d, Statistics port: %d",
- glob.port, glob.port_stats);
+ snprintf(msg, 256, "Id: %d, Command port: %d, Statistics port: %d",
+ glob.localNodeId, glob.port, glob.port_stats);
ndbout_c(msg);
g_EventLogger.info(msg);
@@ -298,14 +311,11 @@ MgmGlobals::~MgmGlobals(){
static bool
readLocalConfig(){
// Read local config file
- ConfigRetriever cr;
- cr.setLocalConfigFileName(glob.local_config_filename);
- int nodeid = cr.init(true);
- if(nodeid == -1){
+ LocalConfig lc;
+ if(!lc.init(glob.local_config_filename))
return false;
- }
- glob.localNodeId = (NodeId)nodeid;
+ glob.localNodeId = lc._ownNodeId;
return true;
}
@@ -328,123 +338,7 @@ readGlobalConfig() {
InitConfigFileParser parser;
glob.cluster_config = parser.parseConfig(glob.config_filename);
if(glob.cluster_config == 0){
- /**
- * Try to get configuration from other MGM server
- * Note: Only new format
- */
- glob.cluster_config = new Config();
-
- ConfigRetriever cr;
- cr.setLocalConfigFileName(glob.local_config_filename);
- glob.cluster_config->m_configValues = cr.getConfig(NDB_VERSION,
- NODE_TYPE_MGM);
- if (glob.cluster_config->m_configValues == NULL)
- return false;
- }
- return true;
-}
-
-/**
- * @fn setPortNo
- * @param glob : Global variables
- * @return true if success, false otherwise.
- *
- * Port number:
- * 2. Use port number from global configuration file
- * 4. Use port number for statistics from global configuration file
- */
-static bool
-setPortNo(){
- const Properties *mgmProps;
-
- ndb_mgm_configuration_iterator * iter =
- ndb_mgm_create_configuration_iterator(glob.cluster_config->m_configValues,
- CFG_SECTION_NODE);
- if(iter == 0)
- return false;
-
- if(ndb_mgm_find(iter, CFG_NODE_ID, glob.localNodeId) != 0){
- ndbout << "Could not retrieve configuration for Node "
- << glob.localNodeId << " in config file." << endl
- << "Have you set correct NodeId for this node?" << endl;
- ndb_mgm_destroy_iterator(iter);
- return false;
- }
-
- unsigned type;
- if(ndb_mgm_get_int_parameter(iter, CFG_TYPE_OF_SECTION, &type) != 0 ||
- type != NODE_TYPE_MGM){
- ndbout << "Local node id " << glob.localNodeId
- << " is not defined as management server" << endl
- << "Have you set correct NodeId for this node?" << endl;
- return false;
- }
-
- /************
- * Set Port *
- ************/
- Uint32 tmp = 0;
- if(ndb_mgm_get_int_parameter(iter, CFG_MGM_PORT, &tmp) != 0){
- ndbout << "Could not find PortNumber in the configuration file." << endl;
- return false;
- }
- glob.port = tmp;
-
- /*****************
- * Set Stat Port *
- *****************/
-#if 0
- if (!mgmProps->get("PortNumberStats", &tmp)){
- ndbout << "Could not find PortNumberStats in the configuration file."
- << endl;
return false;
}
- glob.port_stats = tmp;
-#endif
-
-#if 0
- const char * host;
- if(ndb_mgm_get_string_parameter(iter, mgmProps->get("ExecuteOnComputer", host)){
- ndbout << "Failed to find \"ExecuteOnComputer\" for my node" << endl;
- ndbout << "Unable to verify own hostname" << endl;
- return false;
- }
-
- const char * hostname;
- {
- const Properties * p;
- char buf[255];
- snprintf(buf, sizeof(buf), "Computer_%s", host.c_str());
- if(!glob.cluster_config->get(buf, &p)){
- ndbout << "Failed to find computer " << host << " in config" << endl;
- ndbout << "Unable to verify own hostname" << endl;
- return false;
- }
- if(!p->get("HostName", &hostname)){
- ndbout << "Failed to find \"HostName\" for computer " << host
- << " in config" << endl;
- ndbout << "Unable to verify own hostname" << endl;
- return false;
- }
- if(NdbHost_GetHostName(buf) != 0){
- ndbout << "Unable to get own hostname" << endl;
- ndbout << "Unable to verify own hostname" << endl;
- return false;
- }
- }
-
- const char * ip_address;
- if(mgmProps->get("IpAddress", &ip_address)){
- glob.use_specific_ip = true;
- glob.interface_name = strdup(ip_address);
- return true;
- }
-
- glob.interface_name = strdup(hostname);
-#endif
-
- glob.interface_name = 0;
- glob.use_specific_ip = false;
-
return true;
}