1
/* Copyright (C) 2003 MySQL AB
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.
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.
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 */
17
#ifndef CLUSTER_CONNECTION_HPP
18
#define CLUSTER_CONNECTION_HPP
19
#include <ndb_types.h>
21
class Ndb_cluster_connection_node_iter
23
friend class Ndb_cluster_connection_impl;
25
Ndb_cluster_connection_node_iter() : scan_state(~0),
29
unsigned char scan_state;
30
unsigned char init_pos;
31
unsigned char cur_pos;
35
* @class Ndb_cluster_connection
36
* @brief Represents a connection to a cluster of storage nodes.
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.
45
class Ndb_cluster_connection {
48
* Create a connection to a cluster of storage nodes
50
* @param connectstring The connectstring for where to find the
53
Ndb_cluster_connection(const char * connectstring = 0);
54
~Ndb_cluster_connection();
57
* Set a name on the connection, which will be reported in cluster log
62
void set_name(const char *name);
67
* Used as a timeout when talking to the management server,
68
* helps limit the amount of time that we may block when connecting
70
* Basically just calls ndb_mgm_set_timeout(h,ms).
72
* The default is 30 seconds.
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
80
int set_timeout(int timeout_ms);
83
* Connect to a cluster management server
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
90
* @param retry_delay_in_seconds specifies how often retries should
93
* @param verbose specifies if the method should print a report of its progess
95
* @return 0 = success,
96
* 1 = recoverable error,
97
* -1 = non-recoverable error
99
int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
101
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
102
int start_connect_thread(int (*connect_callback)(void)= 0);
106
* Wait until the requested connection with one or more storage nodes is successful
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
113
* @return = 0 all nodes live,
114
* > 0 at least one node live,
117
int wait_until_ready(int timeout_for_first_alive,
118
int timeout_after_first_alive);
120
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
122
const char *get_connectstring(char *buf, int buf_sz) const;
123
int get_connected_port() const;
124
const char *get_connected_host() const;
126
void set_optimized_node_selection(int val);
128
unsigned no_db_nodes();
130
unsigned get_connect_count() const;
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;
136
Uint64 *get_latest_trans_gci();
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&);