2004-04-14 10:53:21 +02:00
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
#ifndef ConfigRetriever_H
|
|
|
|
#define ConfigRetriever_H
|
|
|
|
|
|
|
|
#include <ndb_types.h>
|
2004-05-26 10:56:32 +02:00
|
|
|
#include <mgmapi.h>
|
2004-08-09 13:25:07 +02:00
|
|
|
#include <BaseString.hpp>
|
|
|
|
#include <LocalConfig.hpp>
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class ConfigRetriever
|
|
|
|
* @brief Used by nodes (DB, MGM, API) to get their config from MGM server.
|
|
|
|
*/
|
|
|
|
class ConfigRetriever {
|
|
|
|
public:
|
2004-09-25 14:10:06 +00:00
|
|
|
ConfigRetriever(LocalConfig &local_config, Uint32 version, Uint32 nodeType);
|
2004-04-14 10:53:21 +02:00
|
|
|
~ConfigRetriever();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read local config
|
|
|
|
* @return Own node id, -1 means fail
|
|
|
|
*/
|
2004-08-09 13:25:07 +02:00
|
|
|
int init();
|
|
|
|
|
2004-09-02 12:04:50 +00:00
|
|
|
int do_connect(int exit_on_connect_failure= false);
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get configuration for current (nodeId given in local config file) node.
|
|
|
|
*
|
|
|
|
* Configuration is fetched from one MGM server configured in local config
|
|
|
|
* file. The method loops over all the configured MGM servers and tries
|
|
|
|
* to establish a connection. This is repeated until a connection is
|
|
|
|
* established, so the function hangs until a connection is established.
|
|
|
|
*
|
2004-05-26 10:56:32 +02:00
|
|
|
* @return ndb_mgm_configuration object if succeeded,
|
2004-04-14 10:53:21 +02:00
|
|
|
* NULL if erroneous local config file or configuration error.
|
|
|
|
*/
|
2004-08-09 13:25:07 +02:00
|
|
|
struct ndb_mgm_configuration * getConfig();
|
2004-05-26 10:56:32 +02:00
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
const char * getErrorString();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Node id of this node (as stated in local config or connectString)
|
|
|
|
*/
|
2004-08-09 13:25:07 +02:00
|
|
|
Uint32 allocNodeId();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get config using socket
|
|
|
|
*/
|
2004-08-09 13:25:07 +02:00
|
|
|
struct ndb_mgm_configuration * getConfig(NdbMgmHandle handle);
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
/**
|
|
|
|
* Get config from file
|
|
|
|
*/
|
2004-08-09 13:25:07 +02:00
|
|
|
struct ndb_mgm_configuration * getConfig(const char * file);
|
2004-08-26 14:35:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify config
|
|
|
|
*/
|
|
|
|
bool verifyConfig(const struct ndb_mgm_configuration *, Uint32 nodeid);
|
2004-04-14 10:53:21 +02:00
|
|
|
private:
|
2004-08-09 13:25:07 +02:00
|
|
|
BaseString errorString;
|
2004-04-14 10:53:21 +02:00
|
|
|
enum ErrorType {
|
|
|
|
CR_ERROR = 0,
|
|
|
|
CR_RETRY = 1
|
|
|
|
};
|
|
|
|
ErrorType latestErrorType;
|
|
|
|
|
|
|
|
void setError(ErrorType, const char * errorMsg);
|
2004-08-09 13:25:07 +02:00
|
|
|
|
2004-09-25 14:10:06 +00:00
|
|
|
struct LocalConfig& _localConfig;
|
2004-09-11 20:53:57 +02:00
|
|
|
Uint32 _ownNodeId;
|
2004-08-09 13:25:07 +02:00
|
|
|
|
|
|
|
Uint32 m_version;
|
|
|
|
Uint32 m_node_type;
|
2004-06-28 17:29:58 +00:00
|
|
|
NdbMgmHandle m_handle;
|
2004-04-14 10:53:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|