ConfigRetriever.hpp 2.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* 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>
21
#include <mgmapi.h>
unknown's avatar
unknown committed
22
#include <BaseString.hpp>
23 24 25 26 27 28 29

/**
 * @class ConfigRetriever
 * @brief Used by nodes (DB, MGM, API) to get their config from MGM server. 
 */
class ConfigRetriever {
public:
30 31
  ConfigRetriever(const char * _connect_string,
		  Uint32 version, Uint32 nodeType);
32 33
  ~ConfigRetriever();

34
  int do_connect(int no_retries, int retry_delay_in_seconds, int verbose);
35 36
  
  /**
unknown's avatar
unknown committed
37
   * Get configuration for current node.
38 39 40 41 42 43
   * 
   * 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.
   * 
44
   * @return ndb_mgm_configuration object if succeeded, 
45 46
   *         NULL if erroneous local config file or configuration error.
   */
unknown's avatar
unknown committed
47
  struct ndb_mgm_configuration * getConfig();
48
  
49 50
  void resetError();
  int hasError();
51 52 53 54 55
  const char * getErrorString();

  /**
   * @return Node id of this node (as stated in local config or connectString)
   */
56
  Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds);
57 58 59 60

  /**
   * Get config using socket
   */
unknown's avatar
unknown committed
61 62
  struct ndb_mgm_configuration * getConfig(NdbMgmHandle handle);
  
63 64 65
  /**
   * Get config from file
   */
unknown's avatar
unknown committed
66
  struct ndb_mgm_configuration * getConfig(const char * file);
67 68 69 70 71

  /**
   * Verify config
   */
  bool verifyConfig(const struct ndb_mgm_configuration *, Uint32 nodeid);
72

73 74
  Uint32 get_mgmd_port() const;
  const char *get_mgmd_host() const;
unknown's avatar
unknown committed
75
  const char *get_connectstring(char *buf, int buf_sz) const;
unknown's avatar
unknown committed
76
  NdbMgmHandle get_mgmHandle() { return m_handle; };
77 78

  Uint32 get_configuration_nodeid() const;
79
private:
unknown's avatar
unknown committed
80
  BaseString errorString;
81
  enum ErrorType {
82 83 84
    CR_NO_ERROR = 0,
    CR_ERROR = 1,
    CR_RETRY = 2
85 86 87 88
  };
  ErrorType latestErrorType;
  
  void setError(ErrorType, const char * errorMsg);
unknown's avatar
unknown committed
89
  
90 91
  Uint32      _ownNodeId;
  /*
92 93
  Uint32      m_mgmd_port;
  const char *m_mgmd_host;
94
  */
95

unknown's avatar
unknown committed
96 97
  Uint32 m_version;
  Uint32 m_node_type;
98
  NdbMgmHandle m_handle;
99 100 101 102 103
};

#endif