A function can return any of the following:
Error conditions can be identified by using the appropriate error-reporting functions ndb_mgm_get_latest_error() and ndb_mgm_error.
Here is an example using the MGM API (without error handling for brevity's sake).
NdbMgmHandle handle= ndb_mgm_create_handle(); ndb_mgm_connect(handle,0,0,0); struct ndb_mgm_cluster_state *state= ndb_mgm_get_status(handle); for(int i=0; i < state->no_of_nodes; i++) { struct ndb_mgm_node_state *node_state= &state->node_states[i]; printf("node with ID=%d ", node_state->node_id); if(node_state->version != 0) printf("connected\n"); else printf("not connected\n"); } free((void*)state); ndb_mgm_destroy_handle(&handle);
Which log events that come out is controlled with ndb_mgm_listen_event(), ndb_mgm_set_clusterlog_loglevel(), and ndb_mgm_set_clusterlog_severity_filter().
Below is an example of how to listen to events related to backup.
int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; int fd = ndb_mgm_listen_event(handle, filter);
Sample code for listening to Backup related events. The availaable log events are listed in ndb_logevent::h
int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; NdbEventLogHandle le_handle= ndb_mgm_create_logevent_handle(handle, filter); struct ndb_logevent le; int r= ndb_logevent_get_next(le_handle,&le,0); if (r < 0) error else if (r == 0) no event switch (le.type) { case NDB_LE_BackupStarted: ... le.BackupStarted.starting_node; ... le.BackupStarted.backup_id; break; case NDB_LE_BackupFailedToStart: ... le.BackupFailedToStart.error; break; case NDB_LE_BackupCompleted: ... le.BackupCompleted.stop_gci; break; case NDB_LE_BackupAborted: ... le.BackupStarted.backup_id; break; default: break; }
| typedef struct ndb_logevent_handle* NdbLogEventHandle |
The NdbLogEventHandle
| typedef struct ndb_mgm_handle* NdbMgmHandle |
The NdbMgmHandle.
| enum Ndb_logevent_type |
Available log events grouped by ndb_mgm_event_category
Log event categories, used to set filter level on the log events using ndb_mgm_set_clusterlog_loglevel() and ndb_mgm_listen_event()
Log event severities (used to filter the cluster log, ndb_mgm_set_clusterlog_severity_filter(), and filter listening to events ndb_mgm_listen_event())
| enum ndb_mgm_node_status |
Database node status
| enum ndb_mgm_node_type |
| int ndb_logevent_get_fd | ( | const | NdbLogEventHandle | ) |
Retrieve filedescriptor from NdbLogEventHandle. May be used in e.g. an application select() statement.
| int ndb_logevent_get_latest_error | ( | const | NdbLogEventHandle | ) |
Retrieve laterst error code
| const char* ndb_logevent_get_latest_error_msg | ( | const | NdbLogEventHandle | ) |
Retrieve laterst error message
| int ndb_logevent_get_next | ( | const | NdbLogEventHandle, | |
| struct ndb_logevent * | dst, | |||
| unsigned | timeout_in_milliseconds | |||
| ) |
Attempt to retrieve next log event and will fill in the supplied struct dst
| dst | Pointer to struct to fill in event information | |
| timeout_in_milliseconds | Timeout for waiting for event |
| int ndb_mgm_abort_backup | ( | NdbMgmHandle | handle, | |
| unsigned int | backup_id, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Abort backup
| handle | NDB management handle. | |
| backup_id | Backup ID. | |
| reply | Reply message. |
| int ndb_mgm_connect | ( | NdbMgmHandle | handle, | |
| int | no_retries, | |||
| int | retry_delay_in_seconds, | |||
| int | verbose | |||
| ) |
Connects to a management server. Connectstring is set by ndb_mgm_set_connectstring().
The timeout value is for connect to each management server. Use ndb_mgm_number_of_mgmd_in_connect_string to work out the approximate maximum amount of time that could be spent in this function.
| handle | Management handle. | |
| no_retries | Number of retries to connect (0 means connect once). | |
| retry_delay_in_seconds | How long to wait until retry is performed. | |
| verbose | Make printout regarding connect retries. |
| NdbMgmHandle ndb_mgm_create_handle | ( | ) |
Create a handle to a management server.
| NdbLogEventHandle ndb_mgm_create_logevent_handle | ( | NdbMgmHandle | , | |
| const int | filter[] | |||
| ) |
Listen to log events.
| handle | NDB management handle. | |
| filter | pairs of { level, ndb_mgm_event_category } that will be pushed to fd, level=0 ends list. |
| int ndb_mgm_create_nodegroup | ( | NdbMgmHandle | handle, | |
| int * | nodes, | |||
| int * | ng, | |||
| struct ndb_mgm_reply * | mgmreply | |||
| ) |
| void ndb_mgm_destroy_handle | ( | NdbMgmHandle * | handle | ) |
Destroy a management server handle.
| handle | Management handle |
| void ndb_mgm_destroy_logevent_handle | ( | NdbLogEventHandle * | ) |
| int ndb_mgm_disconnect | ( | NdbMgmHandle | handle | ) |
Disconnects from a management server
| handle | Management handle. |
| int ndb_mgm_drop_nodegroup | ( | NdbMgmHandle | handle, | |
| int | ng, | |||
| struct ndb_mgm_reply * | mgmreply | |||
| ) |
| int ndb_mgm_dump_state | ( | NdbMgmHandle | handle, | |
| int | nodeId, | |||
| const int * | args, | |||
| int | num_args, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Dump state
| handle | the NDB management handle. | |
| nodeId | the node id. | |
| args | integer array | |
| number | of args in int array | |
| reply | the reply message. |
| int ndb_mgm_enter_single_user | ( | NdbMgmHandle | handle, | |
| unsigned int | nodeId, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Enter Single user mode
| handle | NDB management handle. | |
| nodeId | Node ID of the single user node | |
| reply | Reply message. |
| int ndb_mgm_exit_single_user | ( | NdbMgmHandle | handle, | |
| struct ndb_mgm_reply * | reply | |||
| ) |
Exit Single user mode
| handle | NDB management handle. | |
| reply | Reply message. |
| static int ndb_mgm_filter_clusterlog | ( | NdbMgmHandle | h, | |
| enum ndb_mgm_clusterlog_level | s, | |||
| int | e, | |||
| struct ndb_mgm_reply * | r | |||
| ) | [inline, static] |
| int ndb_mgm_get_clusterlog_loglevel | ( | NdbMgmHandle | handle, | |
| struct ndb_mgm_loglevel * | loglevel, | |||
| unsigned int | loglevel_size | |||
| ) |
get log category and levels
| handle | NDB management handle. | |
| loglevel | A vector of twelve (MGM_LOGLEVELS) elements of struct ndb_mgm_loglevel, where each element contains loglevel of corresponding category | |
| loglevel_size | The size of the vector (MGM_LOGLEVELS) |
| const unsigned int* ndb_mgm_get_clusterlog_loglevel_old | ( | NdbMgmHandle | handle | ) |
get log category and levels
| handle | NDB management handle. |
| int ndb_mgm_get_clusterlog_severity_filter | ( | NdbMgmHandle | handle, | |
| struct ndb_mgm_severity * | severity, | |||
| unsigned int | severity_size | |||
| ) |
Get clusterlog severity filter
| handle | NDB management handle | |
| loglevel | A vector of seven (NDB_MGM_EVENT_SEVERITY_ALL) elements of struct ndb_mgm_severity, where each element contains 1 if a severity indicator is enabled and 0 if not. A severity level is stored at position ndb_mgm_clusterlog_level; for example the "error" level is stored in position [NDB_MGM_EVENT_SEVERITY_ERROR]. The first element [NDB_MGM_EVENT_SEVERITY_ON] in the vector signals whether the cluster log is disabled or enabled. | |
| severity_size | The size of the vector (NDB_MGM_EVENT_SEVERITY_ALL) |
| const unsigned int* ndb_mgm_get_clusterlog_severity_filter_old | ( | NdbMgmHandle | handle | ) |
Get clusterlog severity filter
| handle | NDB management handle |
| int ndb_mgm_get_configuration_nodeid | ( | NdbMgmHandle | handle | ) |
Gets connection node ID
| handle | Management handle |
| const char* ndb_mgm_get_connected_bind_address | ( | NdbMgmHandle | handle | ) |
Gets connection bind address
| handle | Management handle |
| const char* ndb_mgm_get_connected_host | ( | NdbMgmHandle | handle | ) |
Gets connection host
| handle | Management handle |
| int ndb_mgm_get_connected_port | ( | NdbMgmHandle | handle | ) |
Gets connection port
| handle | Management handle |
| const char* ndb_mgm_get_connectstring | ( | NdbMgmHandle | handle, | |
| char * | buf, | |||
| int | buf_sz | |||
| ) |
Gets the connectstring used for a connection
| handle | Management handle | |
| buf | Buffer to hold result | |
| buf_sz | Size of buffer. |
| int ndb_mgm_get_latest_error | ( | const NdbMgmHandle | handle | ) |
Get the most recent error associated with the management server whose handle is used as the value of handle.
| handle | Management handle |
| const char* ndb_mgm_get_latest_error_desc | ( | const NdbMgmHandle | handle | ) |
Get the most recent error description associated with a handle
The error description gives some additional information regarding the error message.
| handle | Management handle. |
| int ndb_mgm_get_latest_error_line | ( | const NdbMgmHandle | handle | ) |
Get the most recent internal source code error line associated with a handle
| handle | Management handle. |
| const char* ndb_mgm_get_latest_error_msg | ( | const NdbMgmHandle | handle | ) |
Get the most recent general error message associated with a handle
| handle | Management handle. |
| static const unsigned int* ndb_mgm_get_logfilter | ( | NdbMgmHandle | h | ) | [inline, static] |
| static const unsigned int* ndb_mgm_get_loglevel_clusterlog | ( | NdbMgmHandle | h | ) | [inline, static] |
| struct ndb_mgm_cluster_state* ndb_mgm_get_status | ( | NdbMgmHandle | handle | ) | [read] |
Gets status of the nodes in an NDB Cluster
| handle | Management handle. |
| struct ndb_mgm_cluster_state* ndb_mgm_get_status2 | ( | NdbMgmHandle | handle, | |
| const enum ndb_mgm_node_type | types[] | |||
| ) | [read] |
Gets status of the nodes *of specified types* in an NDB Cluster
Passing a NULL pointer into types make this equivalent to ndb_mgm_get_status
| handle | Management handle. | |
| types | Pointer to array of interesting node types. Array should be terminated by *NDB_MGM_NODE_TYPE_UNKNOWN*. |
| int ndb_mgm_is_connected | ( | NdbMgmHandle | handle | ) |
Return true if connected.
| handle | Management handle |
| int ndb_mgm_listen_event | ( | NdbMgmHandle | handle, | |
| const int | filter[] | |||
| ) |
Listen to log events. They are read from the return file descriptor and the format is textual, and the same as in the cluster log.
| handle | NDB management handle. | |
| filter | pairs of { level, ndb_mgm_event_category } that will be pushed to fd, level=0 ends list. |
| int ndb_mgm_number_of_mgmd_in_connect_string | ( | NdbMgmHandle | handle | ) |
Returns the number of management servers in the connect string (as set by ndb_mgm_set_connectstring()). This can be used to help work out how long the maximum amount of time that ndb_mgm_connect can take.
| handle | Management handle |
| int ndb_mgm_restart | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list | |||
| ) |
Restart database nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to restart 0: All database nodes in cluster n: Restart the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be restarted |
| int ndb_mgm_restart2 | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list, | |||
| int | initial, | |||
| int | nostart, | |||
| int | abort | |||
| ) |
Restart database nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to be restarted: 0: Restart all database nodes in the cluster n: Restart the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be restarted | |
| initial | Remove filesystem from restarting node(s) | |
| nostart | Don't actually start node(s) but leave them waiting for start command | |
| abort | Don't perform graceful restart, but rather restart immediately |
| int ndb_mgm_restart3 | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list, | |||
| int | initial, | |||
| int | nostart, | |||
| int | abort, | |||
| int * | disconnect | |||
| ) |
Restart nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to be restarted: 0: Restart all database nodes in the cluster n: Restart the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be restarted | |
| initial | Remove filesystem from restarting node(s) | |
| nostart | Don't actually start node(s) but leave them waiting for start command | |
| abort | Don't perform graceful restart, but rather restart immediately | |
| disconnect | Returns true if mgmapi client must disconnect from server to apply the requested operation. (e.g. restart the management server) |
| int ndb_mgm_set_bindaddress | ( | NdbMgmHandle | , | |
| const char * | arg | |||
| ) |
Set local bindaddress
| arg | - Srting of form "host[:port]" |
Error on binding local address will not be reported until connect
| int ndb_mgm_set_clusterlog_loglevel | ( | NdbMgmHandle | handle, | |
| int | nodeId, | |||
| enum ndb_mgm_event_category | category, | |||
| int | level, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Set log category and levels for the cluster log
| handle | NDB management handle. | |
| nodeId | Node ID. | |
| category | Event category. | |
| level | Log level (0-15). | |
| reply | Reply message. |
| int ndb_mgm_set_clusterlog_severity_filter | ( | NdbMgmHandle | handle, | |
| enum ndb_mgm_event_severity | severity, | |||
| int | enable, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Filter cluster log severities
| handle | NDB management handle. | |
| severity | A cluster log severity to filter. | |
| enable | set 1=enable o 0=disable | |
| reply | Reply message. |
| int ndb_mgm_set_configuration_nodeid | ( | NdbMgmHandle | handle, | |
| int | nodeid | |||
| ) |
| int ndb_mgm_set_connect_timeout | ( | NdbMgmHandle | handle, | |
| unsigned int | seconds | |||
| ) |
DEPRICATED: use ndb_mgm_set_timeout instead.
| handle | NdbMgmHandle | |
| seconds | number of seconds |
| int ndb_mgm_set_connectstring | ( | NdbMgmHandle | handle, | |
| const char * | connect_string | |||
| ) |
Sets the connectstring for a management server
| handle | Management handle | |
| connect_string | Connect string to the management server, |
<connectstring> := [<nodeid-specification>,]<host-specification>[,<host-specification>] <nodeid-specification> := nodeid=<id> <host-specification> := <host>[:<port>] <id> is an integer greater than 0 identifying a node in config.ini <port> is an integer referring to a regular unix port <host> is a string containing a valid network host address
| void ndb_mgm_set_error_stream | ( | NdbMgmHandle | , | |
| FILE * | ||||
| ) |
Set error stream
| int ndb_mgm_set_ignore_sigpipe | ( | NdbMgmHandle | handle, | |
| int | val | |||
| ) |
Set 'ignore_sigpipe' behaviour
The mgmapi will by default install a signal handler that ignores all SIGPIPE signals that might occur when writing to an already closed or reset socket. An application that wish to use its own handler for SIGPIPE should call this function after 'ndb_mgm_create_handle' and before 'ndb_mgm_connect'(where the signal handler is installed)
| handle | Management handle | |
| val | Value 0 - Don't ignore SIGPIPE 1 - Ignore SIGPIPE(default) |
| static int ndb_mgm_set_loglevel_clusterlog | ( | NdbMgmHandle | h, | |
| int | n, | |||
| enum ndb_mgm_event_category | c, | |||
| int | l, | |||
| struct ndb_mgm_reply * | r | |||
| ) | [inline, static] |
| void ndb_mgm_set_name | ( | NdbMgmHandle | handle, | |
| const char * | name | |||
| ) |
Set a name of the handle. Name is reported in cluster log.
| handle | Management handle | |
| name | Name |
| int ndb_mgm_set_timeout | ( | NdbMgmHandle | handle, | |
| unsigned int | timeout_ms | |||
| ) |
Sets the number of milliseconds for timeout of network operations Default is 60 seconds. Only increments of 1000 ms are supported. No function is gaurenteed to return in a fraction of a second.
| handle | NdbMgmHandle | |
| timeout_ms | number of milliseconds |
| int ndb_mgm_start | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list | |||
| ) |
Start database nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to be started 0: Start all database nodes in the cluster n: Start the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be started |
| int ndb_mgm_start_backup | ( | NdbMgmHandle | handle, | |
| int | wait_completed, | |||
| unsigned int * | backup_id, | |||
| struct ndb_mgm_reply * | reply | |||
| ) |
Start backup
| handle | NDB management handle. | |
| wait_completed | 0: Don't wait for confirmation 1: Wait for backup to be started 2: Wait for backup to be completed | |
| backup_id | Backup ID is returned from function. | |
| reply | Reply message. |
| int ndb_mgm_start_backup2 | ( | NdbMgmHandle | handle, | |
| int | wait_completed, | |||
| unsigned int * | backup_id, | |||
| struct ndb_mgm_reply * | reply, | |||
| unsigned int | input_backupId | |||
| ) |
Start backup
| handle | NDB management handle. | |
| wait_completed | 0: Don't wait for confirmation 1: Wait for backup to be started 2: Wait for backup to be completed | |
| backup_id | Backup ID is returned from function. | |
| reply | Reply message. | |
| input_backupId | run as backupId and set next backup id to input_backupId+1. |
| int ndb_mgm_start_backup3 | ( | NdbMgmHandle | handle, | |
| int | wait_completed, | |||
| unsigned int * | backup_id, | |||
| struct ndb_mgm_reply * | reply, | |||
| unsigned int | input_backupId, | |||
| unsigned int | backuppoint | |||
| ) |
Start backup
| handle | NDB management handle. | |
| wait_completed | 0: Don't wait for confirmation 1: Wait for backup to be started 2: Wait for backup to be completed | |
| backup_id | Backup ID is returned from function. | |
| reply | Reply message. | |
| input_backupId | run as backupId and set next backup id to input_backupId+1. | |
| backuppoint | Backup happen at start time(1) or complete time(0). |
| int ndb_mgm_stop | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list | |||
| ) |
Stops database nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to be stopped 0: All database nodes in cluster n: Stop the n node(s) specified in the array node_list | |
| node_list | List of node IDs for database nodes to be stopped |
| int ndb_mgm_stop2 | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list, | |||
| int | abort | |||
| ) |
Stops database nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to stop 0: All database nodes in cluster n: Stop the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be stopped | |
| abort | Don't perform graceful stop, but rather stop immediately |
| int ndb_mgm_stop3 | ( | NdbMgmHandle | handle, | |
| int | no_of_nodes, | |||
| const int * | node_list, | |||
| int | abort, | |||
| int * | disconnect | |||
| ) |
Stops cluster nodes
| handle | Management handle. | |
| no_of_nodes | Number of database nodes to stop -1: All database and management nodes 0: All database nodes in cluster n: Stop the n node(s) specified in the array node_list | |
| node_list | List of node IDs of database nodes to be stopped | |
| abort | Don't perform graceful stop, but rather stop immediately | |
| disconnect | Returns true if you need to disconnect to apply the stop command (e.g. stopping the mgm server that handle is connected to) |
char ndb_mgm_node_state::connect_address[] [inherited] |
IP address of node when it connected to the management server.
int ndb_mgm_node_state::connect_count [inherited] |
Number of times node has connected or disconnected to the management server
int ndb_mgm_node_state::dynamic_id [inherited] |
ID for heartbeats and master take-over (only valid for DB nodes)
char ndb_mgm_reply::message[256] [inherited] |
Error or reply message.
int ndb_mgm_node_state::mysql_version [inherited] |
MySQL version number
int ndb_mgm_node_state::node_group [inherited] |
Node group of node (only valid for DB nodes)
struct ndb_mgm_node_state ndb_mgm_cluster_state::node_states[] [read, inherited] |
An array with node_states
enum ndb_mgm_node_status ndb_mgm_node_state::node_status [inherited] |
State of node
enum ndb_mgm_node_type ndb_mgm_node_state::node_type [inherited] |
Type of NDB Cluster node
int ndb_mgm_node_state::start_phase [inherited] |
Start phase.
unsigned int ndb_mgm_loglevel::value [inherited] |
unsigned int ndb_mgm_severity::value [inherited] |
int ndb_mgm_node_state::version [inherited] |
Internal version number
Based on MySQL Cluster 7.0.6.
This page is for information only and is not maintained by MySQL or Sun Microsystems - use at your own risk. For an upto date view of the API refer to the header files included with your MySQL Cluster distribution or check the MySQL Cluster API Developer Guide.