Configuration.cpp 21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

17
#include <ndb_global.h>
18
#include <ndb_opts.h>
19

20 21 22 23 24 25 26 27 28 29 30
#include "Configuration.hpp"
#include <ErrorHandlingMacros.hpp>
#include "GlobalData.hpp"

#include <ConfigRetriever.hpp>
#include <IPCConfig.hpp>
#include <ndb_version.h>
#include <NdbMem.h>
#include <NdbOut.hpp>
#include <WatchDog.hpp>

31 32 33 34 35 36
#include <mgmapi_configuration.hpp>
#include <mgmapi_config_parameters_debug.h>
#include <kernel_config_parameters.h>

#include <kernel_types.h>
#include <ndb_limits.h>
37
#include <ndbapi_limits.h>
38 39
#include "pc.hpp"
#include <LogLevel.hpp>
joreland@mysql.com's avatar
joreland@mysql.com committed
40
#include <NdbSleep.h>
41

42 43 44 45
extern "C" {
  void ndbSetOwnVersion();
}

46 47 48
#include <EventLogger.hpp>
extern EventLogger g_eventLogger;

49
enum ndbd_options {
50
  OPT_INITIAL = NDB_STD_OPTIONS_LAST,
51 52 53 54
  OPT_NODAEMON
};

NDB_STD_OPTS_VARS;
55 56 57 58 59 60 61
static int _daemon, _no_daemon, _initial, _no_start;
/**
 * Arguments to NDB process
 */ 
