diff options
Diffstat (limited to 'ndb/src/kernel/vm/Configuration.cpp')
-rw-r--r-- | ndb/src/kernel/vm/Configuration.cpp | 288 |
1 files changed, 180 insertions, 108 deletions
diff --git a/ndb/src/kernel/vm/Configuration.cpp b/ndb/src/kernel/vm/Configuration.cpp index 257b7a098e0..706f60fd9cf 100644 --- a/ndb/src/kernel/vm/Configuration.cpp +++ b/ndb/src/kernel/vm/Configuration.cpp @@ -14,6 +14,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <ndb_global.h> + +#include <LocalConfig.hpp> #include "Configuration.hpp" #include <ErrorHandlingMacros.hpp> #include "GlobalData.hpp" @@ -53,9 +56,13 @@ Configuration::init(int argc, const char** argv){ int _no_start = 0; int _initial = 0; const char* _connect_str = NULL; - int _deamon = 0; + int _daemon = 1; + int _no_daemon = 0; int _help = 0; int _print_version = 0; +#ifndef DBUG_OFF + const char *debug_option= 0; +#endif /** * Arguments to NDB process @@ -65,8 +72,13 @@ Configuration::init(int argc, const char** argv){ { "version", 'v', arg_flag, &_print_version, "Print ndbd version", "" }, { "nostart", 'n', arg_flag, &_no_start, "Don't start ndbd immediately. Ndbd will await command from ndb_mgmd", "" }, - { "daemon", 'd', arg_flag, &_deamon, "Start ndbd as daemon", "" }, - { "initial", 'i', arg_flag, &_initial, + { "daemon", 'd', arg_flag, &_daemon, "Start ndbd as daemon (default)", "" }, + { "nodaemon", 0, arg_flag, &_no_daemon, "Do not start ndbd as daemon, provided for testing purposes", "" }, +#ifndef DBUG_OFF + { "debug", 0, arg_string, &debug_option, + "Specify debug options e.g. d:t:i:o,out.trace", "options" }, +#endif + { "initial", 0, arg_flag, &_initial, "Perform initial start of ndbd, including cleaning the file system. Consult documentation before using this", "" }, { "connect-string", 'c', arg_string, &_connect_str, @@ -81,18 +93,28 @@ Configuration::init(int argc, const char** argv){ if(getarg(args, num_args, argc, argv, &optind) || _help) { arg_printusage(args, num_args, argv[0], desc); + for (int i = 0; i < argc; i++) { + if (strcmp("-i",argv[i]) == 0) { + printf("flag depricated %s, use %s\n", "-i", "--initial"); + } + } return false; } + if (_no_daemon) { + _daemon= 0; + } + // check for depricated flag '-i' -#if 0 - ndbout << "no_start=" <<_no_start<< endl; - ndbout << "initial=" <<_initial<< endl; - ndbout << "deamon=" <<_deamon<< endl; - ndbout << "connect_str="<<_connect_str<<endl; - arg_printusage(args, num_args, argv[0], desc); - return false; +#ifndef DBUG_OFF + if (debug_option) + DBUG_PUSH(debug_option); #endif + DBUG_PRINT("info", ("no_start=%d", _no_start)); + DBUG_PRINT("info", ("initial=%d", _initial)); + DBUG_PRINT("info", ("daemon=%d", _daemon)); + DBUG_PRINT("info", ("connect_str=%s", _connect_str)); + ndbSetOwnVersion(); if (_print_version) { @@ -114,8 +136,8 @@ Configuration::init(int argc, const char** argv){ if (_connect_str) _connectString = strdup(_connect_str); - // Check deamon flag - if (_deamon) + // Check daemon flag + if (_daemon) _daemonMode = true; // Save programname @@ -132,9 +154,11 @@ Configuration::Configuration() _programName = 0; _connectString = 0; _fsPath = 0; + _backupPath = 0; _initialStart = false; _daemonMode = false; m_config_retriever= 0; + m_clusterConfig= 0; } Configuration::~Configuration(){ @@ -144,6 +168,9 @@ Configuration::~Configuration(){ if(_fsPath != NULL) free(_fsPath); + if(_backupPath != NULL) + free(_backupPath); + if (m_config_retriever) { delete m_config_retriever; } @@ -158,7 +185,7 @@ Configuration::closeConfiguration(){ } void -Configuration::fetch_configuration(){ +Configuration::fetch_configuration(LocalConfig &local_config){ /** * Fetch configuration from management server */ @@ -166,27 +193,28 @@ Configuration::fetch_configuration(){ delete m_config_retriever; } - m_config_retriever= new ConfigRetriever(NDB_VERSION, NODE_TYPE_DB); - m_config_retriever->setConnectString(_connectString ? _connectString : ""); - if(m_config_retriever->init() == -1 || - m_config_retriever->do_connect() == -1){ - + m_mgmd_port= 0; + m_mgmd_host= 0; + m_config_retriever= new ConfigRetriever(local_config, NDB_VERSION, NODE_TYPE_DB); + if(m_config_retriever->do_connect() == -1){ const char * s = m_config_retriever->getErrorString(); if(s == 0) s = "No error given!"; - /* Set stop on error to true otherwise NDB will go into an restart loop... */ - ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could connect to ndb_mgmd", s); + ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not connect to ndb_mgmd", s); } + m_mgmd_port= m_config_retriever->get_mgmd_port(); + m_mgmd_host= m_config_retriever->get_mgmd_host(); + ConfigRetriever &cr= *m_config_retriever; if((globalData.ownId = cr.allocNodeId()) == 0){ for(Uint32 i = 0; i<3; i++){ NdbSleep_SecSleep(3); - if(globalData.ownId = cr.allocNodeId()) + if((globalData.ownId = cr.allocNodeId()) != 0) break; } } @@ -225,8 +253,48 @@ Configuration::fetch_configuration(){ } } +static char * get_and_validate_path(ndb_mgm_configuration_iterator &iter, + Uint32 param, const char *param_string) +{ + const char* path = NULL; + if(iter.get(param, &path)){ + ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched missing ", + param_string); + } + + if(path == 0 || strlen(path) == 0){ + ERROR_SET(fatal, ERR_INVALID_CONFIG, + "Invalid configuration fetched. Configuration does not contain valid ", + param_string); + } + + // check that it is pointing on a valid directory + // + char buf2[PATH_MAX]; + memset(buf2, 0,sizeof(buf2)); +#ifdef NDB_WIN32 + char* szFilePart; + if(!GetFullPathName(path, sizeof(buf2), buf2, &szFilePart) + || (::GetFileAttributes(alloc_path)&FILE_ATTRIBUTE_READONLY)) +#else + if((::realpath(path, buf2) == NULL)|| + (::access(buf2, W_OK) != 0)) +#endif + { + ERROR_SET(fatal, AFS_ERROR_INVALIDPATH, path, " Filename::init()"); + } + + if (strcmp(&buf2[strlen(buf2) - 1], DIR_SEPARATOR)) + strcat(buf2, DIR_SEPARATOR); + + return strdup(buf2); +} + void Configuration::setupConfiguration(){ + + DBUG_ENTER("Configuration::setupConfiguration"); + ndb_mgm_configuration * p = m_clusterConfig; /** @@ -272,29 +340,15 @@ Configuration::setupConfiguration(){ } /** - * Get filesystem path + * Get paths */ - { - const char* pFileSystemPath = NULL; - if(iter.get(CFG_DB_FILESYSTEM_PATH, &pFileSystemPath)){ - ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", - "FileSystemPath missing"); - } - - if(pFileSystemPath == 0 || strlen(pFileSystemPath) == 0){ - ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", - "Configuration does not contain valid filesystem path"); - } - - if(pFileSystemPath[strlen(pFileSystemPath) - 1] == '/') - _fsPath = strdup(pFileSystemPath); - else { - _fsPath = (char *)malloc(strlen(pFileSystemPath) + 2); - strcpy(_fsPath, pFileSystemPath); - strcat(_fsPath, "/"); - } - } - + if (_fsPath) + free(_fsPath); + _fsPath= get_and_validate_path(iter, CFG_DB_FILESYSTEM_PATH, "FileSystemPath"); + if (_backupPath) + free(_backupPath); + _backupPath= get_and_validate_path(iter, CFG_DB_BACKUP_DATADIR, "BackupDataDir"); + if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){ ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "RestartOnErrorInsert missing"); @@ -315,6 +369,8 @@ Configuration::setupConfiguration(){ (p, CFG_SECTION_NODE); calcSizeAlt(cf); + + DBUG_VOID_RETURN; } bool @@ -362,6 +418,11 @@ Configuration::setRestartOnErrorInsert(int i){ m_restartOnErrorInsert = i; } +const char * +Configuration::getConnectString() const { + return _connectString; +} + char * Configuration::getConnectStringCopy() const { if(_connectString != 0) @@ -385,7 +446,8 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ char buf[255]; unsigned int noOfTables = 0; - unsigned int noOfIndexes = 0; + unsigned int noOfUniqueHashIndexes = 0; + unsigned int noOfOrderedIndexes = 0; unsigned int noOfReplicas = 0; unsigned int noOfDBNodes = 0; unsigned int noOfAPINodes = 0; @@ -393,33 +455,28 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ unsigned int noOfNodes = 0; unsigned int noOfAttributes = 0; unsigned int noOfOperations = 0; + unsigned int noOfLocalOperations = 0; unsigned int noOfTransactions = 0; unsigned int noOfIndexPages = 0; unsigned int noOfDataPages = 0; unsigned int noOfScanRecords = 0; + unsigned int noOfLocalScanRecords = 0; + unsigned int noBatchSize = 0; m_logLevel = new LogLevel(); - /** - * {"NoOfConcurrentCheckpointsDuringRestart", &cd.ispValues[1][5] }, - * {"NoOfConcurrentCheckpointsAfterRestart", &cd.ispValues[2][4] }, - * {"NoOfConcurrentProcessesHandleTakeover", &cd.ispValues[1][7] }, - * {"TimeToWaitAlive", &cd.ispValues[0][0] }, - */ - struct AttribStorage { int paramId; Uint32 * storage; }; + struct AttribStorage { int paramId; Uint32 * storage; bool computable; }; AttribStorage tmp[] = { - { CFG_DB_NO_SCANS, &noOfScanRecords }, - { CFG_DB_NO_TABLES, &noOfTables }, - { CFG_DB_NO_INDEXES, &noOfIndexes }, - { CFG_DB_NO_REPLICAS, &noOfReplicas }, - { CFG_DB_NO_ATTRIBUTES, &noOfAttributes }, - { CFG_DB_NO_OPS, &noOfOperations }, - { CFG_DB_NO_TRANSACTIONS, &noOfTransactions } -#if 0 - { "NoOfDiskPagesToDiskDuringRestartTUP", &cd.ispValues[3][8] }, - { "NoOfDiskPagesToDiskAfterRestartTUP", &cd.ispValues[3][9] }, - { "NoOfDiskPagesToDiskDuringRestartACC", &cd.ispValues[3][10] }, - { "NoOfDiskPagesToDiskAfterRestartACC", &cd.ispValues[3][11] }, -#endif + { CFG_DB_NO_SCANS, &noOfScanRecords, false }, + { CFG_DB_NO_LOCAL_SCANS, &noOfLocalScanRecords, true }, + { CFG_DB_BATCH_SIZE, &noBatchSize, false }, + { CFG_DB_NO_TABLES, &noOfTables, false }, + { CFG_DB_NO_ORDERED_INDEXES, &noOfOrderedIndexes, false }, + { CFG_DB_NO_UNIQUE_HASH_INDEXES, &noOfUniqueHashIndexes, false }, + { CFG_DB_NO_REPLICAS, &noOfReplicas, false }, + { CFG_DB_NO_ATTRIBUTES, &noOfAttributes, false }, + { CFG_DB_NO_OPS, &noOfOperations, false }, + { CFG_DB_NO_LOCAL_OPS, &noOfLocalOperations, true }, + { CFG_DB_NO_TRANSACTIONS, &noOfTransactions, false } }; ndb_mgm_configuration_iterator db(*(ndb_mgm_configuration*)ownConfig, 0); @@ -427,8 +484,12 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ const int sz = sizeof(tmp)/sizeof(AttribStorage); for(int i = 0; i<sz; i++){ if(ndb_mgm_get_int_parameter(&db, tmp[i].paramId, tmp[i].storage)){ - snprintf(buf, sizeof(buf), "ConfigParam: %d not found", tmp[i].paramId); - ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); + if (tmp[i].computable) { + *tmp[i].storage = 0; + } else { + BaseString::snprintf(buf, sizeof(buf),"ConfigParam: %d not found", tmp[i].paramId); + ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); + } } } @@ -436,12 +497,12 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ ndb_mgm_get_int64_parameter(&db, CFG_DB_DATA_MEM, &dataMem); ndb_mgm_get_int64_parameter(&db, CFG_DB_INDEX_MEM, &indexMem); if(dataMem == 0){ - snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_DATA_MEM); + BaseString::snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_DATA_MEM); ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); } if(indexMem == 0){ - snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_INDEX_MEM); + BaseString::snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_INDEX_MEM); ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); } @@ -450,7 +511,7 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ for(unsigned j = 0; j<LogLevel::LOGLEVEL_CATEGORIES; j++){ Uint32 tmp; - if(!ndb_mgm_get_int_parameter(&db, LogLevel::MIN_LOGLEVEL_ID+j, &tmp)){ + if(!ndb_mgm_get_int_parameter(&db, CFG_MIN_LOGLEVEL+j, &tmp)){ m_logLevel->setLogLevel((LogLevel::EventCategory)j, tmp); } } @@ -474,13 +535,13 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ } if(nodeId > MAX_NODES || nodeId == 0){ - snprintf(buf, sizeof(buf), + BaseString::snprintf(buf, sizeof(buf), "Invalid node id: %d", nodeId); ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); } if(nodes.get(nodeId)){ - snprintf(buf, sizeof(buf), "Two node can not have the same node id: %d", + BaseString::snprintf(buf, sizeof(buf), "Two node can not have the same node id: %d", nodeId); ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); } @@ -507,42 +568,47 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ case NODE_TYPE_EXT_REP: break; default: - snprintf(buf, sizeof(buf), "Unknown node type: %d", nodeType); + BaseString::snprintf(buf, sizeof(buf), "Unknown node type: %d", nodeType); ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf); } } noOfNodes = nodeNo; - + + noOfTables+= 2; // Add System tables + noOfAttributes += 9; // Add System table attributes + + ConfigValues::Iterator it2(*ownConfig, db.m_config); + it2.set(CFG_DB_NO_TABLES, noOfTables); + it2.set(CFG_DB_NO_ATTRIBUTES, noOfAttributes); + /** * Do size calculations */ ConfigValuesFactory cfg(ownConfig); - noOfTables++; // Remove impact of system table - noOfTables += noOfIndexes; // Indexes are tables too - noOfAttributes += 2; // ---"---- - noOfTables *= 2; // Remove impact of Dict need 2 ids for each table - - if (noOfDBNodes > 15) { - noOfDBNodes = 15; - }//if - Uint32 noOfLocalScanRecords = (noOfDBNodes * noOfScanRecords) + 1; + if (noOfLocalScanRecords == 0) { + noOfLocalScanRecords = (noOfDBNodes * noOfScanRecords) + 1; + } + if (noOfLocalOperations == 0) { + noOfLocalOperations= (11 * noOfOperations) / 10; + } Uint32 noOfTCScanRecords = noOfScanRecords; { + Uint32 noOfAccTables= noOfTables + noOfUniqueHashIndexes; /** * Acc Size Alt values */ // Can keep 65536 pages (= 0.5 GByte) cfg.put(CFG_ACC_DIR_RANGE, - 4 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 4 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); cfg.put(CFG_ACC_DIR_ARRAY, (noOfIndexPages >> 8) + - 4 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 4 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); cfg.put(CFG_ACC_FRAGMENT, - 2 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 2 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); /*-----------------------------------------------------------------------*/ // The extra operation records added are used by the scan and node @@ -552,25 +618,27 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ // The remainder are allowed for use by the scan processes. /*-----------------------------------------------------------------------*/ cfg.put(CFG_ACC_OP_RECS, - ((11 * noOfOperations) / 10 + 50) + - (noOfLocalScanRecords * MAX_PARALLEL_SCANS_PER_FRAG) + + (noOfLocalOperations + 50) + + (noOfLocalScanRecords * noBatchSize) + NODE_RECOVERY_SCAN_OP_RECORDS); cfg.put(CFG_ACC_OVERFLOW_RECS, noOfIndexPages + - 2 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 2 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); cfg.put(CFG_ACC_PAGE8, noOfIndexPages + 32); cfg.put(CFG_ACC_ROOT_FRAG, - NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); - cfg.put(CFG_ACC_TABLE, noOfTables); + cfg.put(CFG_ACC_TABLE, noOfAccTables); cfg.put(CFG_ACC_SCAN, noOfLocalScanRecords); } + Uint32 noOfMetaTables= noOfTables + noOfOrderedIndexes + + noOfUniqueHashIndexes; { /** * Dict Size Alt values @@ -579,7 +647,7 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ noOfAttributes); cfg.put(CFG_DICT_TABLE, - noOfTables); + noOfMetaTables); } { @@ -592,8 +660,12 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ cfg.put(CFG_DIH_CONNECT, noOfOperations + noOfTransactions + 46); + Uint32 noFragPerTable= ((noOfDBNodes + NO_OF_FRAGS_PER_CHUNK - 1) >> + LOG_NO_OF_FRAGS_PER_CHUNK) << + LOG_NO_OF_FRAGS_PER_CHUNK; + cfg.put(CFG_DIH_FRAG_CONNECT, - NO_OF_FRAG_PER_NODE * noOfTables * noOfDBNodes); + noFragPerTable * noOfMetaTables); int temp; temp = noOfReplicas - 2; @@ -603,14 +675,14 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ temp++; cfg.put(CFG_DIH_MORE_NODES, temp * NO_OF_FRAG_PER_NODE * - noOfTables * noOfDBNodes); - + noOfMetaTables * noOfDBNodes); + cfg.put(CFG_DIH_REPLICAS, - NO_OF_FRAG_PER_NODE * noOfTables * + NO_OF_FRAG_PER_NODE * noOfMetaTables * noOfDBNodes * noOfReplicas); cfg.put(CFG_DIH_TABLE, - noOfTables); + noOfMetaTables); } { @@ -618,13 +690,13 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ * Lqh Size Alt values */ cfg.put(CFG_LQH_FRAG, - NO_OF_FRAG_PER_NODE * noOfTables * noOfReplicas); + NO_OF_FRAG_PER_NODE * noOfMetaTables * noOfReplicas); cfg.put(CFG_LQH_TABLE, - noOfTables); + noOfMetaTables); cfg.put(CFG_LQH_TC_CONNECT, - (11 * noOfOperations) / 10 + 50); + noOfLocalOperations + 50); cfg.put(CFG_LQH_SCAN, noOfLocalScanRecords); @@ -641,7 +713,7 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ (2 * noOfOperations) + 16 + noOfTransactions); cfg.put(CFG_TC_TABLE, - noOfTables); + noOfMetaTables); cfg.put(CFG_TC_LOCAL_SCAN, noOfLocalScanRecords); @@ -655,23 +727,23 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ * Tup Size Alt values */ cfg.put(CFG_TUP_FRAG, - 2 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 2 * NO_OF_FRAG_PER_NODE * noOfMetaTables* noOfReplicas); cfg.put(CFG_TUP_OP_RECS, - (11 * noOfOperations) / 10 + 50); + noOfLocalOperations + 50); cfg.put(CFG_TUP_PAGE, noOfDataPages); cfg.put(CFG_TUP_PAGE_RANGE, - 4 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas); + 4 * NO_OF_FRAG_PER_NODE * noOfMetaTables* noOfReplicas); cfg.put(CFG_TUP_TABLE, - noOfTables); + noOfMetaTables); cfg.put(CFG_TUP_TABLE_DESC, 4 * NO_OF_FRAG_PER_NODE * noOfAttributes* noOfReplicas + - 12 * NO_OF_FRAG_PER_NODE * noOfTables* noOfReplicas ); + 12 * NO_OF_FRAG_PER_NODE * noOfMetaTables* noOfReplicas ); cfg.put(CFG_TUP_STORED_PROC, noOfLocalScanRecords); @@ -682,13 +754,13 @@ Configuration::calcSizeAlt(ConfigValues * ownConfig){ * Tux Size Alt values */ cfg.put(CFG_TUX_INDEX, - noOfTables); + noOfOrderedIndexes); cfg.put(CFG_TUX_FRAGMENT, - 2 * NO_OF_FRAG_PER_NODE * noOfTables * noOfReplicas); + 2 * NO_OF_FRAG_PER_NODE * noOfOrderedIndexes * noOfReplicas); cfg.put(CFG_TUX_ATTRIBUTE, - noOfIndexes * 4); + noOfOrderedIndexes * 4); cfg.put(CFG_TUX_SCAN_OP, noOfLocalScanRecords); } |