From 4f63212145523b24fd79211abbcd6931aec7dc67 Mon Sep 17 00:00:00 2001 From: david hill Date: Mon, 6 Nov 2017 17:46:07 -0600 Subject: [PATCH] mcol-1009 and mcol-1014 --- dbcon/mysql/my.cnf | 2 +- dbcon/mysql/mysql-Columnstore | 7 +- oam/etc/Columnstore.xml | 2 +- oam/install_scripts/CMakeLists.txt | 1 + oam/install_scripts/mariadb-command-line.sh | 59 +++ oam/install_scripts/master-rep-columnstore.sh | 11 +- oam/install_scripts/slave-rep-columnstore.sh | 11 +- oamapps/postConfigure/helpers.cpp | 5 +- oamapps/postConfigure/helpers.h | 2 +- oamapps/postConfigure/postConfigure.cpp | 2 +- procmgr/processmanager.cpp | 21 +- procmon/processmonitor.cpp | 477 +++++++++--------- procmon/processmonitor.h | 10 +- 13 files changed, 333 insertions(+), 277 deletions(-) create mode 100644 oam/install_scripts/mariadb-command-line.sh diff --git a/dbcon/mysql/my.cnf b/dbcon/mysql/my.cnf index d4f595062..bdbe7ef26 100644 --- a/dbcon/mysql/my.cnf +++ b/dbcon/mysql/my.cnf @@ -53,7 +53,7 @@ infinidb_compression_type=2 infinidb_stringtable_threshold=20 # infinidb local query flag -# infinidb_local_query=1 +infinidb_local_query=0 infinidb_diskjoin_smallsidelimit=0 infinidb_diskjoin_largesidelimit=0 diff --git a/dbcon/mysql/mysql-Columnstore b/dbcon/mysql/mysql-Columnstore index a0c8bca23..b49c646e2 100755 --- a/dbcon/mysql/mysql-Columnstore +++ b/dbcon/mysql/mysql-Columnstore @@ -61,7 +61,7 @@ datadir=$basedir/db # Value here is overriden by value in my.cnf. # 0 means don't wait at all # Negative numbers mean to wait indefinitely -service_startup_timeout=30 +service_startup_timeout=60 # Lock directory for RedHat / SuSE. lockdir='/var/lock/subsys' @@ -262,6 +262,8 @@ wait_for_gone () { done log_failure_msg + kill_by_pid + return 1 } @@ -310,7 +312,7 @@ fi kill_by_pid() { # let's see if we can kill the 2 mysql procs by hand # get the our mysql from ps - eval $(ps -ef | grep "$COLUMNSTORE_INSTALL_DIR/mysql//bin/mysqld" | grep -v grep | head -1 | awk '{printf "pid=%d\n", $2}') + eval $(ps -ef | grep "$COLUMNSTORE_INSTALL_DIR/mysql/bin/mysqld" | grep -v grep | head -1 | awk '{printf "pid=%d\n", $2}') if [ -n "$pid" ]; then ppid=$(ps -o ppid= -p $pid) @@ -369,6 +371,7 @@ case "$mode" in wait_for_gone $mysqld_pid "$mysqld_pid_file_path"; return_value=$? else log_failure_msg "MySQL server process #$mysqld_pid is not running!" + kill_by_pid rm "$mysqld_pid_file_path" fi diff --git a/oam/etc/Columnstore.xml b/oam/etc/Columnstore.xml index 6efa3f8aa..14098fb28 100644 --- a/oam/etc/Columnstore.xml +++ b/oam/etc/Columnstore.xml @@ -226,7 +226,7 @@ C columnstore-1 - unassigned + pm1 unassigned unassigned 1 diff --git a/oam/install_scripts/CMakeLists.txt b/oam/install_scripts/CMakeLists.txt index 6b7296c54..d450d7f27 100644 --- a/oam/install_scripts/CMakeLists.txt +++ b/oam/install_scripts/CMakeLists.txt @@ -33,6 +33,7 @@ install(PROGRAMS post-install myCnf-include-args.text myCnf-exclude-args.text columnstore.service + mariadb-command-line.sh DESTINATION ${ENGINE_BINDIR} COMPONENT platform) install(FILES module DESTINATION ${ENGINE_LOCALDIR} COMPONENT platform) diff --git a/oam/install_scripts/mariadb-command-line.sh b/oam/install_scripts/mariadb-command-line.sh new file mode 100644 index 000000000..bb2750581 --- /dev/null +++ b/oam/install_scripts/mariadb-command-line.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# +# $Id$ +# +# generic MariaDB Columnstore Command Line script. +# +# Notes: This script gets run by ProcMon during installs and upgrades: + +# check log for error +checkForError() { + grep ERROR /tmp/mariadb-command-line.log > /tmp/error.check + if [ `cat /tmp/error.check | wc -c` -ne 0 ]; then + echo "ERROR: check log file: /tmp/mariadb-command-line.log" + rm -f /tmp/error.check + exit 1 + fi + rm -f /tmp/error.check +} + +prefix=/usr/local +installdir=$prefix/mariadb/columnstore +pwprompt= +for arg in "$@"; do + if [ `expr -- "$arg" : '--command='` -eq 10 ]; then + command1="`echo $arg | awk -F= '{print $2}'`" + command2="`echo $arg | awk -F= '{print $3}'`" + command=$command1"="$command2 + elif [ `expr -- "$arg" : '--installdir='` -eq 13 ]; then + installdir="`echo $arg | awk -F= '{print $2}'`" + prefix=`dirname $installdir` + elif [ `expr -- "$arg" : '--port='` -eq 7 ]; then + port="`echo $arg | awk -F= '{print $2}'`" + fi +done + +test -f $installdir/post/functions && . $installdir/post/functions + + +>/tmp/mariadb-command-line.log + +# +# Run command +# +echo "Run command" >>/tmp/mariadb-command-line.log +cat >/tmp/mariadb-command-line.sql <> /tmp/mariadb-command-line.log +$installdir/mysql/bin/mysql \ + --defaults-extra-file=$installdir/mysql/my.cnf \ + --user=root \ + calpontsys < /tmp/mariadb-command-line.sql >> /tmp/mariadb-command-line.log 2>&1 + +checkForError + +#alls good, 'OK' for success +echo "OK" +exit 0 diff --git a/oam/install_scripts/master-rep-columnstore.sh b/oam/install_scripts/master-rep-columnstore.sh index b811f572a..5d27ee278 100644 --- a/oam/install_scripts/master-rep-columnstore.sh +++ b/oam/install_scripts/master-rep-columnstore.sh @@ -24,9 +24,6 @@ for arg in "$@"; do if [ `expr -- "$arg" : '--prefix='` -eq 9 ]; then prefix="`echo $arg | awk -F= '{print $2}'`" installdir=$prefix/mariadb/columnstore - elif [ `expr -- "$arg" : '--password='` -eq 11 ]; then - password="`echo $arg | awk -F= '{print $2}'`" - pwprompt="--password=$password" elif [ `expr -- "$arg" : '--installdir='` -eq 13 ]; then installdir="`echo $arg | awk -F= '{print $2}'`" prefix=`dirname $installdir` @@ -54,7 +51,7 @@ EOD cat /tmp/idb_master-rep.sql >>/tmp/master-rep-status-$hostipaddr.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/master-rep-status-$hostipaddr.log 2>&1 checkForError @@ -72,7 +69,7 @@ EOD cat /tmp/idb_master-rep.sql >>/tmp/master-rep-status-$hostipaddr.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/master-rep-status-$hostipaddr.log 2>&1 checkForError @@ -88,7 +85,7 @@ EOD cat /tmp/idb_master-rep.sql >>/tmp/master-rep-status-$hostipaddr.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/master-rep-status-$hostipaddr.log 2>&1 checkForError @@ -101,7 +98,7 @@ EOD cat /tmp/idb_master-rep.sql >/tmp/show-master-status.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/show-master-status.log diff --git a/oam/install_scripts/slave-rep-columnstore.sh b/oam/install_scripts/slave-rep-columnstore.sh index 612427f46..ae8914237 100644 --- a/oam/install_scripts/slave-rep-columnstore.sh +++ b/oam/install_scripts/slave-rep-columnstore.sh @@ -24,9 +24,6 @@ for arg in "$@"; do if [ `expr -- "$arg" : '--prefix='` -eq 9 ]; then prefix="`echo $arg | awk -F= '{print $2}'`" installdir=$prefix/mariadb/columnstore - elif [ `expr -- "$arg" : '--password='` -eq 11 ]; then - password="`echo $arg | awk -F= '{print $2}'`" - pwprompt="--password=$password" elif [ `expr -- "$arg" : '--installdir='` -eq 13 ]; then installdir="`echo $arg | awk -F= '{print $2}'`" prefix=`dirname $installdir` @@ -59,7 +56,7 @@ EOD cat /tmp/idb_slave-rep.sql >>/tmp/slave-rep-status.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/slave-rep-status.log 2>&1 checkForError @@ -82,7 +79,7 @@ EOD cat /tmp/idb_slave-rep.sql >>/tmp/slave-rep-status.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/slave-rep-status.log 2>&1 checkForError @@ -98,7 +95,7 @@ EOD cat /tmp/idb_slave-rep.sql >>/tmp/slave-rep-status.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/slave-rep-status.log 2>&1 checkForError @@ -114,7 +111,7 @@ EOD cat /tmp/idb_slave-rep.sql >>/tmp/slave-rep-status.log $installdir/mysql/bin/mysql \ --defaults-extra-file=$installdir/mysql/my.cnf \ - --user=root $pwprompt \ + --user=root \ calpontsys >/tmp/slave-rep-status.log 2>&1 checkForError diff --git a/oamapps/postConfigure/helpers.cpp b/oamapps/postConfigure/helpers.cpp index 07507acf1..3d84496ed 100644 --- a/oamapps/postConfigure/helpers.cpp +++ b/oamapps/postConfigure/helpers.cpp @@ -368,7 +368,7 @@ int sendUpgradeRequest(int IserverTypeInstall, bool pmwithum) * * ******************************************************************************************/ -int sendReplicationRequest(int IserverTypeInstall, std::string password, std::string port, bool pmwithum) +int sendReplicationRequest(int IserverTypeInstall, std::string password, bool pmwithum) { Oam oam; @@ -459,7 +459,7 @@ int sendReplicationRequest(int IserverTypeInstall, std::string password, std::st { // set for slave repl request // don't do PMs unless PMwithUM flag is set string moduleType = (*pt).DeviceName.substr(0,MAX_MODULE_TYPE_SIZE); - + if ( ( moduleType == "pm" && !pmwithum ) && ( IserverTypeInstall != oam::INSTALL_COMBINE_DM_UM_PM ) ) { pt++; @@ -476,7 +476,6 @@ int sendReplicationRequest(int IserverTypeInstall, std::string password, std::st msg << masterLogFile; msg << masterLogPos; - msg << port; returnStatus = sendMsgProcMon( (*pt).DeviceName, msg, requestID, 30 ); diff --git a/oamapps/postConfigure/helpers.h b/oamapps/postConfigure/helpers.h index 652c86958..64917173b 100644 --- a/oamapps/postConfigure/helpers.h +++ b/oamapps/postConfigure/helpers.h @@ -39,7 +39,7 @@ extern void dbrmDirCheck(); extern void mysqlSetup(); extern int sendMsgProcMon( std::string module, ByteStream msg, int requestID, int timeout ); extern int sendUpgradeRequest(int IserverTypeInstall, bool pmwithum); -extern int sendReplicationRequest(int IserverTypeInstall, std::string password, std::string mysqlPort, bool pmwithum); +extern int sendReplicationRequest(int IserverTypeInstall, std::string password, bool pmwithum); extern void checkFilesPerPartion(int DBRootCount, Config* sysConfig); extern void checkMysqlPort( string& mysqlPort, Config* sysConfig); extern bool writeConfig(Config* sysConfig); diff --git a/oamapps/postConfigure/postConfigure.cpp b/oamapps/postConfigure/postConfigure.cpp index cc410e86a..82f92d6da 100644 --- a/oamapps/postConfigure/postConfigure.cpp +++ b/oamapps/postConfigure/postConfigure.cpp @@ -3497,7 +3497,7 @@ int main(int argc, char *argv[]) cout.flush(); //send message to procmon's to run mysql replication script - int status = sendReplicationRequest(IserverTypeInstall, password, mysqlPort, pmwithum); + int status = sendReplicationRequest(IserverTypeInstall, password, pmwithum); if ( status != 0 ) { cout << endl << " MariaDB ColumnStore Install Failed" << endl << endl; diff --git a/procmgr/processmanager.cpp b/procmgr/processmanager.cpp index c99662d3a..492dc9b05 100755 --- a/procmgr/processmanager.cpp +++ b/procmgr/processmanager.cpp @@ -10328,18 +10328,6 @@ int ProcessManager::setMySQLReplication(oam::DeviceNetworkList devicenetworklist */ log.writeLog(__LINE__, "Setup MySQL Replication", LOG_TYPE_DEBUG); - // mysql port number - string MySQLPort; - try { - oam.getSystemConfig("MySQLPort", MySQLPort); - } - catch(...) { - MySQLPort = "3306"; - } - - if ( MySQLPort.empty() ) - MySQLPort = "3306"; - //get master info if ( masterModule == oam::UnassignedName) { @@ -10390,6 +10378,13 @@ int ProcessManager::setMySQLReplication(oam::DeviceNetworkList devicenetworklist if ( remoteModuleName == masterModule ) continue; + // don't do PMs unless PMwithUM flag is set + if ( config.ServerInstallType() != oam::INSTALL_COMBINE_DM_UM_PM ) { + string moduleType = remoteModuleName.substr(0,MAX_MODULE_TYPE_SIZE); + if ( moduleType == "pm" && PMwithUM == "n" ) + continue; + } + ByteStream msg; ByteStream::byte requestID = oam::MASTERDIST; msg << requestID; @@ -10485,7 +10480,6 @@ int ProcessManager::setMySQLReplication(oam::DeviceNetworkList devicenetworklist msg1 << masterLogFile; msg1 << masterLogPos; - msg1 << MySQLPort; } returnStatus = sendMsgProcMon( remoteModuleName, msg1, requestID, 60 ); @@ -10534,7 +10528,6 @@ int ProcessManager::setMySQLReplication(oam::DeviceNetworkList devicenetworklist msg1 << masterLogFile; msg1 << masterLogPos; - msg1 << MySQLPort; } returnStatus = sendMsgProcMon( remoteModuleName, msg1, requestID, 60 ); diff --git a/procmon/processmonitor.cpp b/procmon/processmonitor.cpp index 82e74a1cd..1a1092e61 100644 --- a/procmon/processmonitor.cpp +++ b/procmon/processmonitor.cpp @@ -1582,7 +1582,7 @@ void ProcessMonitor::processMessage(messageqcpp::ByteStream msg, messageqcpp::IO } - case RUNUPGRADE: +/* case RUNUPGRADE: { log.writeLog(__LINE__, "MSG RECEIVED: Run upgrade script "); @@ -1601,7 +1601,7 @@ void ProcessMonitor::processMessage(messageqcpp::ByteStream msg, messageqcpp::IO break; } - +*/ case PROCUNMOUNT: { string dbrootID; @@ -1862,8 +1862,6 @@ void ProcessMonitor::processMessage(messageqcpp::ByteStream msg, messageqcpp::IO msg >> masterLogFile; string masterLogPos; msg >> masterLogPos; - string port; - msg >> port; if ( ( (PMwithUM == "n") && (config.moduleType() == "pm") ) && ( config.ServerInstallType() != oam::INSTALL_COMBINE_DM_UM_PM) ) @@ -1892,7 +1890,7 @@ void ProcessMonitor::processMessage(messageqcpp::ByteStream msg, messageqcpp::IO } // run Slave Rep script - ret = runSlaveRep(masterLogFile, masterLogPos, port); + ret = runSlaveRep(masterLogFile, masterLogPos); ackMsg << (ByteStream::byte) ACK; ackMsg << (ByteStream::byte) SLAVEREP; @@ -4677,7 +4675,7 @@ void ProcessMonitor::checkProcessFailover( std::string processName) * purpose: run upgrade script * ******************************************************************************************/ -int ProcessMonitor::runUpgrade(std::string mysqlpw) +/*int ProcessMonitor::runUpgrade(std::string mysqlpw) { Oam oam; @@ -4711,7 +4709,7 @@ int ProcessMonitor::runUpgrade(std::string mysqlpw) } return oam::API_FAILURE; } - +*/ /****************************************************************************************** * @brief changeMyCnf @@ -4734,204 +4732,103 @@ int ProcessMonitor::changeMyCnf(std::string type) string dbDir = startup::StartUp::installDir() + "/mysql/db"; -/* if ( type == "master" ) + //get server-id based on ExeMgrx setup + string serverID = "0"; + string localModuleName = config.moduleName(); + for ( int id = 1 ; ; id++ ) { - // set master replication entries - vector lines; - char line[200]; - string buf; - while (file.getline(line, 200)) - { - buf = line; - string::size_type pos = buf.find("server-id =",0); - if ( pos != string::npos ) { - buf = "server-id = 1"; + string Section = "ExeMgr" + oam.itoa(id); + + string moduleName; + + try { + Config* sysConfig = Config::makeConfig(); + moduleName = sysConfig->getConfig(Section, "Module"); + + if ( moduleName == localModuleName ) + { + serverID = oam.itoa(id); + break; } - -// pos = buf.find("# binlog_format=ROW",0); -// if ( pos != string::npos ) { -// buf = "binlog_format=ROW"; -// } - - pos = buf.find("infinidb_local_query=1",0); - if ( pos != string::npos && pos == 0) { - buf = "# infinidb_local_query=1"; - } - - //output to temp file - lines.push_back(buf); } - - file.close(); - unlink (mycnfFile.c_str()); - ofstream newFile (mycnfFile.c_str()); - - //create new file - int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0664); - - copy(lines.begin(), lines.end(), ostream_iterator(newFile, "\n")); - newFile.close(); - - close(fd); + catch (...) {} } - if ( type == "slave" ) + if ( serverID == "0" ) { -*/ //get slave id based on ExeMgrx setup - string slaveID = "0"; - string localModuleName = config.moduleName(); - for ( int id = 1 ; ; id++ ) + log.writeLog(__LINE__, "changeMyCnf: ExeMgr for local module doesn't exist", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } + + // set server-id and other options in my.cnf + vector lines; + char line[200]; + string buf; + while (file.getline(line, 200)) + { + buf = line; + string::size_type pos = buf.find("server-id",0); + if ( pos != string::npos ) { + buf = "server-id = " + serverID; + + string command = "SET GLOBAL server_id=" + serverID + ";"; + int ret = runMariaDBCommandLine(command); + if (ret != 0) + { + log.writeLog(__LINE__, "changeMyCnf: runMariaDBCommandLine Error", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } + } + + // set local query flag if on pm + if ( (PMwithUM == "y") && config.moduleType() == "pm" ) { - string Section = "ExeMgr" + oam.itoa(id); + pos = buf.find("infinidb_local_query",0); + if ( pos != string::npos ) { + buf = "infinidb_local_query=1"; + + string command = "SET GLOBAL " + buf + ";"; - string moduleName; - - try { - Config* sysConfig = Config::makeConfig(); - moduleName = sysConfig->getConfig(Section, "Module"); - - if ( moduleName == localModuleName ) + int ret = runMariaDBCommandLine(command); + if (ret != 0) { - slaveID = oam.itoa(id); - break; - } + log.writeLog(__LINE__, "changeMyCnf: runMariaDBCommandLine Error", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } } - catch (...) {} } - - if ( slaveID == "0" ) - { - log.writeLog(__LINE__, "changeMyCnf: ExeMgr for local module doesn't exist", LOG_TYPE_ERROR); - return oam::API_FAILURE; - } - - // get local host name -/* string HOSTNAME = "localhost"; - try - { - ModuleConfig moduleconfig; - oam.getSystemConfig(config.moduleName(), moduleconfig); - HostConfigList::iterator pt1 = moduleconfig.hostConfigList.begin(); - HOSTNAME = (*pt1).HostName; - } - catch(...) - {} - - char* p= getenv("HOSTNAME"); - if (p && *p) - HOSTNAME = p; -*/ - // set slave replication entries - vector lines; - char line[200]; - string buf; - while (file.getline(line, 200)) - { - buf = line; - string::size_type pos = buf.find("server-id",0); + else + { // disable, if needed + pos = buf.find("infinidb_local_query",0); if ( pos != string::npos ) { - buf = "server-id = " + slaveID; - } + buf = "infinidb_local_query=0"; - // set local query flag if on pm - if ( (PMwithUM == "y") && config.moduleType() == "pm" ) - { - pos = buf.find("# infinidb_local_query=1",0); - if ( pos != string::npos ) { - buf = "infinidb_local_query=1"; - } + string command = "SET GLOBAL " + buf + ";"; + int ret = runMariaDBCommandLine(command); + if (ret != 0) + { + log.writeLog(__LINE__, "changeMyCnf: runMariaDBCommandLine Error", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } } - else - { // disable, if needed - pos = buf.find("infinidb_local_query=1",0); - if ( pos != string::npos ) { - buf = "# infinidb_local_query=1"; - } - } - -// pos = buf.find("binlog_format=ROW",0); -// if ( pos != string::npos && pos == 0 ) { -// buf = "# binlog_format=ROW"; -// } - - //output to temp file - lines.push_back(buf); } - - file.close(); - unlink (mycnfFile.c_str()); - ofstream newFile (mycnfFile.c_str()); - //create new file - int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0664); - - copy(lines.begin(), lines.end(), ostream_iterator(newFile, "\n")); - newFile.close(); - - close(fd); -// } - -/* if ( type == "disable" ) - { - // set master replication entries - vector lines; - char line[200]; - string buf; - while (file.getline(line, 200)) - { - buf = line; - string::size_type pos = buf.find("server-id",0); - if ( pos != string::npos ) { - string::size_type pos1 = buf.find("1",pos); - if ( pos1 == string::npos ) { - buf = "# server-id = 1"; - } - } - - pos = buf.find("log-bin=mysql-bin",0); - if ( pos != string::npos ) { - buf = "# log-bin=mysql-bin"; - } - - pos = buf.find("binlog_format=ROW",0); - if ( pos != string::npos && pos == 0 ) { - buf = "# binlog_format=ROW"; - } - - pos = buf.find("infinidb_local_query=1",0); - if ( pos != string::npos && pos == 0) { - buf = "# infinidb_local_query=1"; - } - - pos = buf.find("# relay-log",0); - if ( pos != string::npos ) { - buf = buf; - } - else - { - pos = buf.find("relay-log",0); - if ( pos != string::npos ) { - buf = "# " + buf; - } - } - - //output to temp file - lines.push_back(buf); - } - - file.close(); - unlink (mycnfFile.c_str()); - ofstream newFile (mycnfFile.c_str()); - - //create new file - int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0664); - - copy(lines.begin(), lines.end(), ostream_iterator(newFile, "\n")); - newFile.close(); - - close(fd); + //output to temp file + lines.push_back(buf); } -*/ + + file.close(); + unlink (mycnfFile.c_str()); + ofstream newFile (mycnfFile.c_str()); + + //create new file + int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0664); + + copy(lines.begin(), lines.end(), ostream_iterator(newFile, "\n")); + newFile.close(); + + close(fd); + // set owner and permission string cmd = "chmod 664 " + mycnfFile + " >/dev/null 2>&1"; if ( !rootUser) @@ -4946,18 +4843,72 @@ int ProcessMonitor::changeMyCnf(std::string type) system(cmd.c_str()); // restart mysql - try { +/* try { oam.actionMysqlCalpont(MYSQL_RESTART); sleep(5); // give after mysql restart } catch(...) {} - +*/ log.writeLog(__LINE__, "changeMyCnf function successfully completed", LOG_TYPE_DEBUG); return oam::API_SUCCESS; } +/****************************************************************************************** +* @brief runMariaDBCommandLine +* +* purpose: run MariaDB Command Line script +* +******************************************************************************************/ +int ProcessMonitor::runMariaDBCommandLine(std::string command) +{ + Oam oam; + + log.writeLog(__LINE__, "runMariaDBCommandLine function called: cmd = " + command, LOG_TYPE_DEBUG); + + // mysql port number + string MySQLPort; + try { + oam.getSystemConfig("MySQLPort", MySQLPort); + } + catch(...) { + MySQLPort = "3306"; + } + + if ( MySQLPort.empty() ) + MySQLPort = "3306"; + + string cmd = startup::StartUp::installDir() + "/bin/mariadb-command-line.sh --installdir=" + startup::StartUp::installDir() + " --command='" + command + "' --port=" + MySQLPort + " > /tmp/mariadb-command-line.sh.log 2>&1"; + + log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); + + system(cmd.c_str()); + + string logFile = "/tmp/mariadb-command-line.sh.log"; + + if (oam.checkLogStatus(logFile, "ERROR 1045") ) { + log.writeLog(__LINE__, "mariadb-command-line.sh: MySQL Password Error, check .my.cnf", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } + else + { + if (oam.checkLogStatus(logFile, "OK")) + { + log.writeLog(__LINE__, "mariadb-command-line.sh: Successful return", LOG_TYPE_DEBUG); + return oam::API_SUCCESS; + } + else + { + log.writeLog(__LINE__, "mariadb-command-line.sh: Error return, check log /tmp/mariadb-command-line.sh.log", LOG_TYPE_ERROR); + return oam::API_FAILURE; + } + } + + return oam::API_FAILURE; +} + + /****************************************************************************************** * @brief runMasterRep * @@ -4984,6 +4935,18 @@ int ProcessMonitor::runMasterRep(std::string& masterLogFile, std::string& master // log.writeLog(__LINE__, "EXCEPTION ERROR on getSystemConfig: Caught unknown exception!", LOG_TYPE_ERROR); } + // mysql port number + string MySQLPort; + try { + oam.getSystemConfig("MySQLPort", MySQLPort); + } + catch(...) { + MySQLPort = "3306"; + } + + if ( MySQLPort.empty() ) + MySQLPort = "3306"; + // create user for each module by ip address for ( unsigned int i = 0 ; i < systemModuleTypeConfig.moduletypeconfig.size(); i++) { @@ -5000,46 +4963,41 @@ int ProcessMonitor::runMasterRep(std::string& masterLogFile, std::string& master string moduleType = systemModuleTypeConfig.moduletypeconfig[i].ModuleType; - if ( ( (PMwithUM == "n") && (config.moduleType() == "pm") ) && + if ( ( (PMwithUM == "n") && (moduleType == "pm") ) && ( config.ServerInstallType() != oam::INSTALL_COMBINE_DM_UM_PM) ) continue; HostConfigList::iterator pt1 = (*pt).hostConfigList.begin(); - while(true) // need in case there is a password retry + for ( ; pt1 != (*pt).hostConfigList.end() ; pt1++ ) { - for ( ; pt1 != (*pt).hostConfigList.end() ; pt1++ ) - { - string ipAddr = (*pt1).IPAddr; - - string logFile = "/tmp/master-rep-columnstore-" + moduleName + ".log"; - string cmd = startup::StartUp::installDir() + "/bin/master-rep-columnstore.sh --installdir=" + startup::StartUp::installDir() + " --hostIP=" + ipAddr + " > " + logFile + " 2>&1"; - log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); - - system(cmd.c_str()); - - if (oam.checkLogStatus(logFile, "ERROR 1045") ) { - if ( passwordError ) { - log.writeLog(__LINE__, "master-rep-columnstore.sh: MySQL Password Error", LOG_TYPE_ERROR); - return oam::API_FAILURE; - } - - log.writeLog(__LINE__, "master-rep-columnstore.sh: Missing Password error, go check for a password and retry", LOG_TYPE_DEBUG); - passwordError = true; - break; + string ipAddr = (*pt1).IPAddr; + + string logFile = "/tmp/master-rep-columnstore-" + moduleName + ".log"; + string cmd = startup::StartUp::installDir() + "/bin/master-rep-columnstore.sh --installdir=" + startup::StartUp::installDir() + " --hostIP=" + ipAddr + " --port=" + MySQLPort + " > " + logFile + " 2>&1"; + log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); + + system(cmd.c_str()); + + if (oam.checkLogStatus(logFile, "ERROR 1045") ) { + if ( passwordError ) { + log.writeLog(__LINE__, "master-rep-columnstore.sh: MySQL Password Error", LOG_TYPE_ERROR); + return oam::API_FAILURE; } - else + + log.writeLog(__LINE__, "master-rep-columnstore.sh: Missing Password error, go check for a password and retry", LOG_TYPE_DEBUG); + passwordError = true; + break; + } + else + { + if (oam.checkLogStatus(logFile, "OK")) + log.writeLog(__LINE__, "master-rep-columnstore.sh: Successful return for node " + moduleName, LOG_TYPE_DEBUG); + else { - if (oam.checkLogStatus(logFile, "OK")) - log.writeLog(__LINE__, "master-rep-columnstore.sh: Successful return for node " + moduleName, LOG_TYPE_DEBUG); - else - { - log.writeLog(__LINE__, "master-rep-columnstore.sh: Error return, check log " + logFile, LOG_TYPE_ERROR); - return oam::API_FAILURE; - } + log.writeLog(__LINE__, "master-rep-columnstore.sh: Error return, check log " + logFile, LOG_TYPE_ERROR); + return oam::API_FAILURE; } } - - break; } } } @@ -5106,7 +5064,7 @@ int ProcessMonitor::runMasterRep(std::string& masterLogFile, std::string& master * purpose: run Slave Replication script * ******************************************************************************************/ -int ProcessMonitor::runSlaveRep(std::string& masterLogFile, std::string& masterLogPos, std::string& port) +int ProcessMonitor::runSlaveRep(std::string& masterLogFile, std::string& masterLogPos) { Oam oam; @@ -5127,10 +5085,22 @@ int ProcessMonitor::runSlaveRep(std::string& masterLogFile, std::string& masterL catch(...) {} + // mysql port number + string MySQLPort; + try { + oam.getSystemConfig("MySQLPort", MySQLPort); + } + catch(...) { + MySQLPort = "3306"; + } + + if ( MySQLPort.empty() ) + MySQLPort = "3306"; + bool passwordError = false; while(true) { - string cmd = startup::StartUp::installDir() + "/bin/slave-rep-columnstore.sh --installdir=" + startup::StartUp::installDir() + " --masteripaddr=" + masterIPAddress + " --masterlogfile=" + masterLogFile + " --masterlogpos=" + masterLogPos + + " --port=" + port + " > /tmp/slave-rep-columnstore.log 2>&1"; + string cmd = startup::StartUp::installDir() + "/bin/slave-rep-columnstore.sh --installdir=" + startup::StartUp::installDir() + " --masteripaddr=" + masterIPAddress + " --masterlogfile=" + masterLogFile + " --masterlogpos=" + masterLogPos + " --port=" + MySQLPort + " > /tmp/slave-rep-columnstore.log 2>&1"; log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); @@ -5177,6 +5147,18 @@ int ProcessMonitor::runDisableRep() log.writeLog(__LINE__, "runDisableRep function called", LOG_TYPE_DEBUG); + // mysql port number + string MySQLPort; + try { + oam.getSystemConfig("MySQLPort", MySQLPort); + } + catch(...) { + MySQLPort = "3306"; + } + + if ( MySQLPort.empty() ) + MySQLPort = "3306"; + string cmd = startup::StartUp::installDir() + "/bin/disable-rep-columnstore.sh --installdir=" + startup::StartUp::installDir() + " > /tmp/disable-rep-columnstore.log 2>&1"; log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); @@ -5227,6 +5209,7 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul // log.writeLog(__LINE__, "EXCEPTION ERROR on getSystemConfig: Caught unknown exception!", LOG_TYPE_ERROR); } + int slave = 0; if ( slaveModule == "all" ) { // Distrubuted MySQL Front-end DB to Slave Modules @@ -5238,7 +5221,7 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul string moduleType = systemModuleTypeConfig.moduletypeconfig[i].ModuleType; - if ( ( (PMwithUM == "n") && (config.moduleType() == "pm") ) && + if ( ( (PMwithUM == "n") && (moduleType == "pm") ) && ( config.ServerInstallType() != oam::INSTALL_COMBINE_DM_UM_PM) ) continue; @@ -5251,6 +5234,8 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul if ( moduleName == config.moduleName() ) continue; + slave++; + HostConfigList::iterator pt1 = (*pt).hostConfigList.begin(); for ( ; pt1 != (*pt).hostConfigList.end() ; pt1++ ) { @@ -5263,7 +5248,10 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul string logFile = "/tmp/master-dist_" + moduleName + ".log"; if (!oam.checkLogStatus(logFile, "FAILED")) + { log.writeLog(__LINE__, "runMasterDist: Success rsync to module: " + moduleName, LOG_TYPE_DEBUG); + break; + } else { log.writeLog(__LINE__, "runMasterDist: Failure rsync to module: " + moduleName, LOG_TYPE_ERROR); @@ -5275,24 +5263,37 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul } else { - // get slave IP address - ModuleConfig moduleconfig; - oam.getSystemConfig(slaveModule, moduleconfig); - HostConfigList::iterator pt1 = moduleconfig.hostConfigList.begin(); - string ipAddr = (*pt1).IPAddr; + // don't do PMs unless PMwithUM flag is set + + string moduleType = slaveModule.substr(0,MAX_MODULE_TYPE_SIZE); - string cmd = startup::StartUp::installDir() + "/bin/rsync.sh " + ipAddr + " " + password + " " + startup::StartUp::installDir() + " 1 > /tmp/master-dist_" + slaveModule + ".log"; - system(cmd.c_str()); - - string logFile = "/tmp/master-dist_" + slaveModule + ".log"; - if (!oam.checkLogStatus(logFile, "FAILED")) - log.writeLog(__LINE__, "runMasterDist: Success rsync to module: " + slaveModule, LOG_TYPE_DEBUG); - else + if ( ( (PMwithUM == "y") && (moduleType == "pm") ) && + ( config.ServerInstallType() == oam::INSTALL_COMBINE_DM_UM_PM) ) { - log.writeLog(__LINE__, "runMasterDist: Failure rsync to module: " + slaveModule, LOG_TYPE_ERROR); - return oam::API_FAILURE; + slave++; + + // get slave IP address + ModuleConfig moduleconfig; + oam.getSystemConfig(slaveModule, moduleconfig); + HostConfigList::iterator pt1 = moduleconfig.hostConfigList.begin(); + string ipAddr = (*pt1).IPAddr; + + string cmd = startup::StartUp::installDir() + "/bin/rsync.sh " + ipAddr + " " + password + " " + startup::StartUp::installDir() + " 1 > /tmp/master-dist_" + slaveModule + ".log"; + system(cmd.c_str()); + + string logFile = "/tmp/master-dist_" + slaveModule + ".log"; + if (!oam.checkLogStatus(logFile, "FAILED")) + log.writeLog(__LINE__, "runMasterDist: Success rsync to module: " + slaveModule, LOG_TYPE_DEBUG); + else + { + log.writeLog(__LINE__, "runMasterDist: Failure rsync to module: " + slaveModule, LOG_TYPE_ERROR); + return oam::API_FAILURE; + } } } + + if (slave == 0 ) + log.writeLog(__LINE__, "runMasterDist: No configured slave nodes", LOG_TYPE_DEBUG); return oam::API_SUCCESS; } diff --git a/procmon/processmonitor.h b/procmon/processmonitor.h index a82e80bc0..5a3145963 100644 --- a/procmon/processmonitor.h +++ b/procmon/processmonitor.h @@ -492,13 +492,19 @@ public: /** *@brief run upgrade script */ - int runUpgrade(std::string mysqlpw); +// int runUpgrade(std::string mysqlpw); /** *@brief change my.cnf */ int changeMyCnf(std::string type); + + /** + *@brief run MariaDB Command Line script + */ + int runMariaDBCommandLine(std::string command); + /** *@brief run Master Replication script */ @@ -512,7 +518,7 @@ public: /** *@brief run Slave Replication script */ - int runSlaveRep(std::string& masterLogFile, std::string& masterLogPos, std::string& port); + int runSlaveRep(std::string& masterLogFile, std::string& masterLogPos); /** *@brief run Disable Replication script