static struct my_option my_long_options[] =
{
  NDB_STD_OPTS("ndbd"),
62
  { "initial", OPT_INITIAL,
63 64 65 66 67 68 69 70 71 72 73
    "Perform initial start of ndbd, including cleaning the file system. "
    "Consult documentation before using this",
    (gptr*) &_initial, (gptr*) &_initial, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
  { "nostart", 'n',
    "Don't start ndbd immediately. Ndbd will await command from ndb_mgmd",
    (gptr*) &_no_start, (gptr*) &_no_start, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
  { "daemon", 'd', "Start ndbd as daemon (default)",
    (gptr*) &_daemon, (gptr*) &_daemon, 0,
    GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
74
  { "nodaemon", OPT_NODAEMON,
75 76 77 78 79 80 81 82 83 84 85 86
    "Do not start ndbd as daemon, provided for testing purposes",
    (gptr*) &_no_daemon, (gptr*) &_no_daemon, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
static void short_usage_sub(void)
{
  printf("Usage: %s [OPTIONS]\n", my_progname);
}
static void usage()
{
  short_usage_sub();
87
  ndb_std_print_version();
88 89 90 91 92 93 94
  my_print_help(my_long_options);
  my_print_variables(my_long_options);
}

bool
Configuration::init(int argc, char** argv)
{  
95
  const char *load_default_groups[]= { "mysql_cluster","ndbd",0 };
96 97 98
  load_defaults("my",load_default_groups,&argc,&argv);

  int ho_error;
99 100 101 102 103
#ifndef DBUG_OFF
  opt_debug= "d:t:O,/tmp/ndbd.trace";
#endif
  if ((ho_error=handle_options(&argc, &argv, my_long_options,
			       ndb_std_get_one_option)))
104 105
    exit(ho_error);

106 107 108
  if (_no_daemon) {
    _daemon= 0;
  }
109

110 111
  DBUG_PRINT("info", ("no_start=%d", _no_start));
  DBUG_PRINT("info", ("initial=%d", _initial));
112
  DBUG_PRINT("info", ("daemon=%d", _daemon));
113
  DBUG_PRINT("info", ("connect_str=%s", opt_connect_str));
114

115 116 117
  ndbSetOwnVersion();

  // Check the start flag
118
  if (_no_start)
119
    globalData.theRestartFlag = initial_state;
120 121
  else 
    globalData.theRestartFlag = perform_start;
122 123 124 125 126 127

  // Check the initial flag
  if (_initial)
    _initialStart = true;
  
  // Check connectstring
128 129
  if (opt_connect_str)
    _connectString = strdup(opt_connect_str);
130
  
131 132
  // Check daemon flag
  if (_daemon)
133 134 135 136 137 138 139 140
    _daemonMode = true;

  // Save programname
  if(argc > 0 && argv[0] != 0)
    _programName = strdup(argv[0]);
  else
    _programName = strdup("");
  
141 142
  globalData.ownId= 0;

143 144 145
  return true;
}

146
Configuration::Configuration()
147 148 149 150
{
  _programName = 0;
  _connectString = 0;
  _fsPath = 0;
151
  _backupPath = 0;
152 153
  _initialStart = false;
  _daemonMode = false;
154
  m_config_retriever= 0;
joreland@mysql.com's avatar
joreland@mysql.com committed
155
  m_clusterConfig= 0;
156
  m_clusterConfigIter= 0;
157 158 159 160 161 162 163 164
}

Configuration::~Configuration(){
  if(_programName != NULL)
    free(_programName);

  if(_fsPath != NULL)
    free(_fsPath);
165

166 167 168
  if(_backupPath != NULL)
    free(_backupPath);

169 170 171 172 173 174 175 176 177 178 179
  if (m_config_retriever) {
    delete m_config_retriever;
  }
}

void
Configuration::closeConfiguration(){
  if (m_config_retriever) {
    delete m_config_retriever;
  }
  m_config_retriever= 0;
180 181 182
}

void
183
Configuration::fetch_configuration(){
184 185 186
  /**
   * Fetch configuration from management server
   */
187 188 189 190
  if (m_config_retriever) {
    delete m_config_retriever;
  }

191
  m_mgmd_port= 0;
192 193 194 195 196 197 198 199 200 201 202
  m_config_retriever= new ConfigRetriever(getConnectString(),
					  NDB_VERSION, NODE_TYPE_DB);

  if (m_config_retriever->hasError())
  {
    ERROR_SET(fatal, ERR_INVALID_CONFIG,
	      "Could not connect initialize handle to management server",
	      m_config_retriever->getErrorString());
  }

  if(m_config_retriever->do_connect(12,5,1) == -1){
joreland@mysql.com's avatar
joreland@mysql.com committed
203 204 205 206 207 208
    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...
    */
magnus@neptunus.(none)'s avatar
magnus@neptunus.(none) committed
209
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not connect to ndb_mgmd", s);
joreland@mysql.com's avatar
joreland@mysql.com committed
210 211
  }
  
212 213
  m_mgmd_port= m_config_retriever->get_mgmd_port();
  m_mgmd_host.assign(m_config_retriever->get_mgmd_host());
214

joreland@mysql.com's avatar
joreland@mysql.com committed
215 216
  ConfigRetriever &cr= *m_config_retriever;
  
217 218 219 220 221 222 223
  /**
   * if we have a nodeid set (e.g in a restart situation)
   * reuse it
   */
  if (globalData.ownId)
    cr.setNodeId(globalData.ownId);

224
  globalData.ownId = cr.allocNodeId(2 /*retry*/,3 /*delay*/);
joreland@mysql.com's avatar
joreland@mysql.com committed
225 226 227 228 229 230 231
  
  if(globalData.ownId == 0){
    ERROR_SET(fatal, ERR_INVALID_CONFIG, 
	      "Unable to alloc node id", m_config_retriever->getErrorString());
  }
  
  ndb_mgm_configuration * p = cr.getConfig();
232 233 234 235
  if(p == 0){
    const char * s = cr.getErrorString();
    if(s == 0)
      s = "No error given!";
joreland@mysql.com's avatar
joreland@mysql.com committed
236
    
237 238
    /* Set stop on error to true otherwise NDB will
       go into an restart loop...
joreland@mysql.com's avatar
joreland@mysql.com committed
239 240
    */
    
241 242 243
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Could not fetch configuration"
	      "/invalid configuration", s);
  }
joreland@mysql.com's avatar
joreland@mysql.com committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
  if(m_clusterConfig)
    free(m_clusterConfig);
  
  m_clusterConfig = p;
  
  ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
  if (iter.find(CFG_NODE_ID, globalData.ownId)){
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "DB missing");
  }
  
  if(iter.get(CFG_DB_STOP_ON_ERROR, &_stopOnError)){
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
	      "StopOnError missing");
  }
}
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
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;
281
  if(!GetFullPathName(path, sizeof(buf2), buf2, &szFilePart) ||
joreland@mysql.com's avatar
joreland@mysql.com committed
282
     (GetFileAttributes(buf2) & FILE_ATTRIBUTE_READONLY))
283
#else
284
  if((::realpath(path, buf2) == NULL)||
285 286
       (::access(buf2, W_OK) != 0))
#endif
287
  {
joreland@mysql.com's avatar
joreland@mysql.com committed
288 289 290
    ERROR_SET(fatal, AFS_ERROR_INVALIDPATH, path, " Filename::init()");
  }
  
291 292
  if (strcmp(&buf2[strlen(buf2) - 1], DIR_SEPARATOR))
    strcat(buf2, DIR_SEPARATOR);
joreland@mysql.com's avatar
joreland@mysql.com committed
293
  
294 295 296
  return strdup(buf2);
}

joreland@mysql.com's avatar
joreland@mysql.com committed
297 298
void
Configuration::setupConfiguration(){
299 300 301

  DBUG_ENTER("Configuration::setupConfiguration");

joreland@mysql.com's avatar
joreland@mysql.com committed
302
  ndb_mgm_configuration * p = m_clusterConfig;
303

304 305 306 307
  /**
   * Configure transporters
   */
  {  
joreland@mysql.com's avatar
joreland@mysql.com committed
308
    int res = IPCConfig::configureTransporters(globalData.ownId,
309 310 311
					       * p, 
					       globalTransporterRegistry);
    if(res <= 0){
312 313 314 315 316 317 318 319
      ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
		"No transporters configured");
    }
  }

