⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgmapi.h

📁 在AS4下编译通过
💻 H
📖 第 1 页 / 共 3 页
字号:
/* 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; version 2 of the License.   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 MGMAPI_H#define MGMAPI_H#define NDB_MGM_MAX_LOGLEVEL 15/** * @mainpage MySQL Cluster Management API * * The MySQL Cluster Management API (MGM API) is a C language API * that is used for: * - Starting and stopping database nodes (ndbd processes) * - Starting and stopping Cluster backups * - Controlling the NDB Cluster log * - Performing other administrative tasks * * @section  secMgmApiGeneral General Concepts * * Each MGM API function needs a management server handle * of type @ref NdbMgmHandle. * This handle is created by calling the function  * function ndb_mgm_create_handle() and freed by calling  * ndb_mgm_destroy_handle(). * * A function can return any of the following: *  -# An integer value, with *     a value of <b>-1</b> indicating an error. *  -# A non-constant pointer value.  A <var>NULL</var> value indicates an error; *     otherwise, the return value must be freed *     by the programmer *  -# A constant pointer value, with a <var>NULL</var> value indicating an error. *     The returned value should <em>not</em> be freed. * * Error conditions can be identified by using the appropriate * error-reporting functions ndb_mgm_get_latest_error() and  * @ref ndb_mgm_error. * * Here is an example using the MGM API (without error handling for brevity's sake). * @code *   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); * @endcode * * @section secLogEvents  Log Events * * The database nodes and management server(s) regularly and on specific * occations report on various log events that occurs in the cluster. These * log events are written to the cluster log.  Optionally a mgmapi client * may listen to these events by using the method ndb_mgm_listen_event(). * Each log event belongs to a category, @ref ndb_mgm_event_category, and * has a severity, @ref ndb_mgm_event_severity, associated with it.  Each * log event also has a level (0-15) associated with it. * * 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. * * @code *   int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; *   int fd = ndb_mgm_listen_event(handle, filter); * @endcode * * * @section secSLogEvents  Structured Log Events * * The following steps are involved: * - Create a NdbEventLogHandle using ndb_mgm_create_logevent_handle() * - Wait and store log events using ndb_logevent_get_next() * - The log event data is available in the struct ndb_logevent. The *   data which is specific to a particular event is stored in a union *   between structs so use ndb_logevent::type to decide which struct *   is valid. * * Sample code for listening to Backup related events.  The availaable log * events are listed in @ref ndb_logevent.h * * @code *   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; *   } * @endcode *//* * @page ndb_logevent.h ndb_logevent.h * @include ndb_logevent.h *//** @addtogroup MGM_C_API *  @{ */#include <stdio.h>#include <ndb_types.h>#include "ndb_logevent.h"#include "mgmapi_config_parameters.h"#ifdef __cplusplusextern "C" {#endif  /**   * The NdbMgmHandle.   */  typedef struct ndb_mgm_handle * NdbMgmHandle;  /**   *   NDB Cluster node types   */  enum ndb_mgm_node_type {    NDB_MGM_NODE_TYPE_UNKNOWN = -1  /** Node type not known*/    ,NDB_MGM_NODE_TYPE_API    /** An application (NdbApi) node */#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL    = NODE_TYPE_API#endif    ,NDB_MGM_NODE_TYPE_NDB    /** A database node */#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL    = NODE_TYPE_DB#endif    ,NDB_MGM_NODE_TYPE_MGM    /** A management server node */#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL    = NODE_TYPE_MGM#endif#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL    ,NDB_MGM_NODE_TYPE_REP = NODE_TYPE_REP  /** A replication node */    ,NDB_MGM_NODE_TYPE_MIN     = 0          /** Min valid value*/    ,NDB_MGM_NODE_TYPE_MAX     = 3          /** Max valid value*/#endif  };  /**   *   Database node status   */  enum ndb_mgm_node_status {    /** Node status not known*/    NDB_MGM_NODE_STATUS_UNKNOWN       = 0,    /** No contact with node*/    NDB_MGM_NODE_STATUS_NO_CONTACT    = 1,    /** Has not run starting protocol*/    NDB_MGM_NODE_STATUS_NOT_STARTED   = 2,    /** Is running starting protocol*/    NDB_MGM_NODE_STATUS_STARTING      = 3,    /** Running*/    NDB_MGM_NODE_STATUS_STARTED       = 4,    /** Is shutting down*/    NDB_MGM_NODE_STATUS_SHUTTING_DOWN = 5,    /** Is restarting*/    NDB_MGM_NODE_STATUS_RESTARTING    = 6,    /** Maintenance mode*/    NDB_MGM_NODE_STATUS_SINGLEUSER    = 7,    /** Resume mode*/    NDB_MGM_NODE_STATUS_RESUME        = 8,#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL    /** Min valid value*/    NDB_MGM_NODE_STATUS_MIN           = 0,    /** Max valid value*/    NDB_MGM_NODE_STATUS_MAX           = 8#endif  };  /**   *    Error codes   */  enum ndb_mgm_error {    /** Not an error */    NDB_MGM_NO_ERROR = 0,    /* Request for service errors */    /** Supplied connectstring is illegal */    NDB_MGM_ILLEGAL_CONNECT_STRING = 1001,    /** Supplied NdbMgmHandle is illegal */    NDB_MGM_ILLEGAL_SERVER_HANDLE = 1005,    /** Illegal reply from server */    NDB_MGM_ILLEGAL_SERVER_REPLY = 1006,    /** Illegal number of nodes */    NDB_MGM_ILLEGAL_NUMBER_OF_NODES = 1007,    /** Illegal node status */    NDB_MGM_ILLEGAL_NODE_STATUS = 1008,    /** Memory allocation error */    NDB_MGM_OUT_OF_MEMORY = 1009,    /** Management server not connected */    NDB_MGM_SERVER_NOT_CONNECTED = 1010,    /** Could not connect to socker */    NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET = 1011,    /** Could not bind local address */    NDB_MGM_BIND_ADDRESS = 1012,        /* Alloc node id failures */    /** Generic error, retry may succeed */    NDB_MGM_ALLOCID_ERROR = 1101,    /** Non retriable error */    NDB_MGM_ALLOCID_CONFIG_MISMATCH = 1102,    /* Service errors - Start/Stop Node or System */    /** Start failed */    NDB_MGM_START_FAILED = 2001,    /** Stop failed */    NDB_MGM_STOP_FAILED = 2002,    /** Restart failed */    NDB_MGM_RESTART_FAILED = 2003,    /* Service errors - Backup */    /** Unable to start backup */    NDB_MGM_COULD_NOT_START_BACKUP = 3001,    /** Unable to abort backup */    NDB_MGM_COULD_NOT_ABORT_BACKUP = 3002,    /* Service errors - Single User Mode */    /** Unable to enter single user mode */    NDB_MGM_COULD_NOT_ENTER_SINGLE_USER_MODE = 4001,    /** Unable to exit single user mode */    NDB_MGM_COULD_NOT_EXIT_SINGLE_USER_MODE = 4002,    /* Usage errors */    /** Usage error */    NDB_MGM_USAGE_ERROR = 5001  };#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL  struct Ndb_Mgm_Error_Msg {    enum ndb_mgm_error  code;    const char *        msg;  };  const struct Ndb_Mgm_Error_Msg ndb_mgm_error_msgs[] = {    { NDB_MGM_NO_ERROR, "No error" },    /* Request for service errors */    { NDB_MGM_ILLEGAL_CONNECT_STRING, "Illegal connect string" },    { NDB_MGM_ILLEGAL_SERVER_HANDLE, "Illegal server handle" },    { NDB_MGM_ILLEGAL_SERVER_REPLY, "Illegal reply from server" },    { NDB_MGM_ILLEGAL_NUMBER_OF_NODES, "Illegal number of nodes" },    { NDB_MGM_ILLEGAL_NODE_STATUS, "Illegal node status" },    { NDB_MGM_OUT_OF_MEMORY, "Out of memory" },    { NDB_MGM_SERVER_NOT_CONNECTED, "Management server not connected" },    { NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, "Could not connect to socket" },    /* Service errors - Start/Stop Node or System */    { NDB_MGM_START_FAILED, "Start failed" },    { NDB_MGM_STOP_FAILED, "Stop failed" },    { NDB_MGM_RESTART_FAILED, "Restart failed" },    /* Service errors - Backup */    { NDB_MGM_COULD_NOT_START_BACKUP, "Could not start backup" },    { NDB_MGM_COULD_NOT_ABORT_BACKUP, "Could not abort backup" },    /* Service errors - Single User Mode */    { NDB_MGM_COULD_NOT_ENTER_SINGLE_USER_MODE,      "Could not enter single user mode" },    { NDB_MGM_COULD_NOT_EXIT_SINGLE_USER_MODE,      "Could not exit single user mode" },    /* Usage errors */    { NDB_MGM_USAGE_ERROR,      "Usage error" }  };  const int ndb_mgm_noOfErrorMsgs =  sizeof(ndb_mgm_error_msgs)/sizeof(struct Ndb_Mgm_Error_Msg);#endif  /**   *   Status of a node in the cluster.   *   *   Sub-structure in enum ndb_mgm_cluster_state   *   returned by ndb_mgm_get_status().   *   *   @note <var>node_status</var>, <var>start_phase</var>,   *         <var>dynamic_id</var>    *         and <var>node_group</var> are relevant only for database nodes,   *         i.e. <var>node_type</var> == @ref NDB_MGM_NODE_TYPE_NDB.   */  struct ndb_mgm_node_state {    /** NDB Cluster node ID*/    int node_id;    /** Type of NDB Cluster node*/    enum ndb_mgm_node_type   node_type;   /** State of node*/    enum ndb_mgm_node_status node_status;    /** Start phase.     *     *  @note Start phase is only valid if the <var>node_type</var> is     *        NDB_MGM_NODE_TYPE_NDB and the <var>node_status</var> is      *        NDB_MGM_NODE_STATUS_STARTING     */    int start_phase;    /** ID for heartbeats and master take-over (only valid for DB nodes)     */    int dynamic_id;    /** Node group of node (only valid for DB nodes)*/    int node_group;    /** Internal version number*/    int version;    /** Number of times node has connected or disconnected to the      *  management server     */    int connect_count;    /** IP address of node when it connected to the management server.     *  @note This value will be empty if the management server has restarted     *        since the node last connected.     */    char connect_address[#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL			 sizeof("000.000.000.000")+1#endif    ];  };  /**   *   State of all nodes in the cluster; returned from    *   ndb_mgm_get_status()   */  struct ndb_mgm_cluster_state {    /** Number of entries in the node_states array */    int no_of_nodes;    /** An array with node_states*/    struct ndb_mgm_node_state node_states[#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL					  1#endif    ];  };  /**   *   Default reply from the server (reserved for future use)   */  struct ndb_mgm_reply {    /** 0 if successful, otherwise error code. */    int return_code;    /** Error or reply message.*/    char message[256];  };#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL  /**   *   Default information types   */  enum ndb_mgm_info {    /** ?*/    NDB_MGM_INFO_CLUSTER,    /** Cluster log*/    NDB_MGM_INFO_CLUSTERLOG  };  /**   *   Signal log modes   *   (Used only in the development of NDB Cluster.)   */  enum ndb_mgm_signal_log_mode {    /** Log receiving signals */    NDB_MGM_SIGNAL_LOG_MODE_IN,    /** Log sending signals*/    NDB_MGM_SIGNAL_LOG_MODE_OUT,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -