~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/include/ndbapi/ndb_cluster_connection.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 
 
17
#ifndef CLUSTER_CONNECTION_HPP
 
18
#define CLUSTER_CONNECTION_HPP
 
19
#include <ndb_types.h>
 
20
 
 
21
class Ndb_cluster_connection_node_iter
 
22
{
 
23
  friend class Ndb_cluster_connection_impl;
 
24
public:
 
25
  Ndb_cluster_connection_node_iter() : scan_state(~0),
 
26
                                       init_pos(0),
 
27
                                       cur_pos(0) {};
 
28
private:
 
29
  unsigned char scan_state;
 
30
  unsigned char init_pos;
 
31
  unsigned char cur_pos;
 
32
};
 
33
 
 
34
/**
 
35
 * @class Ndb_cluster_connection
 
36
 * @brief Represents a connection to a cluster of storage nodes.
 
37
 *
 
38
 * Any NDB application program should begin with the creation of a
 
39
 * single Ndb_cluster_connection object, and should make use of one
 
40
 * and only one Ndb_cluster_connection. The application connects to
 
41
 * a cluster management server when this object's connect() method is called.
 
42
 * By using the wait_until_ready() method it is possible to wait
 
43
 * for the connection to reach one or more storage nodes.
 
44
 */
 
45
class Ndb_cluster_connection {
 
46
public:
 
47
  /**
 
48
   * Create a connection to a cluster of storage nodes
 
49
   *
 
50
   * @param connectstring The connectstring for where to find the
 
51
   *                      management server
 
52
   */
 
53
  Ndb_cluster_connection(const char * connectstring = 0);
 
54
  ~Ndb_cluster_connection();
 
55
 
 
56
  /**
 
57
   * Set a name on the connection, which will be reported in cluster log
 
58
   *
 
59
   * @param name
 
60
   *
 
61
   */
 
62
  void set_name(const char *name);
 
63
 
 
64
  /**
 
65
   * Set timeout
 
66
   *
 
67
   * Used as a timeout when talking to the management server,
 
68
   * helps limit the amount of time that we may block when connecting
 
69
   *
 
70
   * Basically just calls ndb_mgm_set_timeout(h,ms).
 
71
   *
 
72
   * The default is 30 seconds.
 
73
   *
 
74
   * @param timeout_ms millisecond timeout. As with ndb_mgm_set_timeout,
 
75
   *                   only increments of 1000 are really supported,
 
76
   *                   with not to much gaurentees about calls completing
 
77
   *                   in any hard amount of time.
 
78
   * @return 0 on success
 
79
   */
 
80
  int set_timeout(int timeout_ms);
 
81
 
 
82
  /**
 
83
   * Connect to a cluster management server
 
84
   *
 
85
   * @param no_retries specifies the number of retries to attempt
 
86
   *        in the event of connection failure; a negative value 
 
87
   *        will result in the attempt to connect being repeated 
 
88
   *        indefinitely
 
89
   *
 
90
   * @param retry_delay_in_seconds specifies how often retries should
 
91
   *        be performed
 
92
   *
 
93
   * @param verbose specifies if the method should print a report of its progess
 
94
   *
 
95
   * @return 0 = success, 
 
96
   *         1 = recoverable error,
 
97
   *        -1 = non-recoverable error
 
98
   */
 
99
  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
 
100
 
 
101
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
 
102
  int start_connect_thread(int (*connect_callback)(void)= 0);
 
103
#endif
 
104
 
 
105
  /**
 
106
   * Wait until the requested connection with one or more storage nodes is successful
 
107
   *
 
108
   * @param timeout_for_first_alive   Number of seconds to wait until
 
109
   *                                  first live node is detected
 
110
   * @param timeout_after_first_alive Number of seconds to wait after
 
111
   *                                  first live node is detected
 
112
   *
 
113
   * @return = 0 all nodes live,
 
114
   *         > 0 at least one node live,
 
115
   *         < 0 error
 
116
   */
 
117
  int wait_until_ready(int timeout_for_first_alive,
 
118
                       int timeout_after_first_alive);
 
119
 
 
120
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
 
121
  int get_no_ready();
 
122
  const char *get_connectstring(char *buf, int buf_sz) const;
 
123
  int get_connected_port() const;
 
124
  const char *get_connected_host() const;
 
125
 
 
126
  void set_optimized_node_selection(int val);
 
127
 
 
128
  unsigned no_db_nodes();
 
129
  unsigned node_id();
 
130
  unsigned get_connect_count() const;
 
131
 
 
132
  void init_get_next_node(Ndb_cluster_connection_node_iter &iter);
 
133
  unsigned int get_next_node(Ndb_cluster_connection_node_iter &iter);
 
134
  unsigned get_active_ndb_objects() const;
 
135
  
 
136
  Uint64 *get_latest_trans_gci();
 
137
#endif
 
138
 
 
139
private:
 
140
  friend class Ndb;
 
141
  friend class NdbImpl;
 
142
  friend class Ndb_cluster_connection_impl;
 
143
  class Ndb_cluster_connection_impl & m_impl;
 
144
  Ndb_cluster_connection(Ndb_cluster_connection_impl&);
 
145
};
 
146
 
 
147
#endif