  /**
   * Setup cluster configuration data
   */
320 321
  ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
  if (iter.find(CFG_NODE_ID, globalData.ownId)){
322 323
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", "DB missing");
  }
324 325 326

  unsigned type;
  if(!(iter.get(CFG_TYPE_OF_SECTION, &type) == 0 && type == NODE_TYPE_DB)){
327 328 329 330
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched",
	      "I'm wrong type of node");
  }
  
331
  if(iter.get(CFG_DB_NO_SAVE_MSGS, &_maxErrorLogs)){
332 333 334 335
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
	      "MaxNoOfSavedMessages missing");
  }
  
336
  if(iter.get(CFG_DB_MEMLOCK, &_lockPagesInMainMemory)){
337 338 339 340
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
	      "LockPagesInMainMemory missing");
  }

341
  if(iter.get(CFG_DB_WATCHDOG_INTERVAL, &_timeBetweenWatchDogCheck)){
342 343 344 345 346
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
	      "TimeBetweenWatchDogCheck missing");
  }

  /**
347
   * Get paths
348
   */  
349 350 351 352 353 354 355
  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");

356
  if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){
357 358 359 360 361 362 363 364 365 366 367 368
    ERROR_SET(fatal, ERR_INVALID_CONFIG, "Invalid configuration fetched", 
	      "RestartOnErrorInsert missing");
  }

  /**
   * Create the watch dog thread
   */
  { 
    Uint32 t = _timeBetweenWatchDogCheck;
    t = globalEmulatorData.theWatchDog ->setCheckInterval(t);
    _timeBetweenWatchDogCheck = t;
  }
369 370 371
  
  ConfigValues* cf = ConfigValuesFactory::extractCurrentSection(iter.m_config);

372 373
  if(m_clusterConfigIter)
    ndb_mgm_destroy_iterator(m_clusterConfigIter);
374 375
  m_clusterConfigIter = ndb_mgm_create_configuration_iterator
    (p, CFG_SECTION_NODE);
376

377
  calcSizeAlt(cf);
378 379

  DBUG_VOID_RETURN;
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
}

bool 
Configuration::lockPagesInMainMemory() const {
  return _lockPagesInMainMemory;
}

int 
Configuration::timeBetweenWatchDogCheck() const {
  return _timeBetweenWatchDogCheck;
}

void 
Configuration::timeBetweenWatchDogCheck(int value) {
  _timeBetweenWatchDogCheck = value;
}

int 
Configuration::maxNoOfErrorLogs() const {
  return _maxErrorLogs;
}

void 
Configuration::maxNoOfErrorLogs(int val){
  _maxErrorLogs = val;
}

bool
Configuration::stopOnError() const {
  return _stopOnError;
}

void 
Configuration::stopOnError(bool val){
  _stopOnError = val;
}

int
Configuration::getRestartOnErrorInsert() const {
  return m_restartOnErrorInsert;
}

void
Configuration::setRestartOnErrorInsert(int i){
  m_restartOnErrorInsert = i;
}

427 428 429 430 431
const char *
Configuration::getConnectString() const {
  return _connectString;
}

432 433 434 435 436 437
char *
Configuration::getConnectStringCopy() const {
  if(_connectString != 0)
    return strdup(_connectString);
  return 0;
}
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
const ndb_mgm_configuration_iterator * 
Configuration::getOwnConfigIterator() const {
  return m_ownConfigIterator;
}
  
ndb_mgm_configuration_iterator * 
Configuration::getClusterConfigIterator() const {
  return m_clusterConfigIter;
}

void
Configuration::calcSizeAlt(ConfigValues * ownConfig){
  const char * msg = "Invalid configuration fetched";
  char buf[255];

  unsigned int noOfTables = 0;
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
455 456
  unsigned int noOfUniqueHashIndexes = 0;
  unsigned int noOfOrderedIndexes = 0;
457
  unsigned int noOfTriggers = 0;
458 459 460 461 462 463 464
  unsigned int noOfReplicas = 0;
  unsigned int noOfDBNodes = 0;
  unsigned int noOfAPINodes = 0;
  unsigned int noOfMGMNodes = 0;
  unsigned int noOfNodes = 0;
  unsigned int noOfAttributes = 0;
  unsigned int noOfOperations = 0;
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
465
  unsigned int noOfLocalOperations = 0;
466 467 468 469
  unsigned int noOfTransactions = 0;
  unsigned int noOfIndexPages = 0;
  unsigned int noOfDataPages = 0;
  unsigned int noOfScanRecords = 0;
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
470 471
  unsigned int noOfLocalScanRecords = 0;
  unsigned int noBatchSize = 0;
472 473
  m_logLevel = new LogLevel();
  
joreland@mysql.com's avatar
joreland@mysql.com committed
474
  struct AttribStorage { int paramId; Uint32 * storage; bool computable; };
475
  AttribStorage tmp[] = {
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
476 477 478 479 480 481
    { 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 },
482
    { CFG_DB_NO_TRIGGERS, &noOfTriggers, true },
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
483 484 485 486 487
    { 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 }
488 489 490 491 492 493 494
  };

  ndb_mgm_configuration_iterator db(*(ndb_mgm_configuration*)ownConfig, 0);
  
  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)){
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
495 496
      if (tmp[i].computable) {
        *tmp[i].storage = 0;
497
      } else {
498
        BaseString::snprintf(buf, sizeof(buf),"ConfigParam: %d not found", tmp[i].paramId);
499 500
        ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
      }
501 502 503 504 505 506 507
    }
  }

  Uint64 indexMem = 0, dataMem = 0;
  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){
508
    BaseString::snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_DATA_MEM);
509 510 511 512
    ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
  }

  if(indexMem == 0){
513
    BaseString::snprintf(buf, sizeof(buf), "ConfigParam: %d not found", CFG_DB_INDEX_MEM);
514 515 516
    ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
  }

517
  noOfDataPages = (dataMem / 32768);
518 519 520 521
  noOfIndexPages = (indexMem / 8192);

  for(unsigned j = 0; j<LogLevel::LOGLEVEL_CATEGORIES; j++){
    Uint32 tmp;
522
    if(!ndb_mgm_get_int_parameter(&db, CFG_MIN_LOGLEVEL+j, &tmp)){
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
      m_logLevel->setLogLevel((LogLevel::EventCategory)j, tmp);
    }
  }
  
  // tmp
  ndb_mgm_configuration_iterator * p = m_clusterConfigIter;

  Uint32 nodeNo = noOfNodes = 0;
  NodeBitmask nodes;
  for(ndb_mgm_first(p); ndb_mgm_valid(p); ndb_mgm_next(p), nodeNo++){
    
    Uint32 nodeId;
    Uint32 nodeType;
    
    if(ndb_mgm_get_int_parameter(p, CFG_NODE_ID, &nodeId)){
      ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, "Node data (Id) missing");
    }
    
    if(ndb_mgm_get_int_parameter(p, CFG_TYPE_OF_SECTION, &nodeType)){
      ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, "Node data (Type) missing");
    }
    
    if(nodeId > MAX_NODES || nodeId == 0){
546
      BaseString::snprintf(buf, sizeof(buf),
547 548 549 550 551
	       "Invalid node id: %d", nodeId);
      ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
    }
    
    if(nodes.get(nodeId)){
552
      BaseString::snprintf(buf, sizeof(buf), "Two node can not have the same node id: %d",
553 554 555 556 557 558 559 560 561 562
	       nodeId);
      ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
    }
    nodes.set(nodeId);
        
    switch(nodeType){
    case NODE_TYPE_DB:
      noOfDBNodes++; // No of NDB processes
      
      if(nodeId > MAX_NDB_NODES){
563
		  BaseString::snprintf(buf, sizeof(buf), "Maximum node id for a ndb node is: %d", 
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
		 MAX_NDB_NODES);
	ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
      }
      break;
    case NODE_TYPE_API:
      noOfAPINodes++; // No of API processes
      break;
    case NODE_TYPE_REP:
      break;
    case NODE_TYPE_MGM:
      noOfMGMNodes++; // No of MGM processes
      break;
    case NODE_TYPE_EXT_REP:
      break;
    default:
579
      BaseString::snprintf(buf, sizeof(buf), "Unknown node type: %d", nodeType);
580 581 582 583
      ERROR_SET(fatal, ERR_INVALID_CONFIG, msg, buf);
    }
  }
  noOfNodes = nodeNo;
584 585

  noOfTables+= 2; // Add System tables
586
  noOfAttributes += 9;  // Add System table attributes
587 588 589 590

  ConfigValues::Iterator it2(*ownConfig, db.m_config);
  it2.set(CFG_DB_NO_TABLES, noOfTables);
  it2.set(CFG_DB_NO_ATTRIBUTES, noOfAttributes);
591
  {
592 593 594 595 596
    Uint32 neededNoOfTriggers =   /* types: Insert/Update/Delete/Custom */
      3 * noOfUniqueHashIndexes + /* for unique hash indexes, I/U/D */
      3 * NDB_MAX_ACTIVE_EVENTS + /* for events in suma, I/U/D */
      3 * noOfTables +            /* for backup, I/U/D */
      noOfOrderedIndexes;         /* for ordered indexes, C */
597 598 599 600 601 602
    if (noOfTriggers < neededNoOfTriggers)
    {
      noOfTriggers= neededNoOfTriggers;
      it2.set(CFG_DB_NO_TRIGGERS, noOfTriggers);
    }
  }
603

604 605 606 607 608
  /**
   * Do size calculations
   */
  ConfigValuesFactory cfg(ownConfig);

609 610
  Uint32 noOfMetaTables= noOfTables + noOfOrderedIndexes +
                           noOfUniqueHashIndexes;
611 612 613
  Uint32 noOfMetaTablesDict= noOfMetaTables;
  if (noOfMetaTablesDict > MAX_TABLES)
    noOfMetaTablesDict= MAX_TABLES;
614 615 616 617 618 619 620 621

  {
    /**
     * Dict Size Alt values
     */
    cfg.put(CFG_DICT_ATTRIBUTE, 
	    noOfAttributes);

622 623
    cfg.put(CFG_DICT_TABLE,
	    noOfMetaTablesDict);
624 625 626
  }


mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
627 628 629 630 631 632
  if (noOfLocalScanRecords == 0) {
    noOfLocalScanRecords = (noOfDBNodes * noOfScanRecords) + 1;
  }
  if (noOfLocalOperations == 0) {
    noOfLocalOperations= (11 * noOfOperations) / 10;
  }
633 634 635
  Uint32 noOfTCScanRecords = noOfScanRecords;

  {
636
    Uint32 noOfAccTables= noOfMetaTables/*noOfTables+noOfUniqueHashIndexes*/;
637 638 639 640 641
    /**
     * Acc Size Alt values
     */
    // Can keep 65536 pages (= 0.5 GByte)
    cfg.put(CFG_ACC_DIR_RANGE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
642
	    4 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas); 
643 644 645
    
    cfg.put(CFG_ACC_DIR_ARRAY,
	    (noOfIndexPages >> 8) + 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
646
	    4 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas);
647 648
    
    cfg.put(CFG_ACC_FRAGMENT,
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
649
	    2 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas);
650 651 652 653 654 655 656 657 658
    
    /*-----------------------------------------------------------------------*/
    // The extra operation records added are used by the scan and node 
    // recovery process. 
    // Node recovery process will have its operations dedicated to ensure
    // that they never have a problem with allocation of the operation record.
    // The remainder are allowed for use by the scan processes.
    /*-----------------------------------------------------------------------*/
    cfg.put(CFG_ACC_OP_RECS,
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
659 660
	    (noOfLocalOperations + 50) + 
	    (noOfLocalScanRecords * noBatchSize) +
661 662 663 664
	    NODE_RECOVERY_SCAN_OP_RECORDS);
    
    cfg.put(CFG_ACC_OVERFLOW_RECS,
	    noOfIndexPages + 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
665
	    2 * NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas);
666 667 668 669 670
    
    cfg.put(CFG_ACC_PAGE8, 
	    noOfIndexPages + 32);
    
    cfg.put(CFG_ACC_ROOT_FRAG, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
671
	    NO_OF_FRAG_PER_NODE * noOfAccTables* noOfReplicas);
672
    
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
673
    cfg.put(CFG_ACC_TABLE, noOfAccTables);
674 675 676 677 678 679 680 681 682 683 684 685
    
    cfg.put(CFG_ACC_SCAN, noOfLocalScanRecords);
  }
  
  {
    /**
     * Dih Size Alt values
     */
    cfg.put(CFG_DIH_API_CONNECT, 
	    2 * noOfTransactions);
    
    cfg.put(CFG_DIH_CONNECT, 
686
	    noOfOperations + noOfTransactions + 46);
687
    
688 689 690 691
    Uint32 noFragPerTable= ((noOfDBNodes + NO_OF_FRAGS_PER_CHUNK - 1) >>
                           LOG_NO_OF_FRAGS_PER_CHUNK) <<
                           LOG_NO_OF_FRAGS_PER_CHUNK;

692
    cfg.put(CFG_DIH_FRAG_CONNECT, 
693
	    noFragPerTable *  noOfMetaTables);
694 695 696 697 698 699 700 701 702
    
    int temp;
    temp = noOfReplicas - 2;
    if (temp < 0)
      temp = 1;
    else
      temp++;
    cfg.put(CFG_DIH_MORE_NODES, 
	    temp * NO_OF_FRAG_PER_NODE *
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
703
	    noOfMetaTables *  noOfDBNodes);
704

705
    cfg.put(CFG_DIH_REPLICAS, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
706
	    NO_OF_FRAG_PER_NODE * noOfMetaTables *
707 708 709
	    noOfDBNodes * noOfReplicas);

    cfg.put(CFG_DIH_TABLE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
710
	    noOfMetaTables);
711 712 713 714 715 716 717
  }
  
  {
    /**
     * Lqh Size Alt values
     */
    cfg.put(CFG_LQH_FRAG, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
718
	    NO_OF_FRAG_PER_NODE * noOfMetaTables * noOfReplicas);
719 720
    
    cfg.put(CFG_LQH_TABLE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
721
	    noOfMetaTables);
722 723

    cfg.put(CFG_LQH_TC_CONNECT, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
724
	    noOfLocalOperations + 50);
725 726 727 728 729 730 731 732 733 734 735 736 737
    
    cfg.put(CFG_LQH_SCAN, 
	    noOfLocalScanRecords);
  }
  
  {
    /**
     * Tc Size Alt values
     */
    cfg.put(CFG_TC_API_CONNECT, 
	    3 * noOfTransactions);
    
    cfg.put(CFG_TC_TC_CONNECT, 
738
	    (2 * noOfOperations) + 16 + noOfTransactions);
739 740
    
    cfg.put(CFG_TC_TABLE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
741
	    noOfMetaTables);
742 743 744 745 746 747 748 749 750 751 752 753 754
    
    cfg.put(CFG_TC_LOCAL_SCAN, 
	    noOfLocalScanRecords);
    
    cfg.put(CFG_TC_SCAN, 
	    noOfTCScanRecords);
  }
  
  {
    /**
     * Tup Size Alt values
     */
    cfg.put(CFG_TUP_FRAG, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
755
	    2 * NO_OF_FRAG_PER_NODE * noOfMetaTables* noOfReplicas);
756 757
    
    cfg.put(CFG_TUP_OP_RECS, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
758
	    noOfLocalOperations + 50);
759 760 761 762 763
    
    cfg.put(CFG_TUP_PAGE, 
	    noOfDataPages);
    
    cfg.put(CFG_TUP_PAGE_RANGE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
764
	    4 * NO_OF_FRAG_PER_NODE * noOfMetaTables* noOfReplicas);
765 766
    
    cfg.put(CFG_TUP_TABLE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
767
	    noOfMetaTables);
768 769
    
    cfg.put(CFG_TUP_TABLE_DESC, 
770 771
	    2 * 6 * NO_OF_FRAG_PER_NODE * noOfAttributes * noOfReplicas +
	    2 * 10 * NO_OF_FRAG_PER_NODE * noOfMetaTables * noOfReplicas );
772 773 774 775 776 777 778 779 780 781
    
    cfg.put(CFG_TUP_STORED_PROC,
	    noOfLocalScanRecords);
  }

  {
    /**
     * Tux Size Alt values
     */
    cfg.put(CFG_TUX_INDEX, 
782
	    noOfMetaTables /*noOfOrderedIndexes*/);
783
    
784
    cfg.put(CFG_TUX_FRAGMENT,
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
785
	    2 * NO_OF_FRAG_PER_NODE * noOfOrderedIndexes * noOfReplicas);
786 787
    
    cfg.put(CFG_TUX_ATTRIBUTE, 
mronstrom@mysql.com's avatar
mronstrom@mysql.com committed
788
	    noOfOrderedIndexes * 4);
789 790 791 792 793 794 795 796 797

    cfg.put(CFG_TUX_SCAN_OP, noOfLocalScanRecords); 
  }

  m_ownConfig = (ndb_mgm_configuration*)cfg.getConfigValues();
  m_ownConfigIterator = ndb_mgm_create_configuration_iterator
    (m_ownConfig, 0);
}

798 799 800 801
void
Configuration::setInitialStart(bool val){
  _initialStart = val;
}